Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

perf(nuxt): only inject preload helper when webpack is used #7460

Merged
merged 2 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/nuxt/src/core/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
4 changes: 2 additions & 2 deletions packages/nuxt/src/core/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/src/config/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
},
/**
Expand Down
4 changes: 3 additions & 1 deletion packages/schema/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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[]
}

Expand Down