generated from siyuan-note/theme-sample
-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.config.cjs
81 lines (80 loc) · 2.31 KB
/
webpack.config.cjs
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
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
module.exports = {
entry: './src/main.ts',
// devtool: 'source-map',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /\/node_modules/,
},
// 添加处理.html文件的规则
{
test: /\.html$/,
use: [
{
loader: 'html-loader',
options: {
minimize: true, // 可选,用于压缩HTML
},
},
],
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: 'theme.js', // 输出文件名
path: path.resolve(__dirname), // 输出目录
},
mode: 'production',
// optimization: {
// minimize: false, // 禁用压缩,调试时使用
// },
externals: {
'@electron/remote': 'commonjs @electron/remote', // 将 @electron/remote 模块作为外部依赖
},
// watch: true,
watchOptions: {
ignored: /node_modules/,
aggregateTimeout: 500,
poll: 3000
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
drop_console: true, // 删除所有console.*函数调用
drop_debugger: true, // 删除所有debugger语句
pure_funcs: ['console.log'], // 删除特定函数调用]
},
mangle: {
keep_classnames: false, // 保留类名
keep_fnames: false, // 保留函数名
toplevel: true, // 混淆顶级作用域中的变量和函数名
properties: {
// 是否混淆对象属性名
regex: /^(?!_)/, // 混淆不以下划线开头的属性名
keep_quoted: true, // 保留引号中的属性名
reserved: ['getCurrentWindow', 'setWindowButtonPosition', 'isFullScreen', 'getAccentColor', 'systemPreferences', 'themeDark', 'themeLight'], // 保留不混淆的属性名
// regex: /^[a-z]*[A-Z][a-z0-9]*/
},
},
format: {
// 输出选项
comments: false, // 去除所有注释
},
},
extractComments: false,
parallel: true, // 启用多进程并行运行以提高构建速度
}),
],
},
// ...
};