-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebpack.config.js
More file actions
103 lines (100 loc) · 3.26 KB
/
webpack.config.js
File metadata and controls
103 lines (100 loc) · 3.26 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const glob = require('glob');
const path = require("path");
// const TerserPlugin = require("terser-webpack-plugin");
module.exports = (env, argv) => {
const isDev = argv.mode !== 'production';
const baseConfig = {
mode: isDev ? 'development' : 'production',
// 使用 eval-source-map 在油猴脚本 file://@require 时方便调试:https://webpack.docschina.org/guides/development/#using-source-maps
devtool: isDev ? 'eval-source-map' : 'source-map',
module: {
rules: [
// 转译 TS:https://webpack.docschina.org/loaders/babel-loader、https://www.babeljs.cn/docs/babel-preset-typescript
{
test: /\.ts$/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-typescript']
}
},
exclude: /(node_modules|bower_components)/
}
]
},
// https://webpack.docschina.org/configuration/resolve/#resolve
resolve: {
// 路径映射为别名,方便 import。同时需要在 tsconfig.json 中配置 paths
alias: {
'@utils': path.resolve(__dirname, 'utils/src')
},
// 忽略路径后缀
extensions: ['.ts'],
// 优先解析相对路径。webpack 从 5.72.1 升级到 5.91.0,glob 从 8.0.3 升级到 10.3.10 后,不开启此配置,会导致 glob.sync 报错“Module not found: Error: Can't resolve ”。
preferRelative: true,
},
// 保留注释:https://webpack.docschina.org/plugins/terser-webpack-plugin/#preserve-comments
optimization: {
// 是否压缩最小化代码
minimize: false,
// minimizer: [
// new TerserPlugin({
// terserOptions: {
// format: {
// comments: /\s*(==(\/|)UserScript==|@(name|namespace|version|description|author|license|match|icon|require|grant))/i,
// },
// },
// extractComments: true,
// }),
// ],
},
};
return [
{
...baseConfig,
entry: glob.sync('./core-socialist-values/src/*.ts'),
output: {
path: path.resolve(__dirname, 'core-socialist-values/dist'),
filename: 'core-socialist-values.user.js',
// 清理 /dist 文件夹:https://webpack.docschina.org/guides/output-management/#cleaning-up-the-dist-folder
clean: true
}
},
{
...baseConfig,
entry: glob.sync('./v2ex-replies-pro/src/*.ts'),
output: {
path: path.resolve(__dirname, 'v2ex-replies-pro/dist'),
filename: 'v2ex-replies-pro.user.js',
clean: true
}
},
{
...baseConfig,
entry: glob.sync('./discourse-pro/src/*.ts'),
output: {
path: path.resolve(__dirname, 'discourse-pro/dist'),
filename: 'discourse-pro.user.js',
clean: true
}
},
{
...baseConfig,
entry: glob.sync('./163-mail-pro/src/*.ts'),
output: {
path: path.resolve(__dirname, '163-mail-pro/dist'),
filename: '163-mail-pro.user.js',
clean: true
}
},
{
...baseConfig,
entry: glob.sync('./gemini-pro/src/*.ts'),
output: {
path: path.resolve(__dirname, 'gemini-pro/dist'),
filename: 'gemini-pro.user.js',
clean: true
}
}
];
}