-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathwebpack.config.js
More file actions
120 lines (117 loc) · 2.85 KB
/
webpack.config.js
File metadata and controls
120 lines (117 loc) · 2.85 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import path from 'path';
import { fileURLToPath } from 'url';
import webpack from 'webpack';
import TerserPlugin from 'terser-webpack-plugin';
import fs from 'fs';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// 读取 license 文件内容并转换为注释格式
const licensePath = path.resolve(__dirname, '../license.md');
const licenseContent = fs.readFileSync(licensePath, 'utf8');
const licenseComment = `/*!\n${licenseContent.split('\n').map(line => ` * ${line}`).join('\n')}\n */`;
export default {
mode: 'production',
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'toolgood.algorithm.js',
library: {
name: 'ToolGood.Algorithm',
type: 'umd',
export: 'default'
},
globalObject: 'this'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
targets: {
browsers: ['defaults']
},
modules: false,
useBuiltIns: 'usage',
corejs: 3
}
]
],
plugins: [
'@babel/plugin-transform-runtime'
]
}
}
}
]
},
resolve: {
extensions: ['.js'],
fallback: {
"crypto": "crypto-browserify",
"buffer": "buffer",
"stream": "stream-browserify",
"vm": "vm-browserify",
"string_decoder": "string_decoder",
"path": false,
"fs": false,
"net": false,
"tls": false,
"child_process": false
}
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
},
'process': {
env: {
NODE_ENV: JSON.stringify('production')
},
version: JSON.stringify('')
}
}),
new webpack.BannerPlugin({
banner: licenseComment,
raw: true,
entryOnly: true
})
],
optimization: {
minimize: true,
usedExports: true,
sideEffects: false,
concatenateModules: true,
minimizer: [
new TerserPlugin({
terserOptions: {
mangle: {
toplevel: true,
safari10: false,
properties: {
regex: /^[a-z_][a-zA-Z0-9—_]*$|^(Get|Set|Next|F_|State)[a-zA-Z0-9—_]*$|^[A-Z]+_[A-Z0-9_]+$/,// 小写字母开头都替换
keep_quoted: false,
}
},
compress: {
drop_console: true,
drop_debugger: true,
passes: 3,
}
}
})
]
},
performance: {
hints: false,
maxAssetSize: 1000000,
maxEntrypointSize: 1000000
}
};