Skip to content

Commit

Permalink
Update esbuild script
Browse files Browse the repository at this point in the history
  • Loading branch information
yinwenhan.98 committed Feb 18, 2024
1 parent a4ef9f5 commit 3c2b5fa
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import esbuild from "esbuild";
import process from "process";
import builtins from 'builtin-modules'
import builtins from "builtin-modules";

const banner =
`/*
Expand All @@ -9,20 +9,40 @@ if you want to view the source, please visit the github repository of this plugi
*/
`;

const prod = (process.argv[2] === 'production');
const prod = (process.argv[2] === "production");

esbuild.build({
const context = await esbuild.context({
banner: {
js: banner,
},
entryPoints: ['main.ts'],
entryPoints: ["main.ts"],
bundle: true,
external: ['obsidian', 'electron', ...builtins],
format: 'cjs',
watch: !prod,
target: 'es2016',
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',
sourcemap: prod ? false : "inline",
treeShaking: true,
outfile: 'main.js',
}).catch(() => process.exit(1));
outfile: "main.js",
});

if (prod) {
await context.rebuild();
process.exit(0);
} else {
await context.watch();
}

0 comments on commit 3c2b5fa

Please sign in to comment.