@@ -65,6 +65,48 @@ module.exports = (api, options) => {
6565 )
6666 webpackConfig . merge ( { entry } )
6767
68+ webpackConfig . plugin ( 'copy-manifest' ) . use ( CopyWebpackPlugin , [
69+ [
70+ {
71+ from : './src/manifest.json' ,
72+ to : 'manifest.json' ,
73+ transform : async ( content ) => {
74+ const jsonContent = JSON . parse ( content )
75+ if ( pluginOptions . manifestSync . includes ( 'version' ) ) {
76+ jsonContent . version = packageJson . version
77+ }
78+ if ( pluginOptions . manifestSync . includes ( 'description' ) ) {
79+ jsonContent . description = packageJson . description
80+ }
81+
82+ // If building for production (going to web store) abort early.
83+ // The browser extension store will hash your signing key and apply CSP policies.
84+ if ( isProduction ) {
85+ return getManifestJsonString ( pluginOptions , jsonContent )
86+ }
87+
88+ jsonContent . content_security_policy =
89+ jsonContent . content_security_policy || "script-src 'self' 'unsafe-eval'; object-src 'self'"
90+
91+ if ( hasKeyFile ) {
92+ try {
93+ jsonContent . key = await hashKey ( keyFile )
94+ } catch ( error ) {
95+ logger . error ( 'Unexpected error hashing keyfile:' , error )
96+ }
97+ }
98+ if ( ! jsonContent . key ) {
99+ logger . warn (
100+ 'No key.pem file found. This is fine for dev, however you may have problems publishing without one'
101+ )
102+ }
103+
104+ return getManifestJsonString ( pluginOptions , jsonContent )
105+ }
106+ }
107+ ]
108+ ] )
109+
68110 if ( pluginOptions . autoImportPolyfill ) {
69111 webpackConfig . plugin ( 'provide-webextension-polyfill' ) . use ( webpack . ProvidePlugin , [
70112 {
@@ -118,45 +160,5 @@ module.exports = (api, options) => {
118160 }
119161
120162 webpackConfig . node . global = false
121-
122- webpackConfig . plugins . push (
123- new CopyWebpackPlugin ( [
124- {
125- from : './src/manifest.json' ,
126- to : 'manifest.json' ,
127- transform : async ( content ) => {
128- const jsonContent = JSON . parse ( content )
129- if ( pluginOptions . manifestSync . includes ( 'version' ) ) {
130- jsonContent . version = packageJson . version
131- }
132- if ( pluginOptions . manifestSync . includes ( 'description' ) ) {
133- jsonContent . description = packageJson . description
134- }
135-
136- if ( isProduction ) {
137- return getManifestJsonString ( pluginOptions , jsonContent )
138- }
139-
140- jsonContent . content_security_policy =
141- jsonContent . content_security_policy || "script-src 'self' 'unsafe-eval'; object-src 'self'"
142-
143- if ( hasKeyFile ) {
144- try {
145- jsonContent . key = await hashKey ( keyFile )
146- } catch ( error ) {
147- logger . error ( 'Unexpected error hashing keyfile:' , error )
148- }
149- }
150- if ( ! jsonContent . key ) {
151- logger . warn (
152- 'No key.pem file found. This is fine for dev, however you may have problems publishing without one'
153- )
154- }
155-
156- return getManifestJsonString ( pluginOptions , jsonContent )
157- }
158- }
159- ] )
160- )
161163 } )
162164}
0 commit comments