refactor(vite): reuse resolved server entry from context (#7268)

This commit is contained in:
Daniel Roe 2022-09-06 09:21:17 +01:00 committed by GitHub
parent 173aead937
commit a4fa070ad5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 8 deletions

View File

@ -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 } from '@nuxt/kit' import { logger, resolveModule, resolvePath } 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'
@ -14,7 +14,7 @@ import { ssrStylesPlugin } from './plugins/ssr-styles'
export async function buildServer (ctx: ViteBuildContext) { export async function buildServer (ctx: ViteBuildContext) {
const useAsyncEntry = ctx.nuxt.options.experimental.asyncEntry || const useAsyncEntry = ctx.nuxt.options.experimental.asyncEntry ||
(ctx.nuxt.options.vite.devBundler === 'vite-node' && ctx.nuxt.options.dev) (ctx.nuxt.options.vite.devBundler === 'vite-node' && ctx.nuxt.options.dev)
ctx.entry = resolve(ctx.nuxt.options.appDir, useAsyncEntry ? 'entry.async' : 'entry') 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, {

View File

@ -123,11 +123,6 @@ function createViteNodeMiddleware (ctx: ViteBuildContext, invalidates: Set<strin
} }
export async function initViteNodeServer (ctx: ViteBuildContext) { export async function initViteNodeServer (ctx: ViteBuildContext) {
let entryPath = resolve(ctx.nuxt.options.appDir, 'entry.async.mjs')
if (!fse.existsSync(entryPath)) {
entryPath = resolve(ctx.nuxt.options.appDir, 'entry.async')
}
const host = ctx.nuxt.options.server.host || 'localhost' const host = ctx.nuxt.options.server.host || 'localhost'
const port = ctx.nuxt.options.server.port || '3000' const port = ctx.nuxt.options.server.port || '3000'
const protocol = ctx.nuxt.options.server.https ? 'https' : 'http' const protocol = ctx.nuxt.options.server.https ? 'https' : 'http'
@ -136,7 +131,7 @@ export async function initViteNodeServer (ctx: ViteBuildContext) {
const viteNodeServerOptions = { const viteNodeServerOptions = {
baseURL: `${protocol}://${host}:${port}/__nuxt_vite_node__`, baseURL: `${protocol}://${host}:${port}/__nuxt_vite_node__`,
root: ctx.nuxt.options.srcDir, root: ctx.nuxt.options.srcDir,
entryPath, entryPath: ctx.entry,
base: ctx.ssrServer!.config.base || '/_nuxt/' base: ctx.ssrServer!.config.base || '/_nuxt/'
} }
process.env.NUXT_VITE_NODE_OPTIONS = JSON.stringify(viteNodeServerOptions) process.env.NUXT_VITE_NODE_OPTIONS = JSON.stringify(viteNodeServerOptions)