mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
22 lines
619 B
TypeScript
22 lines
619 B
TypeScript
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' }
|
|
})
|
|
}
|
|
}
|
|
}
|