refactor(share): use custom build plugin

This commit is contained in:
Elian Doran 2025-06-09 11:18:47 +03:00
parent d6bb790e26
commit 7e443e7b8d
No known key found for this signature in database
3 changed files with 22 additions and 2 deletions

View File

@ -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",

View File

@ -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";

View File

@ -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' }
})
}
}
}