forked from gewechaty/gewechaty
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
77 lines (77 loc) · 2.31 KB
/
webpack.config.js
File metadata and controls
77 lines (77 loc) · 2.31 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
const path = require('path');
// const glob = require('glob'); // 用于获取所有的 JS 文件
module.exports = {
// entry: glob.sync('./src/**/*.js').reduce((entries, file) => {
// // 删除 src/ 部分,只保留 src 下的文件及其相对路径
// const filePath = file.replace('src/', '');
// entries[filePath] = path.resolve(__dirname, file);
// return entries;
// }, {}),
entry: './src/index.js', // 指定你的入口文件
output: {
filename: 'index.js', // 打包后的文件名
path: path.resolve(__dirname, 'dist'), // 输出到 dist 目录
library: 'WechatBot',
libraryTarget: 'umd',
// filename: '[name]', // 使用相对路径保留文件结构
},
target: 'node', // 指定目标为 Node.js
mode: 'production', // 开发模式
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'), // 定义别名 @ 对应 ./src 目录
},
extensions: ['.js'], // 支持导入的文件类型
},
// 添加缓存配置
cache: {
type: 'filesystem', // 使用文件系统缓存
buildDependencies: {
config: [__filename], // 构建依赖
},
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'swc-loader',
options: {
jsc: {
parser: {
syntax: "ecmascript"
},
target: "es2015"
}
}
}
}
]
},
// optimization: {
// splitChunks: {
// chunks: 'all', // 分割所有的代码,包括动态引入
// minSize: 30000, // 当模块超过 30kb 时进行代码分割
// maxInitialRequests: 3, // 最大并行请求数
// cacheGroups: {
// vendors: {
// test: /[\\/]node_modules[\\/]/, // 分离 node_modules 中的代码
// name: 'vendors',
// chunks: 'all',
// },
// },
// },
// },
externals: {
'better-sqlite3': 'commonjs better-sqlite3',
'ds': 'commonjs ds',
'bun:sqlite': 'commonjs bun:sqlite', // 供 Bun 运行时环境使用,有兼容层
// 'node:sqlite': 'commonjs node:sqlite', // 防止旧版本无法打包
},
// 添加性能优化配置
optimization: {
moduleIds: 'deterministic', // 优化模块 ID
minimize: true, // 启用压缩
}
};