fix(vite): warmup improvements (#7377)

This commit is contained in:
Daniel Roe 2022-09-09 10:54:20 +01:00 committed by GitHub
parent 6c462b3315
commit e4b8c2dc88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 13 deletions

View File

@ -18,9 +18,6 @@ import { devStyleSSRPlugin } from './plugins/dev-ssr-css'
import { viteNodePlugin } from './vite-node'
export async function buildClient (ctx: ViteBuildContext) {
const useAsyncEntry = ctx.nuxt.options.experimental.asyncEntry
ctx.entry = resolve(ctx.nuxt.options.appDir, useAsyncEntry ? 'entry.async' : 'entry')
const clientConfig: vite.InlineConfig = vite.mergeConfig(ctx.config, {
entry: ctx.entry,
base: ctx.nuxt.options.dev

View File

@ -37,6 +37,8 @@ function createRunner () {
root: viteNodeOptions.root, // Equals to Nuxt `srcDir`
base: viteNodeOptions.base,
async fetchModule (id) {
// TODO: fix in vite-node
id = id.replace(/\/\//g, '/')
return await $fetch('/module/' + encodeURI(id), {
baseURL: viteNodeOptions.baseURL
}).catch((err) => {

View File

@ -3,7 +3,7 @@ import { resolve } from 'pathe'
import * as vite from 'vite'
import vuePlugin from '@vitejs/plugin-vue'
import viteJsxPlugin from '@vitejs/plugin-vue-jsx'
import { logger, resolveModule, resolvePath } from '@nuxt/kit'
import { logger, resolveModule } from '@nuxt/kit'
import { joinURL, withoutLeadingSlash, withTrailingSlash } from 'ufo'
import { ViteBuildContext, ViteOptions } from './vite'
import { wpfs } from './utils/wpfs'
@ -13,10 +13,6 @@ import { ssrStylesPlugin } from './plugins/ssr-styles'
import { writeManifest } from './manifest'
export async function buildServer (ctx: ViteBuildContext) {
const useAsyncEntry = ctx.nuxt.options.experimental.asyncEntry ||
(ctx.nuxt.options.vite.devBundler === 'vite-node' && ctx.nuxt.options.dev)
ctx.entry = await resolvePath(resolve(ctx.nuxt.options.appDir, useAsyncEntry ? 'entry.async' : 'entry'))
const _resolve = (id: string) => resolveModule(id, { paths: ctx.nuxt.options.modulesDir })
const serverConfig: vite.InlineConfig = vite.mergeConfig(ctx.config, {
entry: ctx.entry,

View File

@ -19,8 +19,8 @@ export async function warmupViteServer (
logger.debug('Warmup for %s failed with: %s', url, e)
}
const mod = await server.moduleGraph.getModuleByUrl(url, isServer)
const deps = Array.from(mod?.importedModules || [])
await Promise.all(deps.map(m => warmup(m.url.replace('/@id/__x00__', '\0'))))
const deps = mod?.ssrTransformResult?.deps /* server */ || Array.from(mod?.importedModules /* client */ || []).map(m => m.url)
await Promise.all(deps.map(m => warmup(m.replace('/@id/__x00__', '\0'))))
}
await Promise.all(entries.map(entry => warmup(entry)))

View File

@ -1,8 +1,8 @@
import * as vite from 'vite'
import { join } from 'pathe'
import { join, resolve } from 'pathe'
import type { Nuxt } from '@nuxt/schema'
import type { InlineConfig, SSROptions } from 'vite'
import { logger, isIgnored } from '@nuxt/kit'
import { logger, isIgnored, resolvePath } from '@nuxt/kit'
import type { Options } from '@vitejs/plugin-vue'
import replace from '@rollup/plugin-replace'
import { sanitizeFilePath } from 'mlly'
@ -28,9 +28,12 @@ export interface ViteBuildContext {
}
export async function bundle (nuxt: Nuxt) {
const useAsyncEntry = nuxt.options.experimental.asyncEntry ||
(nuxt.options.vite.devBundler === 'vite-node' && nuxt.options.dev)
const entry = await resolvePath(resolve(nuxt.options.appDir, useAsyncEntry ? 'entry.async' : 'entry'))
const ctx: ViteBuildContext = {
nuxt,
entry: null!,
entry,
config: vite.mergeConfig(
{
resolve: {