mirror of
https://github.com/ratiger/obsidian-banyan.git
synced 2026-07-22 05:49:34 +00:00
82 lines
1.6 KiB
JavaScript
82 lines
1.6 KiB
JavaScript
import esbuild from "esbuild";
|
|
import process from "process";
|
|
import builtins from "builtin-modules";
|
|
import fs from "fs";
|
|
|
|
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");
|
|
|
|
const copyPlugin = {
|
|
name: 'copy-plugin',
|
|
setup(build) {
|
|
build.onEnd(() => {
|
|
const src = 'manifest.json';
|
|
const dest = 'dist/manifest.json';
|
|
fs.copyFileSync(src, dest);
|
|
console.log('Copied manifest.json to dist/');
|
|
});
|
|
},
|
|
};
|
|
|
|
// JavaScript构建上下文
|
|
const jsContext = await esbuild.context({
|
|
banner: {
|
|
js: banner,
|
|
},
|
|
entryPoints: ["src/main.ts"],
|
|
bundle: true,
|
|
external: [
|
|
"obsidian",
|
|
"electron",
|
|
"@codemirror/autocomplete",
|
|
"@codemirror/collab",
|
|
"@codemirror/commands",
|
|
"@codemirror/language",
|
|
"@codemirror/lint",
|
|
"@codemirror/search",
|
|
"@codemirror/state",
|
|
"@codemirror/view",
|
|
"@lezer/common",
|
|
"@lezer/highlight",
|
|
"@lezer/lr",
|
|
...builtins],
|
|
format: "cjs",
|
|
target: "es2018",
|
|
logLevel: "info",
|
|
sourcemap: prod ? false : "inline",
|
|
treeShaking: true,
|
|
outfile: "dist/main.js",
|
|
minify: prod,
|
|
loader: {
|
|
".md": "text",
|
|
},
|
|
plugins: [copyPlugin],
|
|
});
|
|
|
|
// CSS构建上下文
|
|
const cssContext = await esbuild.context({
|
|
entryPoints: ["styles.css"],
|
|
bundle: true,
|
|
outfile: "dist/styles.css",
|
|
logLevel: "info",
|
|
minify: prod,
|
|
});
|
|
|
|
if (prod) {
|
|
await Promise.all([
|
|
jsContext.rebuild(),
|
|
cssContext.rebuild()
|
|
]);
|
|
process.exit(0);
|
|
} else {
|
|
await Promise.all([
|
|
jsContext.watch(),
|
|
cssContext.watch()
|
|
]);
|
|
}
|