mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 22:59:10 +00:00
fix(html): respect disable modulepreload (#12111)
This commit is contained in:
parent
575bcf61c5
commit
6c5011947e
@ -737,23 +737,25 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
|
||||
toScriptTag(chunk, toOutputAssetFilePath, isAsync),
|
||||
)
|
||||
} else {
|
||||
assetTags = [toScriptTag(chunk, toOutputAssetFilePath, isAsync)]
|
||||
const { modulePreload } = config.build
|
||||
const resolveDependencies =
|
||||
typeof modulePreload === 'object' &&
|
||||
modulePreload.resolveDependencies
|
||||
const importsFileNames = imports.map((chunk) => chunk.fileName)
|
||||
const resolvedDeps = resolveDependencies
|
||||
? resolveDependencies(chunk.fileName, importsFileNames, {
|
||||
hostId: relativeUrlPath,
|
||||
hostType: 'html',
|
||||
})
|
||||
: importsFileNames
|
||||
assetTags = [
|
||||
toScriptTag(chunk, toOutputAssetFilePath, isAsync),
|
||||
...resolvedDeps.map((i) =>
|
||||
toPreloadTag(i, toOutputAssetFilePath),
|
||||
),
|
||||
]
|
||||
if (modulePreload !== false) {
|
||||
const resolveDependencies =
|
||||
typeof modulePreload === 'object' &&
|
||||
modulePreload.resolveDependencies
|
||||
const importsFileNames = imports.map((chunk) => chunk.fileName)
|
||||
const resolvedDeps = resolveDependencies
|
||||
? resolveDependencies(chunk.fileName, importsFileNames, {
|
||||
hostId: relativeUrlPath,
|
||||
hostType: 'html',
|
||||
})
|
||||
: importsFileNames
|
||||
assetTags.push(
|
||||
...resolvedDeps.map((i) =>
|
||||
toPreloadTag(i, toOutputAssetFilePath),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
assetTags.push(...getCssTagsForChunk(chunk, toOutputAssetFilePath))
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
<h1>preload</h1>
|
||||
<div class="chunk"></div>
|
||||
<div id="hello">
|
||||
<button class="load">Load hello</button>
|
||||
<div class="msg"></div>
|
||||
|
1
playground/preload/src/chunk.js
Normal file
1
playground/preload/src/chunk.js
Normal file
@ -0,0 +1 @@
|
||||
export default '[success] message from chunk.js'
|
@ -1,3 +1,7 @@
|
||||
import chunkMsg from './chunk'
|
||||
|
||||
document.querySelector('.chunk').textContent = chunkMsg
|
||||
|
||||
const ids = {
|
||||
hello: async () => {
|
||||
await import(/* a comment */ './hello.js')
|
||||
|
@ -12,6 +12,15 @@ export default defineConfig({
|
||||
passes: 3,
|
||||
},
|
||||
},
|
||||
rollupOptions: {
|
||||
output: {
|
||||
manualChunks(id) {
|
||||
if (id.includes('chunk.js')) {
|
||||
return 'chunk'
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
modulePreload: false,
|
||||
},
|
||||
})
|
||||
|
@ -12,6 +12,15 @@ export default defineConfig({
|
||||
passes: 3,
|
||||
},
|
||||
},
|
||||
rollupOptions: {
|
||||
output: {
|
||||
manualChunks(id) {
|
||||
if (id.includes('chunk.js')) {
|
||||
return 'chunk'
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
modulePreload: {
|
||||
resolveDependencies(filename, deps, { hostId, hostType }) {
|
||||
if (filename.includes('hello')) {
|
||||
|
@ -12,5 +12,14 @@ export default defineConfig({
|
||||
passes: 3,
|
||||
},
|
||||
},
|
||||
rollupOptions: {
|
||||
output: {
|
||||
manualChunks(id) {
|
||||
if (id.includes('chunk.js')) {
|
||||
return 'chunk'
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user