-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
84 lines (84 loc) · 3 KB
/
webpack.config.js
File metadata and controls
84 lines (84 loc) · 3 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
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
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
module.exports = {
entry: './src/index.ts',
mode: 'development',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
experiments: {
asyncWebAssembly: true,
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
//library: 'CordovaApp',
libraryTarget: 'umd',
globalObject: 'this',
clean: true,
pathinfo: false,
},
optimization: {
minimize: true, // 强制启用压缩,即使在development模式下
minimizer: [
// 第一步:Terser 压缩(移除console、精简代码)
new TerserPlugin({
extractComments: false,
terserOptions: {
keep_fnames: false,
keep_classnames: false,
mangle: {
// 保留特定变量名不混淆
reserved: ['其他需要保留的变量'],
toplevel: true,
properties: {
// 强制混淆所有属性(包括全局变量)
reserved: [], // 清空保留列表
// 或者指定要保留的属性
keep_quoted: true,
// 正则表达式匹配要混淆的变量
regex: /^(easyFetch|easyWindow|generateHeaders|commonRequestWithPromise|commonRequestWithData)$/,
}
},
compress: {
/*pure_funcs: [
'console.log',
'console.info',
'console.warn',
'console.error'
],
drop_console: true,*/
dead_code: true,
unused: true,
collapse_vars: true,
reduce_vars: true,
comparisons: true,
booleans: true,
loops: true,
if_return: true,
join_vars: true,
side_effects: true,
passes: 3,
sequences: true, // 使用逗号操作符连接多个语句
conditionals: true, // 优化if条件和条件表达式
evaluate: true, // 尝试计算常量表达式
// 更激进的控制流混淆选项
booleans: true, // 优化布尔表达式
loops: true, // 优化循环
unused: true, // 移除未使用的变量和函数
dead_code: true, // 移除死代码
drop_debugger: true, // 移除debugger语句
},
},
})]},
devtool: 'source-map'
};