-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Wrong InterpolateHtmlPlugin hook for env var replacement #6448
Comments
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
Same issue was reported earlier - #5473 |
What about the following example: <% if ("%NODE_ENV%" === "production") { %>
<script>
console.log('it works!');
</script>
<% } %> Since Is it possible to run this plugin before any processing so it will work? Or maybe a better solution would be to pass ENV variables as options to |
This placeholder is not officially support by documentation. |
@GuiHash yes, this is what I am looking for. Thanks for pointing this issue! However, I think it can be done without breaking changes (no need to change the file extension, and syntax right now). I will create separate issue & probably PR with proper description |
Is this a bug report?
Yes
Steps to Reproduce
yarn build
Expected Behavior
Expect index.html output :
Actual Behavior
Actual index.html output :
Why it happens ?
The bug is due to wrong event/hook selection in InterpolateHtmlPlugin.
With beforeEmit event, The uglification of javascript in the index.html is done before the replacement of environment variables, so step by step we have :
How to fix ?
In html-webpack-plugin, html minification (and js uglify) is done via html-minifier just after the afterTemplateExecution.
So we need to use the afterTemplateExecution event to replace env vars before uglify.
It's the first time where we have the html output, so It seams to be more relevant to replace env vars in the html with this hook.
The text was updated successfully, but these errors were encountered: