fix-ai: 修复引入node模块导致的打包问题
Node.js Build / build (push) Failing after 5s

This commit is contained in:
windychen0
2026-06-06 20:11:41 +08:00
parent 186a4bc48c
commit 0739a7eefc
+27 -13
View File
@@ -1,26 +1,39 @@
const path = require('path'); const path = require("path");
const nodeExternalModules = ["better-sqlite3"];
const commonConfig = {
externals: nodeExternalModules,
resolve: {
fallback: {
fs: false,
path: false,
util: false,
},
},
};
const configs = { const configs = {
cjs: { cjs: {
output: { output: {
path: path.resolve(__dirname, 'dist'), path: path.resolve(__dirname, "dist"),
filename: 'windychen-utils.cjs.js', filename: "windychen-utils.cjs.js",
libraryTarget: 'commonjs2', libraryTarget: "commonjs2",
}, },
}, },
esm: { esm: {
experiments: { outputModule: true }, experiments: { outputModule: true },
output: { output: {
path: path.resolve(__dirname, 'dist'), path: path.resolve(__dirname, "dist"),
filename: 'windychen-utils.esm.js', filename: "windychen-utils.esm.js",
libraryTarget: 'module', libraryTarget: "module",
}, },
}, },
umd: { umd: {
output: { output: {
path: path.resolve(__dirname, 'dist'), path: path.resolve(__dirname, "dist"),
filename: 'windychen-utils.js', filename: "windychen-utils.js",
library: { name: 'WindychenUtils', type: 'umd', export: 'default' }, library: { name: "WindychenUtils", type: "umd", export: "default" },
}, },
}, },
}; };
@@ -28,10 +41,11 @@ const configs = {
module.exports = (env = {}) => { module.exports = (env = {}) => {
const format = env.format; const format = env.format;
if (!format || format === 'all') { if (!format || format === "all") {
return Object.keys(configs).map((key) => ({ return Object.keys(configs).map((key) => ({
name: key, name: key,
entry: './index.js', entry: "./index.js",
...commonConfig,
...configs[key], ...configs[key],
})); }));
} }
@@ -40,5 +54,5 @@ module.exports = (env = {}) => {
throw new Error(`不支持的格式: ${format},可选值: cjs, esm, umd`); throw new Error(`不支持的格式: ${format},可选值: cjs, esm, umd`);
} }
return { entry: './index.js', ...configs[format] }; return { entry: "./index.js", ...commonConfig, ...configs[format] };
}; };