mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 07:32:01 +00:00
perf(nuxt): only inject preload helper when webpack is used (#7460)
This commit is contained in:
parent
1be5e4170b
commit
31de18100c
@ -176,6 +176,11 @@ async function initNuxt (nuxt: Nuxt) {
|
|||||||
// Add prerender payload support
|
// Add prerender payload support
|
||||||
addPlugin(resolve(nuxt.options.appDir, 'plugins/payload.client'))
|
addPlugin(resolve(nuxt.options.appDir, 'plugins/payload.client'))
|
||||||
|
|
||||||
|
// Track components used to render for webpack
|
||||||
|
if (nuxt.options.builder === '@nuxt/webpack-builder') {
|
||||||
|
addPlugin(resolve(nuxt.options.appDir, 'plugins/preload.server'))
|
||||||
|
}
|
||||||
|
|
||||||
for (const m of modulesToInstall) {
|
for (const m of modulesToInstall) {
|
||||||
if (Array.isArray(m)) {
|
if (Array.isArray(m)) {
|
||||||
await installModule(m[0], m[1])
|
await installModule(m[0], m[1])
|
||||||
|
@ -68,8 +68,8 @@ export const serverPluginTemplate: NuxtTemplate<TemplateContext> = {
|
|||||||
filename: 'plugins/server.mjs',
|
filename: 'plugins/server.mjs',
|
||||||
getContents (ctx) {
|
getContents (ctx) {
|
||||||
const serverPlugins = ctx.app.plugins.filter(p => !p.mode || p.mode !== 'client')
|
const serverPlugins = ctx.app.plugins.filter(p => !p.mode || p.mode !== 'client')
|
||||||
const exports: string[] = ['preload']
|
const exports: string[] = []
|
||||||
const imports: string[] = ["import preload from '#app/plugins/preload.server'"]
|
const imports: string[] = []
|
||||||
for (const plugin of serverPlugins) {
|
for (const plugin of serverPlugins) {
|
||||||
const path = relative(ctx.nuxt.options.rootDir, plugin.src)
|
const path = relative(ctx.nuxt.options.rootDir, plugin.src)
|
||||||
const variable = genSafeVariableName(path).replace(/_(45|46|47)/g, '_') + '_' + hash(path)
|
const variable = genSafeVariableName(path).replace(/_(45|46|47)/g, '_') + '_' + hash(path)
|
||||||
|
@ -20,7 +20,7 @@ export default defineUntypedSchema({
|
|||||||
vite: '@nuxt/vite-builder',
|
vite: '@nuxt/vite-builder',
|
||||||
webpack: '@nuxt/webpack-builder',
|
webpack: '@nuxt/webpack-builder',
|
||||||
}
|
}
|
||||||
return map[val] || (await get('vite') === false ? map.webpack : map.vite)
|
return map[val] || val || (await get('vite') === false ? map.webpack : map.vite)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
@ -3,6 +3,7 @@ import { ConfigSchema } from '../../schema/config'
|
|||||||
import type { UserConfig as ViteUserConfig } from 'vite'
|
import type { UserConfig as ViteUserConfig } from 'vite'
|
||||||
import type { Options as VuePluginOptions } from '@vitejs/plugin-vue'
|
import type { Options as VuePluginOptions } from '@vitejs/plugin-vue'
|
||||||
import type { MetaObject } from './meta'
|
import type { MetaObject } from './meta'
|
||||||
|
import type { Nuxt } from './nuxt'
|
||||||
|
|
||||||
type DeepPartial<T> = T extends Function ? T : T extends Record<string, any> ? { [P in keyof T]?: DeepPartial<T[P]> } : T
|
type DeepPartial<T> = T extends Function ? T : T extends Record<string, any> ? { [P in keyof T]?: DeepPartial<T[P]> } : T
|
||||||
|
|
||||||
@ -25,8 +26,9 @@ export type NuxtConfigLayer = ConfigLayer<NuxtConfig & {
|
|||||||
}>
|
}>
|
||||||
|
|
||||||
/** Normalized Nuxt options available as `nuxt.options.*` */
|
/** Normalized Nuxt options available as `nuxt.options.*` */
|
||||||
export interface NuxtOptions extends ConfigSchema {
|
export interface NuxtOptions extends Omit<ConfigSchema, 'builder'> {
|
||||||
sourcemap: Required<Exclude<ConfigSchema['sourcemap'], boolean>>
|
sourcemap: Required<Exclude<ConfigSchema['sourcemap'], boolean>>
|
||||||
|
builder: '@nuxt/vite-builder' | '@nuxt/webpack-builder' | { bundle: (nuxt: Nuxt) => Promise<void> }
|
||||||
_layers: NuxtConfigLayer[]
|
_layers: NuxtConfigLayer[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user