-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
fix: injects scripts into html files without any JS in mpa mode #17968
base: main
Are you sure you want to change the base?
fix: injects scripts into html files without any JS in mpa mode #17968
Conversation
Run & review this pull request in StackBlitz Codeflow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great to have tests for this. You can use playground/legacy
for it. One thing I wonder too if it works correctly if the HTML has <script type="module"
but points to a public file, in that case we shouldn't be removing the script.
@@ -508,6 +508,12 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] { | |||
transformIndexHtml(html, { chunk }) { | |||
if (config.build.ssr) return | |||
if (!chunk) return | |||
if (!chunk.moduleIds.some((moduleId) => moduleId.endsWith('.js'))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the right check, probably chunk.imports.length === 0
is more correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm strange, I was testing using playground/legacy/index.html
locally and was able to see the imports
have the JS chunks, not sure what's going on here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the config file
playground/legacy/vite.config-multiple-input.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix issues #17943
I'm not confident that my solution is sound, and if there are no issues, I plan to add unit tests.
The result after running locally: