-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.mts
More file actions
78 lines (76 loc) · 2.16 KB
/
webpack.config.mts
File metadata and controls
78 lines (76 loc) · 2.16 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
import type {Configuration} from 'webpack';
import nodeExternals from "webpack-node-externals";
import * as path from "node:path";
import CopyPlugin from "copy-webpack-plugin";
import TerserPlugin from "terser-webpack-plugin";
import {fileURLToPath} from "node:url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const config: Configuration = {
mode: "production",
entry: {
index: "./src/index.ts",
// 这会生成 dist/index.js
"types/index": "./src/types/index.ts"
},
devtool: "inline-source-map",
externals: [
nodeExternals({
allowlist: [/electron-util/],
}) as any,
],
optimization: {
minimize: true, // 这里改回 true
minimizer: [
new TerserPlugin({
terserOptions: {
compress: false, // 不压缩逻辑
mangle: false, // 不混淆变量名
output: {
beautify: true, // ✅ 美化输出
indent_level: 2, // 缩进 2 空格
comments: true, // 保留注释
},
},
}),
],
moduleIds: 'named',
chunkIds: 'named',
},
output: {
clean: true,
path: path.resolve(__dirname, "./dist"),
filename: "[name].js",
library: {
type: "umd",
},
},
module: {
rules: [
{
test: /\.ts$/,
use: ["ts-loader"],
},
],
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
plugins: [
new CopyPlugin({
patterns: [
{to: "./types", from: "./src/types/index.ts"},
{to: "./", from: "./src/printer.jar"},
{to: "./", from: "./package.json"},
{to: "./", from: "./LICENSE"},
{to: "./", from: "./PRINT.LICENSE"},
{to: "./", from: "./README.md"},
],
}),
],
target: "node",
node: {
__dirname: false,
},
};
export default config;