-
-
Notifications
You must be signed in to change notification settings - Fork 599
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
[@rollup/plugin-html] Generated HTML includes _all_ JS chunks, should only include entry chunks #1834
Comments
We had an open PR to address this, but it languished and went stale. Happy to review another. |
Aha, found that old PR: #688 |
@shellscape I'm not sure I understand all the back-and-forth in that original PR, but just to clarify, I think this could be a very surgical change to the default template which changes this code plugins/packages/html/src/index.ts Line 38 in d64f8d6
to something like this
and then update/enrich some tests/docs. If that's even approximately correct I can see about spinning up such a PR? |
Sounds good to me. That one was pretty old, I wouldn't give the conversation on that PR much influence and would encourage you to apply a fix as you see it best. |
Expected Behavior
The generated HTML should include
<script>
tags loading only (compiled versions of) the entry points specified ininput
in rollup.js.The stackblitz example above uses a random coin-flip to decide whether or not to execute a dynamic import. This makes rollup splits out the dynamic part of the code, which should not be imported by default (that's the whole point of a dynamic import), so the HTML should look like this:
In the browser it should look like this, depending on the coinflip:
or
Actual Behavior
The generated HTML includes
<script>
tags for those scripts, but ALSO includes<script>
tags for generated assets, including in this example the dynamically loaded code:That means the dynamically loaded JS gets loaded whether or not the code actually opts to perform the load, so you get output that looks like this (depending on the coin flip in main.js).
Additional Information
NOTE WELL that I used dynamic imports to demonstrate this, but this is not specific to dynamic imports, it will affect any situation where there's a
*.js
file that should not be immediately imported, i.e. all cases of code-splitting.The text was updated successfully, but these errors were encountered: