fix(vite-node): entry path and executing in production (#3854)

This commit is contained in:
Anthony Fu 2022-03-24 20:35:09 +08:00 committed by GitHub
parent cd8dbdc01c
commit 11c460fa99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

@ -3,7 +3,9 @@ export default {
* Set to true to generate an async entrypoint for the Vue bundle (for module federation support).
* @version 3
*/
asyncEntry: false,
asyncEntry: {
$resolve: (val, get) => val ?? (get('dev') && get('experimental.viteNode')) ?? false
},
/**
* Use vite-node for on-demand server chunk loading

View File

@ -33,6 +33,7 @@ function createViteNodeMiddleware (ctx: ViteBuildContext): Connect.NextHandleFun
node = new ViteNodeServer(ctx.ssrServer, {
deps: {
inline: [
'nuxt3',
...ctx.nuxt.options.build.transpile as string[]
]
}
@ -55,7 +56,11 @@ function createViteNodeMiddleware (ctx: ViteBuildContext): Connect.NextHandleFun
}
export async function prepareDevServerEntry (ctx: ViteBuildContext) {
const entryPath = resolve(ctx.nuxt.options.appDir, 'entry.async')
let entryPath = resolve(ctx.nuxt.options.appDir, 'entry.async.mjs')
if (!fse.existsSync(entryPath)) {
entryPath = resolve(ctx.nuxt.options.appDir, 'entry.async')
}
const raw = await fse.readFile(resolve(distDir, 'runtime/server.mjs'), 'utf-8')
const host = ctx.nuxt.options.server.host || 'localhost'
const port = ctx.nuxt.options.server.port || '3000'

View File

@ -3,5 +3,8 @@ import { defineNuxtConfig } from 'nuxt3'
export default defineNuxtConfig({
modules: [
'@nuxt/ui'
]
],
experimental: {
viteNode: true
}
})