feat(nuxt): add workspaceDir option and add it to modulesDir (#7439)

This commit is contained in:
Daniel Roe 2022-09-12 21:06:17 +01:00 committed by GitHub
parent ceb61ada2b
commit 3753ea0ead
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 2 deletions

View File

@ -18,6 +18,7 @@ export async function initNitro (nuxt: Nuxt) {
const _nitroConfig = ((nuxt.options as any).nitro || {}) as NitroConfig const _nitroConfig = ((nuxt.options as any).nitro || {}) as NitroConfig
const nitroConfig: NitroConfig = defu(_nitroConfig, <NitroConfig>{ const nitroConfig: NitroConfig = defu(_nitroConfig, <NitroConfig>{
rootDir: nuxt.options.rootDir, rootDir: nuxt.options.rootDir,
workspaceDir: nuxt.options.workspaceDir,
srcDir: join(nuxt.options.srcDir, 'server'), srcDir: join(nuxt.options.srcDir, 'server'),
dev: nuxt.options.dev, dev: nuxt.options.dev,
preset: nuxt.options.dev ? 'nitro-dev' : undefined, preset: nuxt.options.dev ? 'nitro-dev' : undefined,

View File

@ -211,6 +211,7 @@ export async function loadNuxt (opts: LoadNuxtOptions): Promise<Nuxt> {
.map(i => new RegExp(`(^|\\/)${escapeRE(i.cwd!.split('node_modules/').pop()!)}(\\/|$)(?!node_modules\\/)`)) .map(i => new RegExp(`(^|\\/)${escapeRE(i.cwd!.split('node_modules/').pop()!)}(\\/|$)(?!node_modules\\/)`))
} }
}]) }])
options.modulesDir.push(resolve(options.workspaceDir, 'node_modules'))
options.modulesDir.push(resolve(pkgDir, 'node_modules')) options.modulesDir.push(resolve(pkgDir, 'node_modules'))
options.build.transpile.push('@nuxt/ui-templates') options.build.transpile.push('@nuxt/ui-templates')
options.alias['vue-demi'] = resolve(options.appDir, 'compat/vue-demi') options.alias['vue-demi'] = resolve(options.appDir, 'compat/vue-demi')

View File

@ -26,7 +26,6 @@ export default defineBuildConfig({
'hookable', 'hookable',
'nitropack', 'nitropack',
'webpack', 'webpack',
'pkg-types',
'webpack-bundle-analyzer', 'webpack-bundle-analyzer',
'rollup-plugin-visualizer', 'rollup-plugin-visualizer',
'vite', 'vite',

View File

@ -26,6 +26,7 @@
"defu": "^6.1.0", "defu": "^6.1.0",
"jiti": "^1.15.0", "jiti": "^1.15.0",
"pathe": "^0.3.7", "pathe": "^0.3.7",
"pkg-types": "^0.3.5",
"postcss-import-resolver": "^2.0.0", "postcss-import-resolver": "^2.0.0",
"scule": "^0.3.2", "scule": "^0.3.2",
"std-env": "^3.2.1", "std-env": "^3.2.1",

View File

@ -4,6 +4,7 @@ import createRequire from 'create-require'
import { pascalCase } from 'scule' import { pascalCase } from 'scule'
import jiti from 'jiti' import jiti from 'jiti'
import defu from 'defu' import defu from 'defu'
import { findWorkspaceDir } from 'pkg-types'
import { RuntimeConfig } from '../types/config' import { RuntimeConfig } from '../types/config'
@ -37,7 +38,7 @@ export default defineUntypedSchema({
theme: null, theme: null,
/** /**
* Define the workspace directory of your application. * Define the root directory of your application.
* *
* This property can be overwritten (for example, running `nuxt ./my-app/` * This property can be overwritten (for example, running `nuxt ./my-app/`
* will set the `rootDir` to the absolute path of `./my-app/` from the * will set the `rootDir` to the absolute path of `./my-app/` from the
@ -51,6 +52,19 @@ export default defineUntypedSchema({
$resolve: val => typeof val === 'string' ? resolve(val) : process.cwd() $resolve: val => typeof val === 'string' ? resolve(val) : process.cwd()
}, },
/**
* Define the workspace directory of your application.
*
* Often this is used when in a monorepo setup. Nuxt will attempt to detect
* your workspace directory automatically, but you can override it here.
*
* It is normally not needed to configure this option.
* @version 3
*/
workspaceDir: {
$resolve: async (val, get) => val ? resolve(await get('rootDir'), val) : await findWorkspaceDir(await get('rootDir')).catch(() => get('rootDir'))
},
/** /**
* Define the source directory of your Nuxt application. * Define the source directory of your Nuxt application.
* *

View File

@ -1819,6 +1819,7 @@ __metadata:
defu: ^6.1.0 defu: ^6.1.0
jiti: ^1.15.0 jiti: ^1.15.0
pathe: ^0.3.7 pathe: ^0.3.7
pkg-types: ^0.3.5
postcss-import-resolver: ^2.0.0 postcss-import-resolver: ^2.0.0
scule: ^0.3.2 scule: ^0.3.2
std-env: ^3.2.1 std-env: ^3.2.1