Skip to content

Build your personal knowledge base with Trilium Notes

feat(share): add dev mode

Elian Doranbc86fb95b5fa
diff --git a/packages/share-theme/package.json b/packages/share-theme/package.json
index 9a6d36128f..c03ebc0448 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 13b2ac493c..8f90d0828f 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);