perf(vite): don't write stub manifest for legacy bundler (#27957)

This commit is contained in:
Daniel Roe 2024-07-02 19:27:38 +01:00 committed by GitHub
parent ebe6c7122c
commit e717937c03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 25 deletions

View File

@ -5,7 +5,6 @@ import { relative, resolve } from 'pathe'
import { withTrailingSlash, withoutLeadingSlash } from 'ufo' import { withTrailingSlash, withoutLeadingSlash } from 'ufo'
import escapeRE from 'escape-string-regexp' import escapeRE from 'escape-string-regexp'
import { normalizeViteManifest } from 'vue-bundle-renderer' import { normalizeViteManifest } from 'vue-bundle-renderer'
import type { Manifest } from 'vue-bundle-renderer'
import type { ViteBuildContext } from './vite' import type { ViteBuildContext } from './vite'
export async function writeManifest (ctx: ViteBuildContext) { export async function writeManifest (ctx: ViteBuildContext) {
@ -13,26 +12,8 @@ export async function writeManifest (ctx: ViteBuildContext) {
const clientDist = resolve(ctx.nuxt.options.buildDir, 'dist/client') const clientDist = resolve(ctx.nuxt.options.buildDir, 'dist/client')
const serverDist = resolve(ctx.nuxt.options.buildDir, 'dist/server') const serverDist = resolve(ctx.nuxt.options.buildDir, 'dist/server')
const devClientManifest: Manifest = {
'@vite/client': {
isEntry: true,
file: '@vite/client',
css: [],
module: true,
resourceType: 'script',
},
[ctx.entry]: {
isEntry: true,
file: ctx.entry,
module: true,
resourceType: 'script',
},
}
const manifestFile = resolve(clientDist, 'manifest.json') const manifestFile = resolve(clientDist, 'manifest.json')
const clientManifest = ctx.nuxt.options.dev const clientManifest = JSON.parse(readFileSync(manifestFile, 'utf-8'))
? devClientManifest
: JSON.parse(readFileSync(manifestFile, 'utf-8'))
const buildAssetsDir = withTrailingSlash(withoutLeadingSlash(ctx.nuxt.options.app.buildAssetsDir)) const buildAssetsDir = withTrailingSlash(withoutLeadingSlash(ctx.nuxt.options.app.buildAssetsDir))
const BASE_RE = new RegExp(`^${escapeRE(buildAssetsDir)}`) const BASE_RE = new RegExp(`^${escapeRE(buildAssetsDir)}`)

View File

@ -146,9 +146,6 @@ export async function buildServer (ctx: ViteBuildContext) {
return return
} }
// Write dev client manifest
await writeManifest(ctx)
if (!ctx.nuxt.options.ssr) { if (!ctx.nuxt.options.ssr) {
await onBuild() await onBuild()
return return

View File

@ -1,8 +1,8 @@
import { writeFile } from 'node:fs/promises' import { mkdir, writeFile } from 'node:fs/promises'
import { pathToFileURL } from 'node:url' import { pathToFileURL } from 'node:url'
import { createApp, createError, defineEventHandler, defineLazyEventHandler, eventHandler, toNodeListener } from 'h3' import { createApp, createError, defineEventHandler, defineLazyEventHandler, eventHandler, toNodeListener } from 'h3'
import { ViteNodeServer } from 'vite-node/server' import { ViteNodeServer } from 'vite-node/server'
import { isAbsolute, normalize, resolve } from 'pathe' import { isAbsolute, join, normalize, resolve } from 'pathe'
import { addDevServerHandler } from '@nuxt/kit' import { addDevServerHandler } from '@nuxt/kit'
import { isFileServingAllowed } from 'vite' import { isFileServingAllowed } from 'vite'
import type { ModuleNode, Plugin as VitePlugin } from 'vite' import type { ModuleNode, Plugin as VitePlugin } from 'vite'
@ -192,6 +192,8 @@ export async function initViteNodeServer (ctx: ViteBuildContext) {
const serverResolvedPath = resolve(distDir, 'runtime/vite-node.mjs') const serverResolvedPath = resolve(distDir, 'runtime/vite-node.mjs')
const manifestResolvedPath = resolve(distDir, 'runtime/client.manifest.mjs') const manifestResolvedPath = resolve(distDir, 'runtime/client.manifest.mjs')
await mkdir(join(ctx.nuxt.options.buildDir, 'dist/server'), { recursive: true })
await writeFile( await writeFile(
resolve(ctx.nuxt.options.buildDir, 'dist/server/server.mjs'), resolve(ctx.nuxt.options.buildDir, 'dist/server/server.mjs'),
`export { default } from ${JSON.stringify(pathToFileURL(serverResolvedPath).href)}`, `export { default } from ${JSON.stringify(pathToFileURL(serverResolvedPath).href)}`,