Skip to content

Build your personal knowledge base with Trilium Notes

refactor(share): use custom build plugin

Elian Doran7e443e7b8d20
diff --git a/packages/share-theme/package.json b/packages/share-theme/package.json
index 8950f47a29..6120927658 100644
--- a/packages/share-theme/package.json
+++ b/packages/share-theme/package.json
@@ -18,7 +18,6 @@
"license": "ISC",
"devDependencies": {
"@digitak/esrun": "^3.2.24",
- "@digitalmaas/esbuild-plugin-ejs": "1.0.0",
"@types/swagger-ui": "^3.52.0",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "^6.7.2",
diff --git a/packages/share-theme/scripts/build.ts b/packages/share-theme/scripts/build.ts
index ef36d18049..39d24c9623 100644
--- a/packages/share-theme/scripts/build.ts
+++ b/packages/share-theme/scripts/build.ts
@@ -1,6 +1,6 @@
import fs from "node:fs";
import path from "node:path";
-import ejsPlugin from "@digitalmaas/esbuild-plugin-ejs";
+import ejsPlugin from "./esbuild-ejs-plugin.js";
// import {fileURLToPath} from "node:url";
import dotenv from "dotenv";
diff --git a/packages/share-theme/scripts/esbuild-ejs-plugin.ts b/packages/share-theme/scripts/esbuild-ejs-plugin.ts
new file mode 100644
index 0000000000..1b74bc283e
--- /dev/null
+++ b/packages/share-theme/scripts/esbuild-ejs-plugin.ts
@@ -0,0 +1,21 @@
+import { readFile } from 'fs/promises';
+import { compile } from 'ejs';
+
+export default function esbuildPluginEjs(options = {}) {
+ return {
+ name: 'ejs',
+ setup(build) {
+ build.onLoad({ filter: /\.ejs$/ }, async args => {
+ const template = await readFile(args.path, 'utf8')
+ const ejsOptions = {
+ ...options,
+ client: true,
+ strict: true,
+ compileDebug: false }
+ const generator = compile(template, ejsOptions)
+ const contents = `module.exports = ${generator.toString()};`
+ return { contents, loader: 'js' }
+ })
+ }
+ }
+}