@@ -2,8 +2,8 @@ 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' )
6- const ChromeExtensionReloader = require ( 'webpack-chrome-extension-reloader' )
77const ZipPlugin = require ( 'zip-webpack-plugin' )
88const defaultOptions = { components : { } }
99
@@ -32,6 +32,18 @@ module.exports = (api, options) => {
3232 webpackConfig . output . chunkFilename = 'js/[id].[name].js?[hash:8]'
3333 webpackConfig . node . global = false
3434
35+ if ( pluginOptions . autoImportPolyfill ) {
36+ webpackConfig . plugins . push ( new webpack . ProvidePlugin ( {
37+ 'browser' : 'webextension-polyfill'
38+ } ) )
39+
40+ // Workaround for https://github.com/mozilla/webextension-polyfill/issues/68
41+ webpackConfig . module . rules . push ( {
42+ test : require . resolve ( 'webextension-polyfill' , { paths : [ appRootPath ] } ) ,
43+ use : 'imports-loader?browser=>undefined'
44+ } )
45+ }
46+
3547 if ( isProduction ) {
3648 if ( hasKeyFile ) {
3749 webpackConfig . plugins . push ( new CopyWebpackPlugin ( [ { from : keyFile , to : 'key.pem' } ] ) )
@@ -84,13 +96,14 @@ module.exports = (api, options) => {
8496 } ) )
8597 }
8698
87- if ( isDevelopment ) {
99+ if ( options . api === 'chrome' && isDevelopment ) {
88100 const entries = { background : 'background' }
89101
90102 if ( pluginOptions . components . contentScript ) {
91103 entries . contentScript = 'content-script'
92104 }
93105
106+ const ChromeExtensionReloader = require ( 'webpack-chrome-extension-reloader' )
94107 webpackConfig . plugins . push ( new ChromeExtensionReloader ( { entries } ) )
95108 }
96109 } )
0 commit comments