Skip to content

Commit 5389f84

Browse files
authored
Merge pull request #14 from nextgensparx/improve-configuration
Add more options
2 parents 142a603 + 3350582 commit 5389f84

File tree

12 files changed

+177
-66
lines changed

12 files changed

+177
-66
lines changed

README.md

Lines changed: 75 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ It makes some assumptions about your project setup.
1616
I hope to be able to scaffold an app so that identifying the below in unnecessary.
1717

1818
```
19+
|- public/
20+
|- icons/
21+
|- Icons for your extension. Should include a 16, 19, 38, 48, 128 px square image
1922
|- src/
2023
|- assets/
2124
|- Static assets in use in your app, like logo.png
22-
|- icons/
23-
|- Icons for your extension. Should include a 16, 19, 38, 48, 128 px square image
25+
|- content_scripts
26+
|- content-script.js
2427
|- options/ (asked during project generation)
2528
|- App.vue
2629
|- options.html
@@ -50,7 +53,6 @@ I hope to be able to scaffold an app so that identifying the below in unnecessar
5053
|- mutation-types.js
5154
|- mutations.js
5255
|- background.js
53-
|- content-script.js
5456
|- manifest.json
5557
```
5658

@@ -84,9 +86,7 @@ Plugin options can be set inside your `vue.config.js`:
8486
module.exports = {
8587
pluginOptions: {
8688
browserExtension: {
87-
options: {
88-
// options...
89-
}
89+
// options...
9090
}
9191
}
9292
}
@@ -98,18 +98,32 @@ module.exports = {
9898
The browser extension components that will be managed by this plugin.
9999

100100
Valid components are:
101+
- background
101102
- popup
102103
- options
103-
- contentScript
104+
- contentScripts
104105
- standalone
105106

106107
```js
107108
components: {
108-
popup: true,
109-
contentScript: true
109+
background: true,
110+
contentScripts: true
110111
}
111112
```
112113

114+
- **componentOptions**
115+
- Type: `Object.<string, Object>`
116+
117+
See [Component options](#component-options).
118+
119+
- **manifestSync**
120+
- Type: `Array<string>`
121+
- Default: `['version']`
122+
123+
Array containing names of `manifest.json` keys that will be automatically synced with `package.json` on build.
124+
125+
Currently, the only supported keys are `version` and `description`.
126+
113127
- **api**
114128
- Type: `'chrome'|'browser'`
115129
- Default: `'browser'`
@@ -128,6 +142,58 @@ module.exports = {
128142

129143
Whether to auto import `webextension-polyfill` using Webpack's [ProvidePlugin](https://webpack.js.org/plugins/provide-plugin/).
130144

145+
### Component options
146+
147+
Some browser extension components have additional options which can be set as follows:
148+
149+
```js
150+
// vue.config.js
151+
module.exports = {
152+
pluginOptions: {
153+
browserExtension: {
154+
componentOptions: {
155+
// <name of component>: <options>
156+
// e.g.
157+
contentScripts: {
158+
entries: {
159+
'content1': 'src/content-script1.js',
160+
'content2': 'src/content-script2.js'
161+
}
162+
}
163+
}
164+
}
165+
}
166+
}
167+
```
168+
169+
#### background
170+
171+
- **entry**
172+
- Type: `string|Array<string>`
173+
174+
Background script as webpack entry using the [single entry shorthand syntax](https://webpack.js.org/concepts/entry-points/#single-entry-shorthand-syntax).
175+
176+
```js
177+
background: {
178+
entry: 'src/my-background-script.js'
179+
}
180+
```
181+
182+
#### contentScripts
183+
184+
- **entries**
185+
- Type: `{[entryChunkName: string]: string|Array<string>}`
186+
187+
Content scripts as webpack entries using using the [object syntax](https://webpack.js.org/concepts/entry-points/#object-syntax).
188+
189+
```js
190+
contentScripts: {
191+
entries: {
192+
'my-first-content-script': 'src/content-script.js',
193+
'my-second-content-script': 'src/my-second-script.js'
194+
}
195+
}
196+
```
131197

132198
## Testing
133199
This library is following the standard styling of vue projects, and those are really the only tests to perform.

generator/index.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,22 @@ const gitignoreSnippet = `
88
/dist-zip
99
`
1010

11-
module.exports = (api, options) => {
11+
module.exports = (api, _options) => {
12+
const options = Object.assign({}, _options)
13+
options.componentOptions = {}
14+
if (options.components.background) {
15+
options.componentOptions.background = {
16+
entry: 'src/background.js'
17+
}
18+
}
19+
if (options.components.contentScripts) {
20+
options.componentOptions.contentScripts = {
21+
entries: {
22+
'content_scripts/content-script': ['src/content_scripts/content-script.js']
23+
}
24+
}
25+
}
26+
1227
const appRootPath = process.cwd()
1328
const { name } = require(path.join(appRootPath, 'package.json'))
1429
const eslintConfig = { env: { webextensions: true } }
@@ -24,7 +39,7 @@ module.exports = (api, options) => {
2439
vue: {
2540
pages: {},
2641
pluginOptions: {
27-
browserExtension: { options }
42+
browserExtension: options
2843
}
2944
}
3045
}
@@ -44,6 +59,10 @@ module.exports = (api, options) => {
4459
api.extendPackage(pkg)
4560
api.render('./template/base-app', { name, ...options })
4661

62+
if (options.components.background) {
63+
api.render('./template/background', { name, ...options })
64+
}
65+
4766
if (options.components.popup) {
4867
api.render('./template/popup', { name, ...options })
4968

@@ -73,7 +92,7 @@ module.exports = (api, options) => {
7392
}
7493
}
7594

76-
if (options.components.contentScript) {
95+
if (options.components.contentScripts) {
7796
api.render('./template/content-script', { ...options })
7897
}
7998

generator/template/base-app/src/manifest.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99
"128": "icons/128.png"
1010
},
1111
"permissions": [
12-
<%_ if (options.components.contentScript) { -%>
12+
<%_ if (options.components.contentScripts) { -%>
1313
"activeTab",
1414
<%_ } -%>
1515
"<all_urls>",
1616
"*://*/*"
1717
],
18+
<%_ if (options.components.background) { -%>
1819
"background": {
1920
"scripts": ["background.js"],
2021
"persistent": false
2122
},
23+
<%_ } -%>
2224
"browser_action": {
2325
<%_ if (options.components.popup) { -%>
2426
"default_popup": "popup/popup.html",

0 commit comments

Comments
 (0)