1+ import path from "path"
2+ import optionGenerator from "./webpack.common"
3+ import FileManagerWebpackPlugin from "filemanager-webpack-plugin"
4+ import webpack from "webpack"
5+
6+ const { name, version } = require ( path . join ( __dirname , '..' , 'package.json' ) )
7+
8+ const outputDir = path . join ( __dirname , '..' , 'dist_prod_safari' )
9+ const normalZipFilePath = path . resolve ( __dirname , '..' , 'market_packages' , `${ name } -${ version } -safari.zip` )
10+
11+ function removeUnsupportedProperties ( manifest : Partial < chrome . runtime . ManifestV2 > ) {
12+ // 1. permissions. 'idle' is not supported
13+ const originPermissions = manifest . permissions || [ ]
14+ const unsupported = [ 'idle' ]
15+ const supported = [ ]
16+ originPermissions . forEach ( perm => ! unsupported . includes ( perm ) && supported . push ( perm ) )
17+ manifest . permissions = supported
18+ }
19+
20+ const options = optionGenerator (
21+ outputDir ,
22+ baseManifest => {
23+ baseManifest . name = 'Timer'
24+ // Remove unsupported properties in Safari
25+ removeUnsupportedProperties ( baseManifest )
26+ }
27+ )
28+
29+ const filemanagerWebpackPlugin = new FileManagerWebpackPlugin ( {
30+ events : {
31+ // Archive at the end
32+ onEnd : [
33+ { delete : [ path . join ( outputDir , '*.LICENSE.txt' ) ] } ,
34+ // Define plugin to archive zip for different markets
35+ {
36+ delete : [ normalZipFilePath ] ,
37+ archive : [ { source : outputDir , destination : normalZipFilePath } ]
38+ }
39+ ]
40+ }
41+ } )
42+
43+ options . mode = 'production'
44+ options . plugins . push ( filemanagerWebpackPlugin as webpack . WebpackPluginInstance )
45+ options . output . path = outputDir
46+
47+ export default options
0 commit comments