mirror of
https://github.com/vitejs/vite.git
synced 2024-11-22 07:09:05 +00:00
fix: modulePreload false (#13973)
This commit is contained in:
parent
4ca7c13b73
commit
488085d631
@ -344,7 +344,7 @@ export interface InlineConfig extends UserConfig {
|
||||
export type ResolvedConfig = Readonly<
|
||||
Omit<
|
||||
UserConfig,
|
||||
'plugins' | 'css' | 'assetsInclude' | 'optimizeDeps' | 'worker'
|
||||
'plugins' | 'css' | 'assetsInclude' | 'optimizeDeps' | 'worker' | 'build'
|
||||
> & {
|
||||
configFile: string | undefined
|
||||
configFileDependencies: string[]
|
||||
|
@ -593,8 +593,8 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
|
||||
// inject module preload polyfill only when configured and needed
|
||||
const { modulePreload } = config.build
|
||||
if (
|
||||
(modulePreload === true ||
|
||||
(typeof modulePreload === 'object' && modulePreload.polyfill)) &&
|
||||
modulePreload !== false &&
|
||||
modulePreload.polyfill &&
|
||||
(someScriptsAreAsync || someScriptsAreDefer)
|
||||
) {
|
||||
js = `import "${modulePreloadPolyfillId}";\n${js}`
|
||||
|
@ -154,12 +154,7 @@ function preload(
|
||||
export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
|
||||
const ssr = !!config.build.ssr
|
||||
const isWorker = config.isWorker
|
||||
const insertPreload = !(
|
||||
ssr ||
|
||||
!!config.build.lib ||
|
||||
isWorker ||
|
||||
config.build.modulePreload === false
|
||||
)
|
||||
const insertPreload = !(ssr || !!config.build.lib || isWorker)
|
||||
|
||||
const resolveModulePreloadDependencies =
|
||||
config.build.modulePreload && config.build.modulePreload.resolveDependencies
|
||||
@ -448,12 +443,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
|
||||
},
|
||||
|
||||
generateBundle({ format }, bundle) {
|
||||
if (
|
||||
format !== 'es' ||
|
||||
ssr ||
|
||||
isWorker ||
|
||||
config.build.modulePreload === false
|
||||
) {
|
||||
if (format !== 'es' || ssr || isWorker) {
|
||||
return
|
||||
}
|
||||
|
||||
@ -564,14 +554,19 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
|
||||
deps.size > 1 ||
|
||||
// main chunk is removed
|
||||
(hasRemovedPureCssChunk && deps.size > 0)
|
||||
? [...deps]
|
||||
? modulePreload === false
|
||||
? // CSS deps use the same mechanism as module preloads, so even if disabled,
|
||||
// we still need to pass these deps to the preload helper in dynamic imports.
|
||||
[...deps].filter((d) => d.endsWith('.css'))
|
||||
: [...deps]
|
||||
: []
|
||||
|
||||
let renderedDeps: string[]
|
||||
if (normalizedFile && customModulePreloadPaths) {
|
||||
const { modulePreload } = config.build
|
||||
const resolveDependencies =
|
||||
modulePreload && modulePreload.resolveDependencies
|
||||
const resolveDependencies = modulePreload
|
||||
? modulePreload.resolveDependencies
|
||||
: undefined
|
||||
let resolvedDeps: string[]
|
||||
if (resolveDependencies) {
|
||||
// We can't let the user remove css deps as these aren't really preloads, they are just using
|
||||
|
@ -54,8 +54,7 @@ export async function resolvePlugins(
|
||||
preAliasPlugin(config),
|
||||
aliasPlugin({ entries: config.resolve.alias }),
|
||||
...prePlugins,
|
||||
modulePreload === true ||
|
||||
(typeof modulePreload === 'object' && modulePreload.polyfill)
|
||||
modulePreload !== false && modulePreload.polyfill
|
||||
? modulePreloadPolyfillPlugin(config)
|
||||
: null,
|
||||
resolvePlugin({
|
||||
|
@ -19,6 +19,9 @@ describe.runIf(isBuild)('build', () => {
|
||||
|
||||
const html = await page.content()
|
||||
expect(html).not.toMatch(/link rel="modulepreload"/)
|
||||
expect(html).not.toMatch(/link rel="stylesheet"/)
|
||||
|
||||
expect(html).toMatch(
|
||||
/link rel="stylesheet".*?href=".*?\/assets\/hello-\w{8}\.css"/,
|
||||
)
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user