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

templateContent doesn't do templating #1773

Open
tstibbs opened this issue Dec 1, 2022 · 0 comments
Open

templateContent doesn't do templating #1773

tstibbs opened this issue Dec 1, 2022 · 0 comments

Comments

@tstibbs
Copy link

tstibbs commented Dec 1, 2022

Is your feature request related to a problem? Please describe.

Reading the main docs, I naively assumed that the only real difference between template and templateContent was that template read the content from a file for you. I had assumed that I could take the contents of the file I was providing and instead provide the contents to templateContent and get equivalent output. However, this does not appear to be the case. Example:

Using template
config:

template: './index.html.ejs',
inject: false,

index.html.ejs:

<%= htmlWebpackPlugin.options.title %>

generated index.html:

Webpack App

Using templateContent
config:

templateContent: '<%= htmlWebpackPlugin.options.title %>'
inject: false,

generated index.html:

<%= htmlWebpackPlugin.options.title %>

Describe the solution you'd like

Feature request: I would personally like if strings passed to templateContent would do templating in the same way as files passed to template. Making these consistent would give some advantages, for example I could then use the same template language in both, making it easier to share snippets between different templates. Additionally, not all of my templates are in files. For example, in one case I am reading an html file (provided by an up-stream project) and doing some regex replacement on it to turn it into a template. I'd prefer not to have to write that modified template in to a file just so it can go through the templating engine, it would be simpler to just pass the parsed html directly to HtmlWebpackPlugin.

Doc bug report: the doc for templateContent doesn't (in my view) make this difference clear. The doc on writing your own template does repeatedly give a warning saying "templateContent does not allow to use webpack loaders for your template" - if that's the reason for the behaviour I'm seeing then I didn't infer that from the warning text, so I think it could be make clearer.

Describe alternatives you've considered

The obvious simple workaround is to write the template to a temp file first, which is annoying but not difficult. Raising this ticket because even if the feature request is rejected (on the basis of a simple workaround), I think the docs could be clearer on this point.

Additional context

Node.js v16.18.1
npm: 8.19.3
webpack: 5.75.0
html-webpack-plugin: 5.5.0

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

No branches or pull requests

1 participant