Skip to content

Commit 5915fa6

Browse files
committed
Browser polyfill now auto included by default
Removed configuration, but documented an escape route Resolves #50
1 parent 347c517 commit 5915fa6

File tree

11 files changed

+51
-96
lines changed

11 files changed

+51
-96
lines changed

.eslintrc.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
module.exports = {
22
root: true,
33
env: {
4-
node: true
4+
node: true,
5+
webextensions: true,
56
},
67
extends: ['plugin:vue/essential', '@vue/standard'],
78
rules: {
89
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
9-
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
10-
}
11-
}
10+
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
11+
},
12+
};

README.md

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -179,27 +179,6 @@ module.exports = {
179179

180180
Array containing names of mode in which zipping up will trigger after build.
181181

182-
- **api**
183-
184-
- Type: `'chrome'|'browser'`
185-
- Default: `'browser'`
186-
187-
Browser extension API to use.
188-
189-
- **usePolyfill**
190-
191-
- Type: `boolean`
192-
- Default: `true`
193-
194-
Whether to add [webextension-polyfill](https://github.com/mozilla/webextension-polyfill) to polyfill WebExtension APIs in chrome.
195-
196-
- **autoImportPolyfill**
197-
198-
- Type: `boolean`
199-
- Default: `true`
200-
201-
Whether to auto import `webextension-polyfill` using Webpack's [ProvidePlugin](https://webpack.js.org/plugins/provide-plugin/).
202-
203182
- **artifactsDir**
204183

205184
- Type: `string`
@@ -270,6 +249,26 @@ There is some basic usage of it in the manifest, as well as in some of the boile
270249
Since this is largely an out of the box solution provided by the browsers, it is heavily encouraged to utilize it.
271250
If you do not want to translate your app, simply delete the `public/_locales` directory, and no longer use the `browser.i18n` methods.
272251

252+
## Browser Polyfills
253+
254+
This plugin by default adds in the official [mozilla webextension polyfill](https://github.com/mozilla/webextension-polyfill) to the build.
255+
The opinion of this plugin is that developers should be building cross platform, and should have reasonable tooling to do so.
256+
By emphasizing cross platform first, your application will be adhering to the community standards, be ready for distribution to other extension stores, and avoid developing against browser APIs that may have no equivalent.
257+
The polyfill is a no-op on firefox, and only takes up 20.5kb unminified.
258+
259+
If you still feel strongly to not include the polyfill, then this is what you need to add to your webpack chain to do so.
260+
261+
`vue.config.js`
262+
263+
```js
264+
module.exports = {
265+
chainWebpack(config) {
266+
config.plugins.delete('provide-webextension-polyfill');
267+
config.module.rules.delete('provide-webextension-polyfill');
268+
},
269+
};
270+
```
271+
273272
## Testing
274273

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

generator/template/HelloWorld.js.vue

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@
55
</template>
66

77
<script>
8-
<%_ if (options.usePolyfill && !options.autoImportPolyfill) { -%>
9-
import browser from 'webextension-polyfill'
10-
<%_ } -%>
118
export default {
129
name: 'HelloWorld',
1310
mounted () {
14-
<%- options.api %>.runtime.sendMessage({})
11+
browser.runtime.sendMessage({})
1512
},
1613
computed: {
1714
defaultText () {
18-
return <%- options.api %>.i18n.getMessage('extName')
15+
return browser.i18n.getMessage('extName')
1916
}
2017
}
2118
}

generator/template/HelloWorld.ts.vue

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@
66

77
<script lang="ts">
88
import Vue from 'vue'
9-
<%_ if (options.usePolyfill && !options.autoImportPolyfill) { -%>
10-
import browser from 'webextension-polyfill'
11-
<%_ } -%>
9+
1210
export default Vue.extend({
1311
name: 'HelloWorld',
1412
mounted () {
15-
<%- options.api %>.runtime.sendMessage({})
13+
browser.runtime.sendMessage({})
1614
},
1715
computed: {
1816
defaultText () {
19-
return <%- options.api %>.i18n.getMessage('extName')
17+
return browser.i18n.getMessage('extName')
2018
}
2119
}
2220
})

generator/template/background/src/background.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
<%_ if (options.usePolyfill && !options.autoImportPolyfill) { -%>
2-
import browser from 'webextension-polyfill'
3-
<%_ } -%>
4-
51
<%_ if (options.popupPage) { -%>
6-
<%- options.api %>.runtime.onMessage.addListener(function (request, sender, sendResponse) {
2+
browser.runtime.onMessage.addListener(function (request, sender, sendResponse) {
73
<%_ } else { -%>
8-
<%- options.api %>.browserAction.onClicked.addListener(function (tab) {
4+
browser.browserAction.onClicked.addListener(function (tab) {
95
<%_ } -%>
106
console.log('Hello from the background')
117
<%_ if (options.components.contentScripts) { -%>
128

13-
<%- options.api %>.tabs.executeScript({
9+
browser.tabs.executeScript({
1410
file: 'content-script.js',
1511
});
1612
<%_ } -%>

generator/template/background/src/background.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
<%_ if (options.usePolyfill && !options.autoImportPolyfill) { -%>
2-
import browser from 'webextension-polyfill'
3-
<%_ } -%>
4-
51
<%_ if (options.popupPage) { -%>
6-
<%- options.api %>.runtime.onMessage.addListener(function (request, sender, sendResponse) {
2+
browser.runtime.onMessage.addListener(function (request, sender, sendResponse) {
73
<%_ } else { -%>
8-
<%- options.api %>.browserAction.onClicked.addListener(function (tab) {
4+
browser.browserAction.onClicked.addListener(function (tab) {
95
<%_ } -%>
106
console.log('Hello from the background')
117
<%_ if (options.components.contentScripts) { -%>
128

13-
<%- options.api %>.tabs.executeScript({
9+
browser.tabs.executeScript({
1410
file: 'content-script.js',
1511
});
1612
<%_ } -%>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
},
4141
"options_ui": {
4242
"page": "options.html",
43-
"<%- options.api %>_style": true
43+
"browser_style": true
4444
<%_ } -%>
4545
<%_ if (options.components.override) { -%>
4646
},

generator/template/devtools/src/devtools/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Vue from 'vue'
22
import App from './App.vue'
33

4-
<%- options.api %>.devtools.panels.create(<%- options.api %>.i18n.getMessage('extName'), '/assets/logo.png', 'devtools.html')
4+
browser.devtools.panels.create(browser.i18n.getMessage('extName'), '/assets/logo.png', 'devtools.html')
55

66
/* eslint-disable no-new */
77
new Vue({

generator/template/devtools/src/devtools/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Vue from 'vue'
22
import App from './App.vue'
33

4-
<%- options.api %>.devtools.panels.create(<%- options.api %>.i18n.getMessage('extName'), '/assets/logo.png', 'devtools.html')
4+
browser.devtools.panels.create(browser.i18n.getMessage('extName'), '/assets/logo.png', 'devtools.html')
55

66
/* eslint-disable no-new */
77
new Vue({

index.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,19 @@ module.exports = (api, options) => {
106106
]
107107
])
108108

109-
if (pluginOptions.autoImportPolyfill) {
110-
webpackConfig.plugin('provide-webextension-polyfill').use(webpack.ProvidePlugin, [
111-
{
112-
browser: 'webextension-polyfill'
113-
}
114-
])
109+
webpackConfig.plugin('provide-webextension-polyfill').use(webpack.ProvidePlugin, [
110+
{
111+
browser: 'webextension-polyfill'
112+
}
113+
])
115114

116-
// Workaround for https://github.com/mozilla/webextension-polyfill/issues/68
117-
webpackConfig.module
118-
.rule('provide-webextension-polyfill')
119-
.test(require.resolve('webextension-polyfill', { paths: [appRootPath] }))
120-
.use('imports')
121-
.loader('imports-loader')
122-
.options({ browser: '>undefined' })
123-
}
115+
// Workaround for https://github.com/mozilla/webextension-polyfill/issues/68
116+
webpackConfig.module
117+
.rule('provide-webextension-polyfill')
118+
.test(require.resolve('webextension-polyfill', { paths: [appRootPath] }))
119+
.use('imports')
120+
.loader('imports-loader')
121+
.options({ browser: '>undefined' })
124122

125123
if (isProduction) {
126124
// Silence warnings of known large files, like images, sourcemaps, and the zip artifact

0 commit comments

Comments
 (0)