Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
# npm
node_modules

# Don't include the compiled main.js file in the repo.
# Don't include the build artifacts in the repo.
# They should be uploaded to GitHub releases instead.
main.js
dist/

# Exclude sourcemaps
*.map
Expand Down
39 changes: 29 additions & 10 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import process from "node:process";
import path from "node:path";
import { copyFileSync } from "node:fs";

import esbuild from "esbuild";
import process from "process";
import builtins from "builtin-modules";

const banner =
`/*
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 prod = process.argv[2] === "production";

const context = await esbuild.context({
const buildOptions = {
banner: {
js: banner,
},
entryPoints: ["main.ts"],
entryPoints: ["main.ts", "styles.css"],
outdir: "dist",
bundle: true,
external: [
"obsidian",
Expand All @@ -31,18 +34,34 @@ const context = await esbuild.context({
"@lezer/common",
"@lezer/highlight",
"@lezer/lr",
...builtins],
...builtins,
],
format: "cjs",
target: "es2018",
logLevel: "info",
sourcemap: prod ? false : "inline",
treeShaking: true,
outfile: "main.js",
});
};

const context = await esbuild.context(buildOptions);

if (prod) {
await context.rebuild();
/**
* If there is a new version number, copy it to the dist folder
*/
if (process.env.npm_new_version) {
const manifestJsonSrc = path.join(process.cwd(), "manifest.json");
const manifestJsonDist = path.join(
process.cwd(),
buildOptions.outdir,
"manifest.json"
);

// Copy the manifest.json file over to the dist folder
copyFileSync(manifestJsonSrc, manifestJsonDist);
}
process.exit(0);
} else {
await context.watch();
}
}
Loading