@@ -12,17 +12,18 @@ const defaultOptions = {
1212 modesToZip : [ 'production' ]
1313}
1414const performanceAssetFilterList = [
15- ( file ) => ! ( / \. m a p $ / . test ( file ) ) ,
15+ ( file ) => ! / \. m a p $ / . test ( file ) ,
1616 ( file ) => ! file . endsWith ( '.zip' ) ,
17- ( file ) => ! ( / ^ i c o n s \/ / . test ( file ) )
17+ ( file ) => ! / ^ i c o n s \/ / . test ( file )
1818]
1919
2020module . exports = ( api , options ) => {
2121 const appRootPath = api . getCwd ( )
22- const pluginOptions = options . pluginOptions . browserExtension ? Object . assign ( defaultOptions , options . pluginOptions . browserExtension ) : defaultOptions
22+ const pluginOptions = options . pluginOptions . browserExtension
23+ ? Object . assign ( defaultOptions , options . pluginOptions . browserExtension )
24+ : defaultOptions
2325 const componentOptions = pluginOptions . componentOptions
2426 const packageJson = require ( path . join ( appRootPath , 'package.json' ) )
25- const isDevelopment = api . service . mode === 'development'
2627 const isProduction = api . service . mode === 'production'
2728 const keyFile = api . resolve ( 'key.pem' )
2829 const hasKeyFile = fs . existsSync ( keyFile )
@@ -40,10 +41,10 @@ module.exports = (api, options) => {
4041 if ( ! Array . isArray ( paths ) ) {
4142 paths = [ paths ]
4243 }
43- entry [ name ] = paths . map ( path => api . resolve ( path ) )
44+ entry [ name ] = paths . map ( ( path ) => api . resolve ( path ) )
4445 }
4546 }
46- webpackConfig . merge ( { entry} )
47+ webpackConfig . merge ( { entry } )
4748 webpackConfig . optimization . delete ( 'splitChunks' )
4849 } )
4950
@@ -55,16 +56,19 @@ module.exports = (api, options) => {
5556 if ( webpackConfig . performance === undefined ) {
5657 webpackConfig . performance = { }
5758 }
58- webpackConfig . performance . assetFilter = ( assetFilename ) => performanceAssetFilterList . every ( ( filter ) => filter ( assetFilename ) )
59+ webpackConfig . performance . assetFilter = ( assetFilename ) =>
60+ performanceAssetFilterList . every ( ( filter ) => filter ( assetFilename ) )
5961
6062 if ( pluginOptions . autoImportPolyfill ) {
61- webpackConfig . plugins . push ( new webpack . ProvidePlugin ( {
62- 'browser' : 'webextension-polyfill'
63- } ) )
63+ webpackConfig . plugins . push (
64+ new webpack . ProvidePlugin ( {
65+ browser : 'webextension-polyfill'
66+ } )
67+ )
6468
6569 // Workaround for https://github.com/mozilla/webextension-polyfill/issues/68
6670 webpackConfig . module . rules . push ( {
67- test : require . resolve ( 'webextension-polyfill' , { paths : [ appRootPath ] } ) ,
71+ test : require . resolve ( 'webextension-polyfill' , { paths : [ appRootPath ] } ) ,
6872 use : 'imports-loader?browser=>undefined'
6973 } )
7074 }
@@ -77,50 +81,59 @@ module.exports = (api, options) => {
7781 }
7882 }
7983
80- webpackConfig . plugins . push ( new CopyWebpackPlugin ( [ {
81- from : './src/manifest.json' ,
82- to : 'manifest.json' ,
83- transform : ( content ) => {
84- return new Promise ( ( resolve , reject ) => {
85- const jsonContent = JSON . parse ( content )
86- if ( pluginOptions . manifestSync . includes ( 'version' ) ) {
87- jsonContent . version = packageJson . version
88- }
89- if ( pluginOptions . manifestSync . includes ( 'description' ) ) {
90- jsonContent . description = packageJson . description
91- }
92-
93- if ( isProduction ) {
94- return resolve ( JSON . stringify ( jsonContent , null , 2 ) )
95- }
96-
97- jsonContent . content_security_policy = jsonContent . content_security_policy || "script-src 'self' 'unsafe-eval'; object-src 'self'"
98-
99- try {
100- fs . statSync ( keyFile )
84+ webpackConfig . plugins . push (
85+ new CopyWebpackPlugin ( [
86+ {
87+ from : './src/manifest.json' ,
88+ to : 'manifest.json' ,
89+ transform : ( content ) => {
90+ return new Promise ( ( resolve , reject ) => {
91+ const jsonContent = JSON . parse ( content )
92+ if ( pluginOptions . manifestSync . includes ( 'version' ) ) {
93+ jsonContent . version = packageJson . version
94+ }
95+ if ( pluginOptions . manifestSync . includes ( 'description' ) ) {
96+ jsonContent . description = packageJson . description
97+ }
10198
102- return exec ( `openssl rsa -in ${ keyFile } -pubout -outform DER | openssl base64 -A` , ( error , stdout ) => {
103- if ( error ) {
104- // node couldn't execute the command
105- reject ( error )
99+ if ( isProduction ) {
100+ return resolve ( JSON . stringify ( jsonContent , null , 2 ) )
106101 }
107102
108- jsonContent . key = stdout
109- resolve ( JSON . stringify ( jsonContent , null , 2 ) )
103+ jsonContent . content_security_policy =
104+ jsonContent . content_security_policy || "script-src 'self' 'unsafe-eval'; object-src 'self'"
105+
106+ try {
107+ fs . statSync ( keyFile )
108+
109+ return exec ( `openssl rsa -in ${ keyFile } -pubout -outform DER | openssl base64 -A` , ( error , stdout ) => {
110+ if ( error ) {
111+ // node couldn't execute the command
112+ reject ( error )
113+ }
114+
115+ jsonContent . key = stdout
116+ resolve ( JSON . stringify ( jsonContent , null , 2 ) )
117+ } )
118+ } catch ( error ) {
119+ logger . warn (
120+ 'No key.pem file found. This is fine for dev, however you may have problems publishing without one'
121+ )
122+ resolve ( JSON . stringify ( jsonContent , null , 2 ) )
123+ }
110124 } )
111- } catch ( error ) {
112- logger . warn ( 'No key.pem file found. This is fine for dev, however you may have problems publishing without one' )
113- resolve ( JSON . stringify ( jsonContent , null , 2 ) )
114125 }
115- } )
116- }
117- } ] ) )
126+ }
127+ ] )
128+ )
118129
119130 if ( pluginOptions . modesToZip . includes ( api . service . mode ) ) {
120- webpackConfig . plugins . push ( new ZipPlugin ( {
121- path : api . resolve ( `${ options . outputDir || 'dist' } -zip` ) ,
122- filename : `${ packageJson . name } -v${ packageJson . version } -${ api . service . mode } .zip`
123- } ) )
131+ webpackConfig . plugins . push (
132+ new ZipPlugin ( {
133+ path : api . resolve ( `${ options . outputDir || 'dist' } -zip` ) ,
134+ filename : `${ packageJson . name } -v${ packageJson . version } -${ api . service . mode } .zip`
135+ } )
136+ )
124137 }
125138
126139 // configure webpack-extension-reloader for automatic reloading of extension when content and background scripts change (not HMR)
0 commit comments