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

perf(vite): remove vite warm up #6227

Closed
wants to merge 2 commits into from
Closed
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
26 changes: 11 additions & 15 deletions packages/vite/src/vite.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
import * as vite from 'vite'
import { join } from 'pathe'
import { resolve } from 'pathe'
import type { Nuxt } from '@nuxt/schema'
import type { InlineConfig, SSROptions } from 'vite'
import { logger, isIgnored } from '@nuxt/kit'
import { isIgnored } from '@nuxt/kit'
import type { Options } from '@vitejs/plugin-vue'
import replace from '@rollup/plugin-replace'
import { sanitizeFilePath } from 'mlly'
import { buildClient } from './client'
import { buildServer } from './server'
import virtual from './plugins/virtual'
import { warmupViteServer } from './utils/warmup'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is not relevant anymore I think we can remove util as well. Only I want to make sure vite and vite-node does the same because in past, without entrywarmup we were simply delaying it until first request.

import { resolveCSSOptions } from './css'
import { composableKeysPlugin } from './plugins/composable-keys'

export interface ViteOptions extends InlineConfig {
vue?: Options
ssr?: SSROptions
devBundler?: 'vite-node' | 'legacy'
}

export interface ViteBuildContext {
nuxt: Nuxt
config: ViteOptions
entry: string
clientServer?: vite.ViteDevServer
ssrServer?: vite.ViteDevServer
}

export async function bundle (nuxt: Nuxt) {
const ctx: ViteBuildContext = {
nuxt,
entry: null!,
config: vite.mergeConfig(
{
resolve: {
Expand All @@ -41,18 +37,23 @@ export async function bundle (nuxt: Nuxt) {
// will be filled in client/server configs
'#build/plugins': '',
'#build': nuxt.options.buildDir,
'/entry.mjs': resolve(nuxt.options.appDir, nuxt.options.experimental.asyncEntry ? 'entry.async' : 'entry'),
'web-streams-polyfill/ponyfill/es2018': 'unenv/runtime/mock/empty',
// Cannot destructure property 'AbortController' of ..
'abort-controller': 'unenv/runtime/mock/empty'
}
},
optimizeDeps: {
entries: [
resolve(nuxt.options.appDir, 'entry.ts')
],
include: ['vue']
},
css: resolveCSSOptions(nuxt),
build: {
rollupOptions: {
output: { sanitizeFileName: sanitizeFilePath }
output: { sanitizeFileName: sanitizeFilePath },
input: resolve(nuxt.options.appDir, 'entry')
},
watch: {
exclude: nuxt.options.ignore
Expand Down Expand Up @@ -85,13 +86,13 @@ export async function bundle (nuxt: Nuxt) {
// In build mode we explicitly override any vite options that vite is relying on
// to detect whether to inject production or development code (such as HMR code)
if (!nuxt.options.dev) {
ctx.config.server!.watch = undefined
ctx.config.build!.watch = undefined
ctx.config.server.watch = undefined
ctx.config.build.watch = undefined
}

await nuxt.callHook('vite:extend', ctx)

nuxt.hook('vite:serverCreated', (server: vite.ViteDevServer, env) => {
nuxt.hook('vite:serverCreated', (server: vite.ViteDevServer) => {
// Invalidate virtual modules when templates are re-generated
ctx.nuxt.hook('app:templatesGenerated', () => {
for (const [id, mod] of server.moduleGraph.idToModuleMap) {
Expand All @@ -100,11 +101,6 @@ export async function bundle (nuxt: Nuxt) {
}
}
})

const start = Date.now()
warmupViteServer(server, [join('/@fs/', ctx.entry)])
.then(() => logger.info(`Vite ${env.isClient ? 'client' : 'server'} warmed up in ${Date.now() - start}ms`))
.catch(logger.error)
})

await buildClient(ctx)
Expand Down