diff --git a/webpack.config.js b/webpack.config.js index cf1c28a..b3254e3 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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 = { cjs: { output: { - path: path.resolve(__dirname, 'dist'), - filename: 'windychen-utils.cjs.js', - libraryTarget: 'commonjs2', + 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', + 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' }, + path: path.resolve(__dirname, "dist"), + filename: "windychen-utils.js", + library: { name: "WindychenUtils", type: "umd", export: "default" }, }, }, }; @@ -28,10 +41,11 @@ const configs = { module.exports = (env = {}) => { const format = env.format; - if (!format || format === 'all') { + if (!format || format === "all") { return Object.keys(configs).map((key) => ({ name: key, - entry: './index.js', + entry: "./index.js", + ...commonConfig, ...configs[key], })); } @@ -40,5 +54,5 @@ module.exports = (env = {}) => { throw new Error(`不支持的格式: ${format},可选值: cjs, esm, umd`); } - return { entry: './index.js', ...configs[format] }; + return { entry: "./index.js", ...commonConfig, ...configs[format] }; };