hn-hlw-service/esbuild.config.js

23 lines
843 B
JavaScript
Raw Permalink Normal View History

2026-07-27 11:28:33 +08:00
const { build } = require("esbuild");
const envFile = `.env.${process.env.NODE_ENV || 'development'}`;
require('dotenv').config({ path: envFile });
const difineOption = Object.keys(process.env).reduce((prev, key) => {
if (key.startsWith('CONFIG_')) {
prev[`process.env.${key}`] = JSON.stringify(process.env[key]);
}
return prev;
}, {"process.env.IS_BUILDED": '"YES"'})
build({
entryPoints: ["./index.js"], // 入口文件
outfile: `./dist/bundle_${process.env.NODE_ENV}.js`, // 输出文件
platform: "node", // Node.js 平台
bundle: true, // 打包依赖
minify: true, // 压缩代码
sourcemap: false, // 生成 sourcemap 文件,方便调试
target: ["node16", "node19"], // 目标运行时版本
external: ["fs", "path"], // 排除 Node.js 内置模块
define: difineOption
}).catch(() => process.exit(1));