Skip to content

Commit

Permalink
upgrade esbuild to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Jan 9, 2024
1 parent abfa0cd commit 96bf693
Showing 1 changed file with 69 additions and 48 deletions.
117 changes: 69 additions & 48 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import esbuild from "esbuild";
import process from "process";
import builtins from "builtin-modules";
import path from "path";
import fs from "fs";
import { copyFile } from "fs/promises";
import { config } from "dotenv";

config();
Expand All @@ -15,53 +18,71 @@ const prod = process.argv[2] === "production";

const dir = prod ? "./" : process.env.OUTDIR;

esbuild
.build({
banner: {
js: banner
},
loader: { ".ttf": "base64", ".woff": "base64" },
entryPoints: ["src/main.ts", "src/styles.css"],
bundle: true,
external: [
"obsidian",
"get-fonts",
"electron",
"codemirror",
"@codemirror/autocomplete",
"@codemirror/closebrackets",
"@codemirror/collab",
"@codemirror/commands",
"@codemirror/comment",
"@codemirror/fold",
"@codemirror/gutter",
"@codemirror/highlight",
"@codemirror/history",
"@codemirror/language",
"@codemirror/lint",
"@codemirror/matchbrackets",
"@codemirror/panel",
"@codemirror/rangeset",
"@codemirror/rectangular-selection",
"@codemirror/search",
"@codemirror/state",
"@codemirror/stream-parser",
"@codemirror/text",
"@codemirror/tooltip",
"@codemirror/view",
...builtins
],
format: "cjs",
watch: !prod,
target: "es2020",
logLevel: "info",
minify: true,
treeShaking: true,
sourcemap: !prod,
outdir: dir,
metafile: true
})
.catch((e) => {
console.error(e);
const parameters = {
banner: {
js: banner
},
entryPoints: ["src/main.ts", "src/styles.css"],
bundle: true,
external: [
"obsidian",
"electron",
"codemirror",
"@codemirror/autocomplete",
"@codemirror/closebrackets",
"@codemirror/collab",
"@codemirror/commands",
"@codemirror/comment",
"@codemirror/fold",
"@codemirror/gutter",
"@codemirror/highlight",
"@codemirror/history",
"@codemirror/language",
"@codemirror/lint",
"@codemirror/matchbrackets",
"@codemirror/panel",
"@codemirror/rangeset",
"@codemirror/rectangular-selection",
"@codemirror/search",
"@codemirror/state",
"@codemirror/stream-parser",
"@codemirror/text",
"@codemirror/tooltip",
"@codemirror/view",
"moment",
...builtins
],
format: "cjs",
target: "es2022",
logLevel: "info",
sourcemap: prod ? false : "inline",
minify: prod,
treeShaking: true,
outdir: dir

logOverride: { "empty-import-meta": "silent" }
};

await esbuild.build(parameters).catch((x) => {
if (x.errors) {
console.error(x.errors);
} else {
console.error(x);
}
process.exit(1);
});

if (prod) {
await esbuild.build(parameters).catch((x) => {
if (x.errors) {
console.error(x.errors);
} else {
console.error(x);
}
process.exit(1);
});
} else {
let ctx = await esbuild.context(parameters);
await copyFile("./manifest.json", path.resolve(dir, "manifest.json"));
await ctx.watch();
}

0 comments on commit 96bf693

Please sign in to comment.