mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +00:00
fix(vite): warmup improvements (#7377)
This commit is contained in:
parent
6c462b3315
commit
e4b8c2dc88
@ -18,9 +18,6 @@ import { devStyleSSRPlugin } from './plugins/dev-ssr-css'
|
|||||||
import { viteNodePlugin } from './vite-node'
|
import { viteNodePlugin } from './vite-node'
|
||||||
|
|
||||||
export async function buildClient (ctx: ViteBuildContext) {
|
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, {
|
const clientConfig: vite.InlineConfig = vite.mergeConfig(ctx.config, {
|
||||||
entry: ctx.entry,
|
entry: ctx.entry,
|
||||||
base: ctx.nuxt.options.dev
|
base: ctx.nuxt.options.dev
|
||||||
|
@ -37,6 +37,8 @@ function createRunner () {
|
|||||||
root: viteNodeOptions.root, // Equals to Nuxt `srcDir`
|
root: viteNodeOptions.root, // Equals to Nuxt `srcDir`
|
||||||
base: viteNodeOptions.base,
|
base: viteNodeOptions.base,
|
||||||
async fetchModule (id) {
|
async fetchModule (id) {
|
||||||
|
// TODO: fix in vite-node
|
||||||
|
id = id.replace(/\/\//g, '/')
|
||||||
return await $fetch('/module/' + encodeURI(id), {
|
return await $fetch('/module/' + encodeURI(id), {
|
||||||
baseURL: viteNodeOptions.baseURL
|
baseURL: viteNodeOptions.baseURL
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
|
@ -3,7 +3,7 @@ import { resolve } from 'pathe'
|
|||||||
import * as vite from 'vite'
|
import * as vite from 'vite'
|
||||||
import vuePlugin from '@vitejs/plugin-vue'
|
import vuePlugin from '@vitejs/plugin-vue'
|
||||||
import viteJsxPlugin from '@vitejs/plugin-vue-jsx'
|
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 { joinURL, withoutLeadingSlash, withTrailingSlash } from 'ufo'
|
||||||
import { ViteBuildContext, ViteOptions } from './vite'
|
import { ViteBuildContext, ViteOptions } from './vite'
|
||||||
import { wpfs } from './utils/wpfs'
|
import { wpfs } from './utils/wpfs'
|
||||||
@ -13,10 +13,6 @@ import { ssrStylesPlugin } from './plugins/ssr-styles'
|
|||||||
import { writeManifest } from './manifest'
|
import { writeManifest } from './manifest'
|
||||||
|
|
||||||
export async function buildServer (ctx: ViteBuildContext) {
|
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 _resolve = (id: string) => resolveModule(id, { paths: ctx.nuxt.options.modulesDir })
|
||||||
const serverConfig: vite.InlineConfig = vite.mergeConfig(ctx.config, {
|
const serverConfig: vite.InlineConfig = vite.mergeConfig(ctx.config, {
|
||||||
entry: ctx.entry,
|
entry: ctx.entry,
|
||||||
|
@ -19,8 +19,8 @@ export async function warmupViteServer (
|
|||||||
logger.debug('Warmup for %s failed with: %s', url, e)
|
logger.debug('Warmup for %s failed with: %s', url, e)
|
||||||
}
|
}
|
||||||
const mod = await server.moduleGraph.getModuleByUrl(url, isServer)
|
const mod = await server.moduleGraph.getModuleByUrl(url, isServer)
|
||||||
const deps = Array.from(mod?.importedModules || [])
|
const deps = mod?.ssrTransformResult?.deps /* server */ || Array.from(mod?.importedModules /* client */ || []).map(m => m.url)
|
||||||
await Promise.all(deps.map(m => warmup(m.url.replace('/@id/__x00__', '\0'))))
|
await Promise.all(deps.map(m => warmup(m.replace('/@id/__x00__', '\0'))))
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(entries.map(entry => warmup(entry)))
|
await Promise.all(entries.map(entry => warmup(entry)))
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import * as vite from 'vite'
|
import * as vite from 'vite'
|
||||||
import { join } from 'pathe'
|
import { join, resolve } from 'pathe'
|
||||||
import type { Nuxt } from '@nuxt/schema'
|
import type { Nuxt } from '@nuxt/schema'
|
||||||
import type { InlineConfig, SSROptions } from 'vite'
|
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 type { Options } from '@vitejs/plugin-vue'
|
||||||
import replace from '@rollup/plugin-replace'
|
import replace from '@rollup/plugin-replace'
|
||||||
import { sanitizeFilePath } from 'mlly'
|
import { sanitizeFilePath } from 'mlly'
|
||||||
@ -28,9 +28,12 @@ export interface ViteBuildContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function bundle (nuxt: Nuxt) {
|
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 = {
|
const ctx: ViteBuildContext = {
|
||||||
nuxt,
|
nuxt,
|
||||||
entry: null!,
|
entry,
|
||||||
config: vite.mergeConfig(
|
config: vite.mergeConfig(
|
||||||
{
|
{
|
||||||
resolve: {
|
resolve: {
|
||||||
|
Loading…
Reference in New Issue
Block a user