Files
windyChenUtils/webpack.config.js
T
windychen0 0739a7eefc
Node.js Build / build (push) Failing after 5s
fix-ai: 修复引入node模块导致的打包问题
2026-06-06 20:11:41 +08:00

59 lines
1.2 KiB
JavaScript

const path = require("path");
const nodeExternalModules = ["better-sqlite3"];
const commonConfig = {
externals: nodeExternalModules,
resolve: {
fallback: {
fs: false,
path: false,
util: false,
},
},
};
const configs = {
cjs: {
output: {
path: path.resolve(__dirname, "dist"),
filename: "windychen-utils.cjs.js",
libraryTarget: "commonjs2",
},
},
esm: {
experiments: { outputModule: true },
output: {
path: path.resolve(__dirname, "dist"),
filename: "windychen-utils.esm.js",
libraryTarget: "module",
},
},
umd: {
output: {
path: path.resolve(__dirname, "dist"),
filename: "windychen-utils.js",
library: { name: "WindychenUtils", type: "umd", export: "default" },
},
},
};
module.exports = (env = {}) => {
const format = env.format;
if (!format || format === "all") {
return Object.keys(configs).map((key) => ({
name: key,
entry: "./index.js",
...commonConfig,
...configs[key],
}));
}
if (!configs[format]) {
throw new Error(`不支持的格式: ${format},可选值: cjs, esm, umd`);
}
return { entry: "./index.js", ...commonConfig, ...configs[format] };
};