feat(schema, nuxt): allow user-configurable serverDir (#7868)

This commit is contained in:
Daniel Roe 2022-10-10 11:49:44 +01:00 committed by GitHub
parent 385674494d
commit 81a8a25834
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -19,7 +19,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
const nitroConfig: NitroConfig = defu(_nitroConfig, <NitroConfig>{ const nitroConfig: NitroConfig = defu(_nitroConfig, <NitroConfig>{
rootDir: nuxt.options.rootDir, rootDir: nuxt.options.rootDir,
workspaceDir: nuxt.options.workspaceDir, workspaceDir: nuxt.options.workspaceDir,
srcDir: join(nuxt.options.srcDir, 'server'), srcDir: nuxt.options.serverDir,
dev: nuxt.options.dev, dev: nuxt.options.dev,
preset: nuxt.options.dev ? 'nitro-dev' : undefined, preset: nuxt.options.dev ? 'nitro-dev' : undefined,
buildDir: nuxt.options.buildDir, buildDir: nuxt.options.buildDir,
@ -28,7 +28,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
projectRoot: nuxt.options.rootDir, projectRoot: nuxt.options.rootDir,
filename: join(nuxt.options.rootDir, '.nuxt/stats', '{name}.html') filename: join(nuxt.options.rootDir, '.nuxt/stats', '{name}.html')
}, },
scanDirs: nuxt.options._layers.map(layer => layer.config.srcDir).filter(Boolean).map(dir => join(dir!, 'server')), scanDirs: nuxt.options._layers.map(layer => (layer.config.serverDir || layer.config.srcDir) && resolve(layer.cwd, layer.config.serverDir || resolve(layer.config.srcDir, 'server'))).filter(Boolean),
renderer: resolve(distDir, 'core/runtime/nitro/renderer'), renderer: resolve(distDir, 'core/runtime/nitro/renderer'),
errorHandler: resolve(distDir, 'core/runtime/nitro/error'), errorHandler: resolve(distDir, 'core/runtime/nitro/error'),
nodeModulesDirs: nuxt.options.modulesDir, nodeModulesDirs: nuxt.options.modulesDir,

View File

@ -100,6 +100,18 @@ export default defineUntypedSchema({
$resolve: async (val, get) => resolve(await get('rootDir'), val || '.') $resolve: async (val, get) => resolve(await get('rootDir'), val || '.')
}, },
/**
* Define the server directory of your Nuxt application, where Nitro
* routes, middleware and plugins are kept.
*
* If a relative path is specified, it will be relative to your `rootDir`.
*
* @version 3
*/
serverDir: {
$resolve: async (val, get) => resolve(await get('rootDir'), val || resolve(await get('srcDir'), 'server'))
},
/** /**
* Define the directory where your built Nuxt files will be placed. * Define the directory where your built Nuxt files will be placed.
* *