mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-19 01:45:53 +00:00
perf(vite): use stub entry in vite server build when ssr: false
(#18782)
This commit is contained in:
parent
76a08e3ccd
commit
39747ce095
1
packages/nuxt/src/app/entry-spa.ts
Normal file
1
packages/nuxt/src/app/entry-spa.ts
Normal file
@ -0,0 +1 @@
|
||||
export default () => {}
|
@ -2,7 +2,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 } from '@nuxt/kit'
|
||||
import { logger, resolveModule, resolvePath } from '@nuxt/kit'
|
||||
import { joinURL, withoutLeadingSlash, withTrailingSlash } from 'ufo'
|
||||
import type { ViteBuildContext, ViteOptions } from './vite'
|
||||
import { cacheDirPlugin } from './plugins/cache-dir'
|
||||
@ -14,8 +14,9 @@ import { transpile } from './utils/transpile'
|
||||
export async function buildServer (ctx: ViteBuildContext) {
|
||||
const _resolve = (id: string) => resolveModule(id, { paths: ctx.nuxt.options.modulesDir })
|
||||
const helper = ctx.nuxt.options.nitro.imports !== false ? '' : 'globalThis.'
|
||||
const entry = ctx.nuxt.options.ssr ? ctx.entry : await resolvePath(resolve(ctx.nuxt.options.appDir, 'entry-spa'))
|
||||
const serverConfig: vite.InlineConfig = vite.mergeConfig(ctx.config, {
|
||||
entry: ctx.entry,
|
||||
entry,
|
||||
base: ctx.nuxt.options.dev
|
||||
? joinURL(ctx.nuxt.options.app.baseURL.replace(/^\.\//, '/') || '/', ctx.nuxt.options.app.buildAssetsDir)
|
||||
: undefined,
|
||||
@ -47,7 +48,7 @@ export async function buildServer (ctx: ViteBuildContext) {
|
||||
'typeof XMLHttpRequest': '"undefined"'
|
||||
},
|
||||
optimizeDeps: {
|
||||
entries: [ctx.entry]
|
||||
entries: ctx.nuxt.options.ssr ? [ctx.entry] : []
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
@ -82,9 +83,9 @@ export async function buildServer (ctx: ViteBuildContext) {
|
||||
build: {
|
||||
sourcemap: ctx.nuxt.options.sourcemap.server ? ctx.config.build?.sourcemap ?? true : false,
|
||||
outDir: resolve(ctx.nuxt.options.buildDir, 'dist/server'),
|
||||
ssr: ctx.nuxt.options.ssr ?? true,
|
||||
ssr: true,
|
||||
rollupOptions: {
|
||||
input: ctx.entry,
|
||||
input: entry,
|
||||
external: ['#internal/nitro', ...ctx.nuxt.options.experimental.externalVue ? ['vue', 'vue-router'] : []],
|
||||
output: {
|
||||
entryFileNames: 'server.mjs',
|
||||
|
Loading…
Reference in New Issue
Block a user