File tree Expand file tree Collapse file tree 6 files changed +45
-0
lines changed
standalone/src/standalone/router/pages Expand file tree Collapse file tree 6 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,13 @@ module.exports = (api, options) => {
2929 }
3030 }
3131
32+ if ( options . usePolyfill ) {
33+ pkg . dependencies [ 'webextension-polyfill' ] = '^0.3.0'
34+ pkg . devDependencies = {
35+ 'imports-loader' : '^0.8.0'
36+ }
37+ }
38+
3239 if ( api . hasPlugin ( 'eslint' ) ) {
3340 console . log ( 'Adding eslint config stuffs' )
3441 pkg . eslintConfig = eslintConfig
Original file line number Diff line number Diff line change 11import store from './store'
2+ < % _ if ( options . usePolyfill && ! options . autoImportPolyfill ) { - % >
3+ import browser from 'webextension-polyfill'
4+ < % _ } - % >
25
36< % _ if ( options . popupPage ) { - % >
47< % - options . api % > . runtime . onMessage . addListener ( function ( request , sender , sendResponse ) { < % _ } else { - % >
Original file line number Diff line number Diff line change 33</template >
44
55<script >
6+ < % _ if (options .usePolyfill && ! options .autoImportPolyfill ) { -% >
7+ import browser from ' webextension-polyfill'
8+ < % _ } -% >
9+
610export default {
711 data () {
812 return {}
Original file line number Diff line number Diff line change 33</template >
44
55<script >
6+ < % _ if (options .usePolyfill && ! options .autoImportPolyfill ) { -% >
7+ import browser from ' webextension-polyfill'
8+ < % _ } -% >
9+
610export default {
711 data () {
812 return {}
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ const path = require('path')
22const fs = require ( 'fs' )
33const { exec } = require ( 'child_process' )
44const logger = require ( '@vue/cli-shared-utils' )
5+ const webpack = require ( 'webpack' )
56const CopyWebpackPlugin = require ( 'copy-webpack-plugin' )
67const ChromeExtensionReloader = require ( 'webpack-chrome-extension-reloader' )
78const ZipPlugin = require ( 'zip-webpack-plugin' )
@@ -32,6 +33,18 @@ module.exports = (api, options) => {
3233 webpackConfig . output . chunkFilename = 'js/[id].[name].js?[hash:8]'
3334 webpackConfig . node . global = false
3435
36+ if ( pluginOptions . autoImportPolyfill ) {
37+ webpackConfig . plugins . push ( new webpack . ProvidePlugin ( {
38+ 'browser' : 'webextension-polyfill'
39+ } ) )
40+
41+ // Workaround for https://github.com/mozilla/webextension-polyfill/issues/68
42+ webpackConfig . module . rules . push ( {
43+ test : require . resolve ( 'webextension-polyfill' , { paths : [ appRootPath ] } ) ,
44+ use : 'imports-loader?browser=>undefined'
45+ } )
46+ }
47+
3548 if ( isProduction ) {
3649 if ( hasKeyFile ) {
3750 webpackConfig . plugins . push ( new CopyWebpackPlugin ( [ { from : keyFile , to : 'key.pem' } ] ) )
Original file line number Diff line number Diff line change @@ -57,5 +57,19 @@ module.exports = [
5757 value : 'chrome'
5858 }
5959 ]
60+ } ,
61+ {
62+ name : 'usePolyfill' ,
63+ type : 'confirm' ,
64+ message : 'Add WebExtension polyfill?' ,
65+ default : true ,
66+ when : answers => answers . api === 'browser'
67+ } ,
68+ {
69+ name : 'autoImportPolyfill' ,
70+ type : 'confirm' ,
71+ message : 'Make polyfill available without import?' ,
72+ default : true ,
73+ when : answers => answers . usePolyfill
6074 }
6175]
You can’t perform that action at this time.
0 commit comments