yeban8090_mp-preview/esbuild.config.mjs

59 lines
1.3 KiB
JavaScript
Raw Normal View History

2025-02-26 06:18:12 +00:00
import esbuild from "esbuild";
import process from "process";
import builtins from "builtin-modules";
const banner =
`/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
`;
const prod = process.argv[2] === "production";
2025-04-13 08:13:29 +00:00
const config = {
2025-02-26 06:18:12 +00:00
banner: {
js: banner,
},
entryPoints: ["src/main.ts"],
bundle: true,
external: [
"obsidian",
"electron",
2025-04-13 08:13:29 +00:00
"@codemirror/autocomplete",
2025-02-26 06:18:12 +00:00
...builtins
],
format: "cjs",
2025-04-13 08:13:29 +00:00
target: "es2018",
2025-02-26 06:18:12 +00:00
logLevel: "info",
sourcemap: prod ? false : "inline",
treeShaking: true,
outfile: "main.js",
2025-04-13 08:13:29 +00:00
};
// 修改 CSS 配置部分
const cssConfig = {
entryPoints: ['src/styles/index.css'],
bundle: true,
outfile: 'styles.css', // 直接输出到项目根目录
allowOverwrite: true
};
2025-02-26 06:18:12 +00:00
if (prod) {
2025-04-13 08:13:29 +00:00
await Promise.all([
esbuild.build(config),
esbuild.build(cssConfig)
]).catch(() => process.exit(1));
2025-02-26 06:18:12 +00:00
} else {
2025-04-13 08:13:29 +00:00
const [jsContext, cssContext] = await Promise.all([
esbuild.context(config),
esbuild.context(cssConfig)
]);
await Promise.all([
jsContext.watch(),
cssContext.watch()
]);
console.log("⚡ 正在监听 JavaScript 和 CSS 变更...");
2025-02-26 06:18:12 +00:00
}