-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.production.js
51 lines (47 loc) · 1.47 KB
/
webpack.config.production.js
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
const config = require("./webpack.config.base.js");
const { merge } = require("webpack-merge");
const ZipPlugin = require("zip-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const CopyWebpackPlugin = require('copy-webpack-plugin');
let target = process.env.BROWSER_TARGET;
if (!target) {
throw new Error("Missing required environment variable 'BROWSER_TARGET'");
}
if (!['firefox', 'chrome'].includes(target)) {
throw new Error(`Unsupported browser: ${ target }`);
}
module.exports = merge(config, {
mode: "production",
optimization: {
minimizer: [
new TerserPlugin(),
new OptimizeCSSAssetsPlugin({
cssProcessorPluginOptions: {
preset: [
"default",
{
discardComments: {
removeAll: true,
},
},
],
},
}),
],
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{
context: "public",
from: `manifest.${target}.json`,
to: "manifest.json",
},
],
}),
new ZipPlugin({
filename: target === "chrome" ? "app.chrome" : "app.firefox",
}),
],
});