Skip to content

Commit f178c77

Browse files
committed
Added keyfiles to gitignore.
Added configurable output dir based on vue config file.
1 parent 6e56f6f commit f178c77

File tree

6 files changed

+32
-24
lines changed

6 files changed

+32
-24
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ This can be added to your vuejs project by one of the following methods:
4646
## Usage
4747
Running the Livereload server.
4848
This will build and write to the local `dist` directory.
49+
This plugin will respect the `outputDir` setting, however it cannot read into passed CLI args, so if you require a custom output dir, be sure to add it in your `vue.config.js` file.
4950
You can then add this as an unpacked plugin to your browser, and will continue to update as you make changes.
5051
**NOTE:** you cannot get HMR support in the popup window, however, closing and reopening will refresh your content.
5152

5253
```sh
53-
yarn ext-serve
54+
yarn serve
55+
yarn build
5456
```
5557

5658

@@ -62,15 +64,14 @@ yarn test
6264
```
6365

6466
## Roadmap
65-
- Add generators for background.js, popup, vuex, and vue-router stuff. (Make startup a breeze)
6667
- Add some generator options for other pieces of browser extensions. This includes scaffolding the components/dirs, and registering the build options into the build time hooks.
6768
- Dev Tools
6869
- Dedicated extension pages
6970
- Options Pages
7071
- Content scripts
71-
- Add zipping to the bundle for production builds
7272
- More configurability in scaffolding, like Kocal/vue-web-extension does
7373
- A preset
74+
- Key Generation
7475

7576
## Credits
7677
- [https://github.com/Kocal/vue-web-extension](https://github.com/Kocal/vue-web-extension) For inspiration on app and build structure

generator/index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
const fs = require('fs')
2+
const gitignoreSnippet = `
3+
# Vue Browser Extension Output
4+
*.pem
5+
*.pub
6+
*.zip
7+
/dist-zip
8+
`
9+
110
module.exports = (api, { config }) => {
211
const eslintConfig = { env: { webextensions: true } }
312
const pkg = {
413
private: true,
514
scripts: {
6-
'ext-serve': 'vue-cli-service ext-serve --mode development'
15+
'serve': 'vue-cli-service build --mode development --watch'
716
},
817
dependencies: {
918
'vue-router': '^3.0.1',
@@ -18,4 +27,9 @@ module.exports = (api, { config }) => {
1827

1928
api.extendPackage(pkg)
2029
api.render('./template')
30+
31+
api.onCreateComplete(() => {
32+
const gitignore = fs.readFileSync(api.resolve('./.gitignore'), 'utf8')
33+
fs.writeFileSync(api.resolve('./.gitignore'), gitignore + gitignoreSnippet)
34+
})
2135
}

index.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const path = require('path')
22
const fs = require('fs')
33
const { exec } = require('child_process')
4-
const { log } = require('@vue/cli-shared-utils')
4+
const logger = require('@vue/cli-shared-utils')
55
const CopyWebpackPlugin = require('copy-webpack-plugin')
66
const ChromeExtensionReloader = require('webpack-chrome-extension-reloader')
77
const WebpackShellPlugin = require('webpack-shell-plugin-next')
@@ -13,9 +13,10 @@ module.exports = (api) => {
1313
const { name, version } = require(path.join(appRootPath, 'package.json'))
1414
const isDevelopment = api.service.mode === 'development'
1515
const isProduction = api.service.mode === 'production'
16+
const outputDir = api.resolve(api.service.projectOptions.outputDir || 'dist')
1617
const packageScript = isProduction ? 'build-zip.js' : 'remove-evals.js'
1718

18-
api.configureWebpack(webpackConfig => {
19+
api.configureWebpack((webpackConfig) => {
1920
webpackConfig.output.filename = '[name].js'
2021
webpackConfig.output.chunkFilename = 'js/[id].[name].js?[hash:8]'
2122

@@ -57,7 +58,11 @@ module.exports = (api) => {
5758
resolve(JSON.stringify(jsonContent, null, 2))
5859
})
5960
} catch (error) {
60-
console.log('No key.pem file found. This is fine for dev, you will have problems publishing without one')
61+
if (isProduction) {
62+
logger.error('no key.pem file found. You cannot publish to the chrome store without one. If this is your first publish, chrome will make a key for you, and you can ignore this message')
63+
} else {
64+
logger.warn('No key.pem file found. This is fine for dev, however you may have problems publishing without one')
65+
}
6166
}
6267
})
6368
}
@@ -77,7 +82,7 @@ module.exports = (api) => {
7782

7883
webpackConfig.plugins.push(new WebpackShellPlugin({
7984
onBuildExit: {
80-
scripts: [`node ${path.join(__dirname, 'scripts', packageScript)}`],
85+
scripts: [`node ${path.join(__dirname, 'scripts', packageScript)} ${outputDir}`],
8186
blocking: true,
8287
parallel: false
8388
}
@@ -93,16 +98,4 @@ module.exports = (api) => {
9398
])
9499
}
95100
})
96-
97-
api.registerCommand('ext-serve', {
98-
description: 'Builds and watches the project, writing the files to the output directory'
99-
}, (...args) => {
100-
log('Starting webpack in watch mode...')
101-
102-
api.configureWebpack((webpackConfig) => {
103-
webpackConfig.watch = true
104-
})
105-
106-
api.service.run('build', ...args)
107-
})
108101
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-cli-plugin-browser-extension",
3-
"version": "0.3.3",
3+
"version": "0.4.0",
44
"description": "Browser extension development plugin for vue-cli 3.0",
55
"main": "index.js",
66
"scripts": {

scripts/build-zip.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const path = require('path')
55
const zipFolder = require('zip-folder')
66

77
const appRootPath = process.cwd()
8-
const DEST_DIR = path.join(appRootPath, 'dist')
9-
const DEST_ZIP_DIR = path.join(appRootPath, 'dist-zip')
8+
const DEST_DIR = process.argv[2]
9+
const DEST_ZIP_DIR = path.join(appRootPath, `${DEST_DIR}-zip`)
1010
const { name, version } = require(path.join(appRootPath, 'package.json'))
1111

1212
const makeDestZipDirIfNotExists = () => {

scripts/remove-evals.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const path = require('path')
44
const fs = require('fs')
5-
const BUNDLE_DIR = path.join(process.cwd(), 'dist')
5+
const BUNDLE_DIR = process.argv[2]
66
const bundles = [
77
'background.js',
88
'popup/popup.js'

0 commit comments

Comments
 (0)