Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(share-theme): ship the minified build instead of the development one
Claudefa585d492411
diff --git a/apps/build-docs/src/build-docs.ts b/apps/build-docs/src/build-docs.tsindex 1ec341584c..038c9adb16 100644--- a/apps/build-docs/src/build-docs.ts+++ b/apps/build-docs/src/build-docs.ts@@ -290,7 +290,7 @@ export async function buildDocsFromConfig(configPath?: string, gitRootDir?: striif (gitRootDir) {// Build the share theme if we have a gitRootDir (for Trilium project)- execSync(`pnpm run --filter share-theme build`, {+ execSync(`pnpm run --filter share-theme dist`, {stdio: "inherit",cwd: gitRootDir});@@ -311,7 +311,7 @@ export async function buildDocsFromConfig(configPath?: string, gitRootDir?: striexport default async function buildDocs({ gitRootDir }: BuildContext) {// Build the share theme.- execSync(`pnpm run --filter share-theme build`, {+ execSync(`pnpm run --filter share-theme dist`, {stdio: "inherit",cwd: gitRootDir});diff --git a/apps/desktop/scripts/build.ts b/apps/desktop/scripts/build.tsindex 960832c373..6d259fc0b4 100644--- a/apps/desktop/scripts/build.ts+++ b/apps/desktop/scripts/build.ts@@ -28,7 +28,7 @@ async function main() {// The LLM skill sheets moved to core with the rest of the stack, but the// Node hosts still read them from RESOURCE_DIR. See server core_assets.ts.build.copy("/packages/trilium-core/src/assets/llm/skills", "assets/llm/skills/");- build.triggerBuildAndCopyTo("packages/share-theme", "share-theme/assets/");+ build.triggerBuildAndCopyTo("packages/share-theme", "share-theme/assets/", "dist");build.copy("/packages/share-theme/src/templates", "share-theme/templates/");// Copy node modules dependenciesdiff --git a/apps/edit-docs/scripts/build.ts b/apps/edit-docs/scripts/build.tsindex b7b329fd44..880b393343 100644--- a/apps/edit-docs/scripts/build.ts+++ b/apps/edit-docs/scripts/build.ts@@ -11,7 +11,7 @@ async function main() {// Copy assets from server (needed for DB initialization)build.copy("/apps/server/src/assets", "assets/");- build.triggerBuildAndCopyTo("packages/share-theme", "share-theme/assets/");+ build.triggerBuildAndCopyTo("packages/share-theme", "share-theme/assets/", "dist");build.copy("/packages/share-theme/src/templates", "share-theme/templates/");build.copy("/node_modules/ckeditor5/dist/ckeditor5-content.css", "ckeditor5-content.css");build.buildFrontend();diff --git a/apps/server/scripts/build.ts b/apps/server/scripts/build.tsindex 5af3be1ded..dd9cddb3b5 100644--- a/apps/server/scripts/build.ts+++ b/apps/server/scripts/build.ts@@ -27,7 +27,7 @@ async function main() {// `import.meta.url`, which in a split bundle is a hash-named file under chunks/, so the bytes// are handed to it explicitly from here instead. See pdf_renderer.ts.build.copy("/node_modules/@hyzyla/pdfium/dist/pdfium.wasm", "assets/pdfium.wasm");- build.triggerBuildAndCopyTo("packages/share-theme", "share-theme/assets/");+ build.triggerBuildAndCopyTo("packages/share-theme", "share-theme/assets/", "dist");build.copy("/packages/share-theme/src/templates", "share-theme/templates/");// Copy node modules dependenciesdiff --git a/docs/Developer Guide/Developer Guide/Concepts/Share.md b/docs/Developer Guide/Developer Guide/Concepts/Share.mdindex 22dc512f58..4d08e1d7e7 100644--- a/docs/Developer Guide/Developer Guide/Concepts/Share.md+++ b/docs/Developer Guide/Developer Guide/Concepts/Share.md@@ -11,6 +11,9 @@ The share theme represents the layout, styles and scripts behind the Share notes* In `packages/share-theme`, run `pnpm build` to trigger a build. This will generate `dist` which will then be used by the server.* Alternatively, use `pnpm dev` to watch for changes.+* `pnpm dist` is the same build, minified. It is what the app builds run, so a release ships the minified assets while local development keeps readable ones.++Both scripts clear `dist` first, since esbuild writes into it without removing what an earlier build left there — a minified release build would otherwise be copied alongside the unminified files `pnpm install` produces. A `--module=` build (`build-scripts`, `build-styles`) builds one entry point and deliberately does not clear, so it leaves the other's output alone.## Integration with the server for the share functionalitydiff --git a/packages/share-theme/scripts/build.ts b/packages/share-theme/scripts/build.tsindex 79f982c058..55ea42631a 100644--- a/packages/share-theme/scripts/build.ts+++ b/packages/share-theme/scripts/build.ts@@ -3,7 +3,7 @@ import path from "node:path";import dotenv from "dotenv";import * as esbuild from "esbuild";-import { writeFileSync } from "node:fs";+import { rmSync, writeFileSync } from "node:fs";import { createRequire } from "node:module";import { pathToFileURL } from "node:url";import * as sass from "sass";@@ -74,13 +74,24 @@ const sassPlugin: esbuild.Plugin = {}};+const outDir = path.join(rootDir, "dist");+async function runBuild(watch: boolean) {const before = performance.now();++ // esbuild leaves its outdir as it found it, and every `pnpm install` writes an unminified+ // build there, so a minified release build would land beside those files and both sets would+ // be copied into the app. A partial build must not clean: `--module=` builds one of the two+ // entry points and would otherwise delete the other's output.+ if (!modulesRequested.length) {+ rmSync(outDir, { recursive: true, force: true });+ }+const opts: esbuild.BuildOptions = {entryPoints: entryPoints,bundle: true,splitting: true,- outdir: path.join(rootDir, "dist"),+ outdir: outDir,format: "esm",target: ["chrome96"],loader: {diff --git a/scripts/build-utils.ts b/scripts/build-utils.tsindex daec32033c..e14cce3044 100644--- a/scripts/build-utils.ts+++ b/scripts/build-utils.ts@@ -153,9 +153,16 @@ export default class BuildHelper {this.triggerBuildAndCopyTo("packages/pdfjs-viewer", "pdfjs-viewer");}- triggerBuildAndCopyTo(projectToBuild: string, destPath: string) {+ /**+ * Builds another workspace package and copies its `dist` into this one.+ *+ * `script` names the package script to run, for a package whose release build is not its+ * plain `build` — `share-theme` keeps `build` unminified for development and minifies in+ * `dist`.+ */+ triggerBuildAndCopyTo(projectToBuild: string, destPath: string, script = "build") {const projectDir = join(this.rootDir, projectToBuild);- execSync("pnpm build", { cwd: projectDir, stdio: "inherit" });+ execSync(`pnpm ${script}`, { cwd: projectDir, stdio: "inherit" });cpSync(join(projectDir, "dist"), join(this.projectDir, "dist", destPath), { recursive: true });}