Skip to content

Commit

Permalink
build: update esbuild file
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Jan 7, 2025
1 parent a897f1e commit 548b14f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 29 deletions.
42 changes: 42 additions & 0 deletions .esbuild.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { appendFileSync } from "node:fs";
import builtins from "builtin-modules";
import esbuild from "esbuild";

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 production = process.argv[2] === "production";
const analyze = process.argv[2] === "analyze";

//──────────────────────────────────────────────────────────────────────────────

const result = await esbuild
.build({
entryPoints: ["src/main.ts"],
banner: { js: banner + "\n" },
outfile: "main.js",
bundle: true,
// biome-ignore format: no need to inspect this regularly
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: "es2022",
sourcemap: production || analyze ? false : "inline",
minify: production || analyze,
drop: ["debugger"],
treeShaking: true,
logLevel: analyze ? "silent" : "info",
metafile: analyze,
})
.catch(() => process.exit(1));

//──────────────────────────────────────────────────────────────────────────────

// DOCS https://esbuild.github.io/api/index#metafile
if (result.metafile) {
const sizes = await esbuild.analyzeMetafile(result.metafile, { verbose: false });
console.info(sizes);
}

// FIX prevent Obsidian from removing the source map when using dev build
// https://forum.obsidian.md/t/source-map-trimming-in-dev-builds/87612
if (!production) appendFileSync(import.meta.dirname + "/main.js", "\n/* nosourcemap */");
29 changes: 0 additions & 29 deletions esbuild.config.mjs

This file was deleted.

0 comments on commit 548b14f

Please sign in to comment.