feat: add configuration option to disable automatic "modulepreloads" #7766
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
When being not in
lib
-mode a script is injected in the mainjs
-file which automatically adds chunked files to the html<head>
and links them with<link rel="modulepreload">
or<link rel="preload">
.The following line is responsible for the injection:
vite/packages/vite/src/node/plugins/importAnalysisBuild.ts
Line 94 in 9a93233
In most cases this behaviour is fine, but can lead to problems in combination with glob importing:
<link rel="modulepreload">
s to the recipients<head>
– which leads to overhead in themain.js
I don't need and want (about 2-3kb uncompressed) AND failing fetches as the links link relatively to the base of theurl
.The only possibility (which apparently is being used!) is ugly RegEx/replacement to remove the problematic and in that case unneded code after build time.
This PR introduces a build option to completely disable the injection of the script.
The following issues could benefit from this PR:
Additional context
I didn't add a test – it would be great, if someone with more experience in Vite-development could help out with that! ❤️
What is the purpose of this pull request?
(I'm not sure whether this is more a bug fix or a feature. 😄)
Before submitting the PR, please make sure you do the following
fixes #123
).