mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-01 18:07:22 +00:00
feat(cli): programmatically pass nuxt config overrides (to dev) (#19371)
This commit is contained in:
parent
c2ab76d68e
commit
e344321d92
@ -22,7 +22,7 @@ export default defineNuxtCommand({
|
|||||||
usage: 'npx nuxi dev [rootDir] [--dotenv] [--log-level] [--clipboard] [--open, -o] [--port, -p] [--host, -h] [--https] [--ssl-cert] [--ssl-key]',
|
usage: 'npx nuxi dev [rootDir] [--dotenv] [--log-level] [--clipboard] [--open, -o] [--port, -p] [--host, -h] [--https] [--ssl-cert] [--ssl-key]',
|
||||||
description: 'Run nuxt development server'
|
description: 'Run nuxt development server'
|
||||||
},
|
},
|
||||||
async invoke (args) {
|
async invoke (args, options = {}) {
|
||||||
overrideEnv('development')
|
overrideEnv('development')
|
||||||
|
|
||||||
const { listen } = await import('listhen')
|
const { listen } = await import('listhen')
|
||||||
@ -50,7 +50,8 @@ export default defineNuxtCommand({
|
|||||||
cwd: rootDir,
|
cwd: rootDir,
|
||||||
overrides: {
|
overrides: {
|
||||||
dev: true,
|
dev: true,
|
||||||
logLevel: args['log-level']
|
logLevel: args['log-level'],
|
||||||
|
...(options.overrides || {})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -96,7 +97,8 @@ export default defineNuxtCommand({
|
|||||||
dev: true,
|
dev: true,
|
||||||
ready: false,
|
ready: false,
|
||||||
overrides: {
|
overrides: {
|
||||||
logLevel: args['log-level']
|
logLevel: args['log-level'],
|
||||||
|
...(options.overrides || {})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ export interface NuxtCommandMeta {
|
|||||||
export type CLIInvokeResult = void | 'error' | 'wait'
|
export type CLIInvokeResult = void | 'error' | 'wait'
|
||||||
|
|
||||||
export interface NuxtCommand {
|
export interface NuxtCommand {
|
||||||
invoke(args: Argv): Promise<CLIInvokeResult> | CLIInvokeResult
|
invoke(args: Argv, options?: Record<string, any>): Promise<CLIInvokeResult> | CLIInvokeResult
|
||||||
meta: NuxtCommandMeta
|
meta: NuxtCommandMeta
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,12 +2,12 @@ import mri from 'mri'
|
|||||||
import type { Command, NuxtCommand } from './commands'
|
import type { Command, NuxtCommand } from './commands'
|
||||||
import { commands } from './commands'
|
import { commands } from './commands'
|
||||||
|
|
||||||
export async function runCommand (command: string, argv = process.argv.slice(2)) {
|
export async function runCommand (command: string, argv = process.argv.slice(2), options: Record<string, any> = {}) {
|
||||||
const args = mri(argv)
|
const args = mri(argv)
|
||||||
args.clear = false // used by dev
|
args.clear = false // used by dev
|
||||||
const cmd = await commands[command as Command]() as NuxtCommand
|
const cmd = await commands[command as Command]() as NuxtCommand
|
||||||
if (!cmd) {
|
if (!cmd) {
|
||||||
throw new Error(`Invalid command ${command}`)
|
throw new Error(`Invalid command ${command}`)
|
||||||
}
|
}
|
||||||
await cmd.invoke(args)
|
await cmd.invoke(args, options)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user