mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 09:02:03 +00:00
refactor(vite): reuse resolved server entry from context (#7268)
This commit is contained in:
parent
173aead937
commit
a4fa070ad5
@ -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, {
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user