-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.prod.js
90 lines (85 loc) · 2.72 KB
/
webpack.prod.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const TerserPlugin = require('terser-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const path = require('path');
const WebpackUserscript = require('webpack-userscript');
const webpack = require("webpack");
function getConf(env, name) {
const plugins = [
new webpack.DefinePlugin({
"PRODUCTION": true
}),
];
if (env.report) {
plugins.push(new BundleAnalyzerPlugin({
analyzerMode: "static",
openAnalyzer: false,
generateStatsFile: true,
reportFilename: path.join(__dirname, 'report', name, 'report.html'),
statsFilename: path.join(__dirname, 'report', name, 'stats.json'),
}));
}
if (env.userscript) {
plugins.push(new WebpackUserscript({
headers: {
name: 'CR Queue Sorter',
version: `[version]`,
match: 'https://www.crunchyroll.com/home/queue',
grant: [
'unsafeWindow'
]
},
downloadBaseUrl: "https://github.com/edusperoni/cr-queue-sorter/raw/master/release/userscript/bundle.user.js",
updateBaseUrl: "https://github.com/edusperoni/cr-queue-sorter/raw/master/release/userscript/bundle.meta.js"
}));
}
const sourceMapOption = 'hidden-source-map';
return merge(common(env), {
name,
watch: false,
mode: 'production',
devtool: sourceMapOption,
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
cache: true,
terserOptions: {
mangle: true,
output: {
comments: false,
semicolons: !sourceMapOption
},
keep_classnames: true
},
sourceMap: true
})
]
},
plugins: plugins,
output: {
sourceMapFilename: '[file].map'
}
});
}
module.exports = (env) => {
env = env || {};
let {
userscript,
chrome
} = env;
env.chrome = false;
env.userscript = false;
if (!userscript && !chrome) {
userscript = chrome = true;
}
const configs = [];
if (userscript) {
configs.push(getConf({ ...env, userscript: true, subdir: 'userscript' }, 'userscript'));
}
if (chrome) {
configs.push(getConf({ ...env, chrome: true, subdir: 'chrome' }, 'chrome'));
}
return configs;
};