Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[esbuild-plugin-html] Add a preprocess step for HTML plugin ? #191

Open
iamvdo opened this issue Jun 13, 2024 · 0 comments · May be fixed by #192
Open

[esbuild-plugin-html] Add a preprocess step for HTML plugin ? #191

iamvdo opened this issue Jun 13, 2024 · 0 comments · May be fixed by #192

Comments

@iamvdo
Copy link

iamvdo commented Jun 13, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant