mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 15:42:09 +00:00
fix(nuxi): preview nitro build with custom dir config (#18882)
This commit is contained in:
parent
0c9823eb87
commit
9fd398216c
@ -4,6 +4,7 @@ import { execa } from 'execa'
|
|||||||
import { setupDotenv } from 'c12'
|
import { setupDotenv } from 'c12'
|
||||||
import { resolve } from 'pathe'
|
import { resolve } from 'pathe'
|
||||||
import consola from 'consola'
|
import consola from 'consola'
|
||||||
|
import { loadKit } from '../utils/kit'
|
||||||
|
|
||||||
import { defineNuxtCommand } from './index'
|
import { defineNuxtCommand } from './index'
|
||||||
|
|
||||||
@ -16,8 +17,13 @@ export default defineNuxtCommand({
|
|||||||
async invoke (args) {
|
async invoke (args) {
|
||||||
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
|
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
|
||||||
const rootDir = resolve(args._[0] || '.')
|
const rootDir = resolve(args._[0] || '.')
|
||||||
|
const { loadNuxtConfig } = await loadKit(rootDir)
|
||||||
|
const config = await loadNuxtConfig({ cwd: rootDir })
|
||||||
|
|
||||||
const nitroJSONPaths = ['.output/nitro.json', 'nitro.json'].map(p => resolve(rootDir, p))
|
const resolvedOutputDir = resolve(config.srcDir || rootDir, config.nitro.srcDir || 'server', config.nitro.output?.dir || '.output', 'nitro.json')
|
||||||
|
const defaultOutput = resolve(rootDir, '.output', 'nitro.json') // for backwards compatibility
|
||||||
|
|
||||||
|
const nitroJSONPaths = [resolvedOutputDir, defaultOutput]
|
||||||
const nitroJSONPath = nitroJSONPaths.find(p => existsSync(p))
|
const nitroJSONPath = nitroJSONPaths.find(p => existsSync(p))
|
||||||
if (!nitroJSONPath) {
|
if (!nitroJSONPath) {
|
||||||
consola.error('Cannot find `nitro.json`. Did you run `nuxi build` first? Search path:\n', nitroJSONPaths)
|
consola.error('Cannot find `nitro.json`. Did you run `nuxi build` first? Search path:\n', nitroJSONPaths)
|
||||||
|
@ -183,6 +183,9 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Resolve user-provided paths
|
||||||
|
nitroConfig.srcDir = resolve(nuxt.options.rootDir, nuxt.options.srcDir, nitroConfig.srcDir!)
|
||||||
|
|
||||||
// Add head chunk for SPA renders
|
// Add head chunk for SPA renders
|
||||||
const head = createHeadCore()
|
const head = createHeadCore()
|
||||||
head.push(nuxt.options.app.head)
|
head.push(nuxt.options.app.head)
|
||||||
|
Loading…
Reference in New Issue
Block a user