From 1a474dd44046f326a23166ed28a971696f322e26 Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Thu, 19 Jan 2023 09:42:48 +0000 Subject: [PATCH] Update `esbuild.config.mjs` to work with esbuild v0.17 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `v0.17.x` versions of `esbuild` contain breaking changes that require modifications to your configuration file, `esbuild.config.mjs`. Without these changes, running `npm run build` or `npm run dev` produces an output like this: ``` ✘ [ERROR] Invalid option in build() call: "watch" ``` This updates the config file to match the new requirements, preserving all existing functionality, including our "build" and "dev" modes in `package.json`'s `scripts`. Fixes https://github.com/obsidianmd/obsidian-sample-plugin/issues/45. --- esbuild.config.mjs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/esbuild.config.mjs b/esbuild.config.mjs index b3e3a68..b13282b 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -11,7 +11,7 @@ if you want to view the source, please visit the github repository of this plugi const prod = (process.argv[2] === "production"); -esbuild.build({ +const context = await esbuild.context({ banner: { js: banner, }, @@ -33,10 +33,16 @@ esbuild.build({ "@lezer/lr", ...builtins], format: "cjs", - watch: !prod, target: "es2018", logLevel: "info", sourcemap: prod ? false : "inline", treeShaking: true, outfile: "main.js", -}).catch(() => process.exit(1)); +}); + +if (prod) { + await context.rebuild(); + process.exit(0); +} else { + await context.watch(); +} \ No newline at end of file