From bc86fb95b5faea36e0cbcd218ed65e64374582bd Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Wed, 29 Oct 2025 18:27:43 +0200 Subject: [PATCH] feat(share): add dev mode --- packages/share-theme/package.json | 1 + packages/share-theme/scripts/build.ts | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/share-theme/package.json b/packages/share-theme/package.json index 9a6d36128..c03ebc044 100644 --- a/packages/share-theme/package.json +++ b/packages/share-theme/package.json @@ -5,6 +5,7 @@ "type": "module", "main": "index.js", "scripts": { + "dev": "esrun scripts/build.ts -- --watch", "build": "esrun scripts/build.ts", "build-scripts": "esrun scripts/build.ts -- --module=scripts", "build-styles": "esrun scripts/build.ts -- --module=styles", diff --git a/packages/share-theme/scripts/build.ts b/packages/share-theme/scripts/build.ts index 13b2ac493..8f90d0828 100644 --- a/packages/share-theme/scripts/build.ts +++ b/packages/share-theme/scripts/build.ts @@ -45,9 +45,9 @@ for (const mod of modulesRequested) { if (!entryPoints.length) for (const mod of modules) entryPoints.push(makeEntry(mod)); -async function runBuild() { +async function runBuild(watch: boolean) { const before = performance.now(); - await esbuild.build({ + const opts: esbuild.BuildOptions = { entryPoints: entryPoints, bundle: true, splitting: true, @@ -68,9 +68,16 @@ async function runBuild() { logLevel: "info", metafile: true, minify: process.argv.includes("--minify") - }); - const after = performance.now(); - console.log(`Build actually took ${(after - before).toFixed(2)}ms`); + }; + if (watch) { + const ctx = esbuild.context(opts); + (await ctx).watch(); + } else { + await esbuild.build(opts); + const after = performance.now(); + console.log(`Build actually took ${(after - before).toFixed(2)}ms`); + } } -runBuild().catch(console.error); +const watch = process.argv.includes("--watch"); +runBuild(watch).catch(console.error);