rna
rna copied to clipboard
[esbuild-plugin-html] Add a preprocess step for HTML plugin ?
Hello,
I tested many (if not all) esbuild html plugins, and this is by far the better. But I have one question: how about adding a preprocess option, that lets user execute task on html at the start of the process? It could be useful to replace some text, or use a preprocessor.
For instance, something like this in the build, to preprocess using ejs
esbuild.build({
...,
plugins: [htmlPlugin({
preprocess(html) {
return ejs.render(html, { title: 'A title' });
}
})]
})
And in the lib, just before lines 182/183 of lib/index.js:
let code = args.code;
if (preprocess) {
code = preprocess(code);
}
const $ = loadHtml(code);
Maybe, I'm thinking in the wrong direction, but I cannot manage to use other preprocessor plugins (like ejs or pug) with HTML files. They all build JS. Thanks.