59 lines
1.2 KiB
JavaScript
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] };
|
|
};
|