-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathwebpack.prod.ts
More file actions
53 lines (43 loc) · 2.12 KB
/
webpack.prod.ts
File metadata and controls
53 lines (43 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import optionGenerator from "./webpack.common"
import path from "path"
import FileManagerWebpackPlugin from "filemanager-webpack-plugin"
import webpack from "webpack"
const { name, version } = require(path.join(__dirname, '..', 'package.json'))
const outputDir = path.resolve(__dirname, '..', 'dist_prod')
const option = optionGenerator(outputDir)
option.mode = 'production'
const normalZipFilePath = path.resolve(__dirname, '..', 'market_packages', `${name}-${version}.mv3.zip`)
const sourceCodeForFireFox = path.resolve(__dirname, '..', 'market_packages', `${name}-${version}-src.mv3.zip`)
// Temporary directory for source code to archive on Firefox
const sourceTempDir = path.resolve(__dirname, '..', 'firefox')
const srcDir = ['public', 'src', "test", "types", 'package.json', 'tsconfig.json', 'webpack', "jest.config.ts", "script", ".gitignore"]
const copyMapper = srcDir.map(p => { return { source: path.resolve(__dirname, '..', p), destination: path.resolve(sourceTempDir, p) } })
const readmeForFirefox = path.join(__dirname, '..', 'doc', 'for-fire-fox.md')
const filemanagerWebpackPlugin = new FileManagerWebpackPlugin({
events: {
// Archive at the end
onEnd: [
{ delete: [path.join(outputDir, '*.LICENSE.txt')] },
// Define plugin to archive zip for different markets
{
delete: [normalZipFilePath],
archive: [{ source: outputDir, destination: normalZipFilePath }]
},
// Archive source code for FireFox
{
copy: [
{ source: readmeForFirefox, destination: path.join(sourceTempDir, 'README.md') },
{ source: readmeForFirefox, destination: path.join(sourceTempDir, 'doc', 'for-fire-fox.md') },
...copyMapper
],
archive: [
{ source: sourceTempDir, destination: sourceCodeForFireFox },
],
delete: [sourceTempDir]
}
]
}
})
option.plugins.push(filemanagerWebpackPlugin as webpack.WebpackPluginInstance)
option.output.path = outputDir
export default option