mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 00:52:01 +00:00
feat(nuxi,schema): add support for setting nuxt logLevel
(#19369)
This commit is contained in:
parent
fe149618da
commit
3f1e02351d
@ -11,7 +11,7 @@ import { defineNuxtCommand } from './index'
|
|||||||
export default defineNuxtCommand({
|
export default defineNuxtCommand({
|
||||||
meta: {
|
meta: {
|
||||||
name: 'analyze',
|
name: 'analyze',
|
||||||
usage: 'npx nuxi analyze [rootDir]',
|
usage: 'npx nuxi analyze [--log-level] [rootDir]',
|
||||||
description: 'Build nuxt and analyze production bundle (experimental)'
|
description: 'Build nuxt and analyze production bundle (experimental)'
|
||||||
},
|
},
|
||||||
async invoke (args) {
|
async invoke (args) {
|
||||||
@ -24,10 +24,9 @@ export default defineNuxtCommand({
|
|||||||
|
|
||||||
const nuxt = await loadNuxt({
|
const nuxt = await loadNuxt({
|
||||||
rootDir,
|
rootDir,
|
||||||
config: {
|
overrides: {
|
||||||
build: {
|
build: { analyze: true },
|
||||||
analyze: true
|
logLevel: args['log-level']
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import { defineNuxtCommand } from './index'
|
|||||||
export default defineNuxtCommand({
|
export default defineNuxtCommand({
|
||||||
meta: {
|
meta: {
|
||||||
name: 'build',
|
name: 'build',
|
||||||
usage: 'npx nuxi build [--prerender] [--dotenv] [rootDir]',
|
usage: 'npx nuxi build [--prerender] [--dotenv] [--log-level] [rootDir]',
|
||||||
description: 'Build nuxt for production deployment'
|
description: 'Build nuxt for production deployment'
|
||||||
},
|
},
|
||||||
async invoke (args) {
|
async invoke (args) {
|
||||||
@ -33,6 +33,7 @@ export default defineNuxtCommand({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
overrides: {
|
overrides: {
|
||||||
|
logLevel: args['log-level'],
|
||||||
_generate: args.prerender
|
_generate: args.prerender
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -19,7 +19,7 @@ import { defineNuxtCommand } from './index'
|
|||||||
export default defineNuxtCommand({
|
export default defineNuxtCommand({
|
||||||
meta: {
|
meta: {
|
||||||
name: 'dev',
|
name: 'dev',
|
||||||
usage: 'npx nuxi dev [rootDir] [--dotenv] [--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) {
|
||||||
@ -48,7 +48,10 @@ export default defineNuxtCommand({
|
|||||||
|
|
||||||
const config = await loadNuxtConfig({
|
const config = await loadNuxtConfig({
|
||||||
cwd: rootDir,
|
cwd: rootDir,
|
||||||
overrides: { dev: true }
|
overrides: {
|
||||||
|
dev: true,
|
||||||
|
logLevel: args['log-level']
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const listener = await listen(serverHandler, {
|
const listener = await listen(serverHandler, {
|
||||||
@ -88,7 +91,14 @@ export default defineNuxtCommand({
|
|||||||
await distWatcher.close()
|
await distWatcher.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
currentNuxt = await loadNuxt({ rootDir, dev: true, ready: false })
|
currentNuxt = await loadNuxt({
|
||||||
|
rootDir,
|
||||||
|
dev: true,
|
||||||
|
ready: false,
|
||||||
|
overrides: {
|
||||||
|
logLevel: args['log-level']
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
currentNuxt.hooks.hookOnce('restart', async (options) => {
|
currentNuxt.hooks.hookOnce('restart', async (options) => {
|
||||||
if (options?.hard && process.send) {
|
if (options?.hard && process.send) {
|
||||||
|
@ -9,7 +9,7 @@ import { defineNuxtCommand } from './index'
|
|||||||
export default defineNuxtCommand({
|
export default defineNuxtCommand({
|
||||||
meta: {
|
meta: {
|
||||||
name: 'prepare',
|
name: 'prepare',
|
||||||
usage: 'npx nuxi prepare',
|
usage: 'npx nuxi prepare [--log-level] [rootDir]',
|
||||||
description: 'Prepare nuxt for development/build'
|
description: 'Prepare nuxt for development/build'
|
||||||
},
|
},
|
||||||
async invoke (args) {
|
async invoke (args) {
|
||||||
@ -17,7 +17,13 @@ export default defineNuxtCommand({
|
|||||||
const rootDir = resolve(args._[0] || '.')
|
const rootDir = resolve(args._[0] || '.')
|
||||||
|
|
||||||
const { loadNuxt } = await loadKit(rootDir)
|
const { loadNuxt } = await loadKit(rootDir)
|
||||||
const nuxt = await loadNuxt({ rootDir, config: { _prepare: true } })
|
const nuxt = await loadNuxt({
|
||||||
|
rootDir,
|
||||||
|
overrides: {
|
||||||
|
_prepare: true,
|
||||||
|
logLevel: args['log-level']
|
||||||
|
}
|
||||||
|
})
|
||||||
await clearDir(nuxt.options.buildDir)
|
await clearDir(nuxt.options.buildDir)
|
||||||
|
|
||||||
await buildNuxt(nuxt)
|
await buildNuxt(nuxt)
|
||||||
|
@ -9,7 +9,7 @@ import { defineNuxtCommand } from './index'
|
|||||||
export default defineNuxtCommand({
|
export default defineNuxtCommand({
|
||||||
meta: {
|
meta: {
|
||||||
name: 'typecheck',
|
name: 'typecheck',
|
||||||
usage: 'npx nuxi typecheck [rootDir]',
|
usage: 'npx nuxi typecheck [--log-level] [rootDir]',
|
||||||
description: 'Runs `vue-tsc` to check types throughout your app.'
|
description: 'Runs `vue-tsc` to check types throughout your app.'
|
||||||
},
|
},
|
||||||
async invoke (args) {
|
async invoke (args) {
|
||||||
@ -17,7 +17,13 @@ export default defineNuxtCommand({
|
|||||||
const rootDir = resolve(args._[0] || '.')
|
const rootDir = resolve(args._[0] || '.')
|
||||||
|
|
||||||
const { loadNuxt, buildNuxt } = await loadKit(rootDir)
|
const { loadNuxt, buildNuxt } = await loadKit(rootDir)
|
||||||
const nuxt = await loadNuxt({ rootDir, config: { _prepare: true } })
|
const nuxt = await loadNuxt({
|
||||||
|
rootDir,
|
||||||
|
overrides: {
|
||||||
|
_prepare: true,
|
||||||
|
logLevel: args['log-level']
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Generate types and build nuxt instance
|
// Generate types and build nuxt instance
|
||||||
await writeTypes(nuxt)
|
await writeTypes(nuxt)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { defineUntypedSchema } from 'untyped'
|
import { defineUntypedSchema } from 'untyped'
|
||||||
import { defu } from 'defu'
|
import { defu } from 'defu'
|
||||||
import { join } from 'pathe'
|
import { join } from 'pathe'
|
||||||
|
import { isTest } from 'std-env'
|
||||||
|
|
||||||
export default defineUntypedSchema({
|
export default defineUntypedSchema({
|
||||||
/**
|
/**
|
||||||
@ -38,6 +39,23 @@ export default defineUntypedSchema({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log level when building logs.
|
||||||
|
*
|
||||||
|
* Defaults to 'silent' when running in CI or when a TTY is not available.
|
||||||
|
* This option is then used as 'silent' in Vite and 'none' in Webpack
|
||||||
|
*
|
||||||
|
* @type {'silent' | 'info' | 'verbose'}
|
||||||
|
*/
|
||||||
|
logLevel: {
|
||||||
|
$resolve: (val) => {
|
||||||
|
if (val && !['silent', 'info', 'verbose'].includes(val)) {
|
||||||
|
console.warn(`Invalid \`logLevel\` option: \`${val}\`. Must be one of: \`silent\`, \`info\`, \`verbose\`.`)
|
||||||
|
}
|
||||||
|
return val ?? (isTest ? 'silent' : 'info')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shared build configuration.
|
* Shared build configuration.
|
||||||
*/
|
*/
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import * as vite from 'vite'
|
import * as vite from 'vite'
|
||||||
import { join, resolve } from 'pathe'
|
import { join, resolve } from 'pathe'
|
||||||
import type { Nuxt } from '@nuxt/schema'
|
import type { Nuxt, NuxtOptions } from '@nuxt/schema'
|
||||||
import type { InlineConfig, SSROptions } from 'vite'
|
import type { InlineConfig, SSROptions, UserConfig } from 'vite'
|
||||||
import { logger, isIgnored, resolvePath, addVitePlugin } from '@nuxt/kit'
|
import { logger, isIgnored, resolvePath, addVitePlugin } from '@nuxt/kit'
|
||||||
import type { Options as VueOptions } from '@vitejs/plugin-vue'
|
import type { Options as VueOptions } from '@vitejs/plugin-vue'
|
||||||
import type { Options as VueJsxOptions } from '@vitejs/plugin-vue-jsx'
|
import type { Options as VueJsxOptions } from '@vitejs/plugin-vue-jsx'
|
||||||
@ -41,6 +41,7 @@ export async function bundle (nuxt: Nuxt) {
|
|||||||
entry,
|
entry,
|
||||||
config: vite.mergeConfig(
|
config: vite.mergeConfig(
|
||||||
{
|
{
|
||||||
|
logLevel: logLevelMap[nuxt.options.logLevel] ?? logLevelMap.info,
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
...nuxt.options.alias,
|
...nuxt.options.alias,
|
||||||
@ -147,3 +148,9 @@ export async function bundle (nuxt: Nuxt) {
|
|||||||
await buildClient(ctx)
|
await buildClient(ctx)
|
||||||
await buildServer(ctx)
|
await buildServer(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const logLevelMap: Record<NuxtOptions['logLevel'], UserConfig['logLevel']> = {
|
||||||
|
silent: 'silent',
|
||||||
|
info: 'info',
|
||||||
|
verbose: 'info'
|
||||||
|
}
|
||||||
|
@ -2,12 +2,14 @@ import { resolve, normalize } from 'pathe'
|
|||||||
// @ts-expect-error missing types
|
// @ts-expect-error missing types
|
||||||
import TimeFixPlugin from 'time-fix-plugin'
|
import TimeFixPlugin from 'time-fix-plugin'
|
||||||
import WebpackBar from 'webpackbar'
|
import WebpackBar from 'webpackbar'
|
||||||
|
import type { Configuration } from 'webpack'
|
||||||
import webpack from 'webpack'
|
import webpack from 'webpack'
|
||||||
import { logger } from '@nuxt/kit'
|
import { logger } from '@nuxt/kit'
|
||||||
// @ts-expect-error missing types
|
// @ts-expect-error missing types
|
||||||
import FriendlyErrorsWebpackPlugin from '@nuxt/friendly-errors-webpack-plugin'
|
import FriendlyErrorsWebpackPlugin from '@nuxt/friendly-errors-webpack-plugin'
|
||||||
import escapeRegExp from 'escape-string-regexp'
|
import escapeRegExp from 'escape-string-regexp'
|
||||||
import { joinURL } from 'ufo'
|
import { joinURL } from 'ufo'
|
||||||
|
import type { NuxtOptions } from '@nuxt/schema'
|
||||||
import type { WarningFilter } from '../plugins/warning-ignore'
|
import type { WarningFilter } from '../plugins/warning-ignore'
|
||||||
import WarningIgnorePlugin from '../plugins/warning-ignore'
|
import WarningIgnorePlugin from '../plugins/warning-ignore'
|
||||||
import type { WebpackConfigContext } from '../utils/config'
|
import type { WebpackConfigContext } from '../utils/config'
|
||||||
@ -40,7 +42,7 @@ function baseConfig (ctx: WebpackConfigContext) {
|
|||||||
mode: ctx.isDev ? 'development' : 'production',
|
mode: ctx.isDev ? 'development' : 'production',
|
||||||
cache: getCache(ctx),
|
cache: getCache(ctx),
|
||||||
output: getOutput(ctx),
|
output: getOutput(ctx),
|
||||||
stats: 'none',
|
stats: statsMap[ctx.nuxt.options.logLevel] ?? statsMap.info,
|
||||||
...ctx.config
|
...ctx.config
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -244,3 +246,9 @@ function getEnv (ctx: WebpackConfigContext) {
|
|||||||
|
|
||||||
return _env
|
return _env
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const statsMap: Record<NuxtOptions['logLevel'], Configuration['stats']> = {
|
||||||
|
silent: 'none',
|
||||||
|
info: 'normal',
|
||||||
|
verbose: 'verbose'
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user