mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +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
|
||||
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) {
|
||||
if (Array.isArray(m)) {
|
||||
await installModule(m[0], m[1])
|
||||
|
@ -68,8 +68,8 @@ export const serverPluginTemplate: NuxtTemplate<TemplateContext> = {
|
||||
filename: 'plugins/server.mjs',
|
||||
getContents (ctx) {
|
||||
const serverPlugins = ctx.app.plugins.filter(p => !p.mode || p.mode !== 'client')
|
||||
const exports: string[] = ['preload']
|
||||
const imports: string[] = ["import preload from '#app/plugins/preload.server'"]
|
||||
const exports: string[] = []
|
||||
const imports: string[] = []
|
||||
for (const plugin of serverPlugins) {
|
||||
const path = relative(ctx.nuxt.options.rootDir, plugin.src)
|
||||
const variable = genSafeVariableName(path).replace(/_(45|46|47)/g, '_') + '_' + hash(path)
|
||||
|
@ -20,7 +20,7 @@ export default defineUntypedSchema({
|
||||
vite: '@nuxt/vite-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 { Options as VuePluginOptions } from '@vitejs/plugin-vue'
|
||||
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
|
||||
|
||||
@ -25,8 +26,9 @@ export type NuxtConfigLayer = ConfigLayer<NuxtConfig & {
|
||||
}>
|
||||
|
||||
/** 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>>
|
||||
builder: '@nuxt/vite-builder' | '@nuxt/webpack-builder' | { bundle: (nuxt: Nuxt) => Promise<void> }
|
||||
_layers: NuxtConfigLayer[]
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user