diff --git a/packages/kit/src/module/define.ts b/packages/kit/src/module/define.ts index b0f30d80fb..5414481338 100644 --- a/packages/kit/src/module/define.ts +++ b/packages/kit/src/module/define.ts @@ -120,7 +120,7 @@ function _defineNuxtModule< // Measure setup time if (setupTime > 5000 && uniqueKey !== '@nuxt/telemetry') { logger.warn(`Slow module \`${uniqueKey || ''}\` took \`${setupTime}ms\` to setup.`) - } else if (nuxt.options.debug) { + } else if (nuxt.options.debug && nuxt.options.debug.log) { logger.info(`Module \`${uniqueKey || ''}\` took \`${setupTime}ms\` to setup.`) } diff --git a/packages/nuxt/src/core/app.ts b/packages/nuxt/src/core/app.ts index 887604d5e3..172738b2fd 100644 --- a/packages/nuxt/src/core/app.ts +++ b/packages/nuxt/src/core/app.ts @@ -87,7 +87,7 @@ export async function generateApp (nuxt: Nuxt, app: NuxtApp, options: { filter?: const perf = performance.now() - start const setupTime = Math.round((perf * 100)) / 100 - if (nuxt.options.debug || setupTime > 500) { + if ((nuxt.options.debug && nuxt.options.debug.log) || setupTime > 500) { logger.info(`Compiled \`${template.filename}\` in ${setupTime}ms`) } diff --git a/packages/nuxt/src/core/builder.ts b/packages/nuxt/src/core/builder.ts index 6b24372b88..8a552b91cb 100644 --- a/packages/nuxt/src/core/builder.ts +++ b/packages/nuxt/src/core/builder.ts @@ -119,7 +119,7 @@ function createWatcher () { function createGranularWatcher () { const nuxt = useNuxt() - if (nuxt.options.debug) { + if (nuxt.options.debug && nuxt.options.debug.log) { // eslint-disable-next-line no-console console.time('[nuxt] builder:chokidar:watch') } @@ -164,7 +164,7 @@ function createGranularWatcher () { }) watcher.on('ready', () => { pending-- - if (nuxt.options.debug && !pending) { + if (nuxt.options.debug && nuxt.options.debug.log && !pending) { // eslint-disable-next-line no-console console.timeEnd('[nuxt] builder:chokidar:watch') } @@ -175,7 +175,7 @@ function createGranularWatcher () { async function createParcelWatcher () { const nuxt = useNuxt() - if (nuxt.options.debug) { + if (nuxt.options.debug && nuxt.options.debug.log) { // eslint-disable-next-line no-console console.time('[nuxt] builder:parcel:watch') } @@ -201,7 +201,7 @@ async function createParcelWatcher () { ], }) watcher.then((subscription) => { - if (nuxt.options.debug) { + if (nuxt.options.debug && nuxt.options.debug.log) { // eslint-disable-next-line no-console console.timeEnd('[nuxt] builder:parcel:watch') } diff --git a/packages/nuxt/src/core/nitro.ts b/packages/nuxt/src/core/nitro.ts index 698cb04b3a..88f416a9b8 100644 --- a/packages/nuxt/src/core/nitro.ts +++ b/packages/nuxt/src/core/nitro.ts @@ -52,7 +52,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { const isNuxtV4 = nuxt.options.future?.compatibilityVersion === 4 const nitroConfig: NitroConfig = defu(nuxt.options.nitro, { - debug: nuxt.options.debug, + debug: nuxt.options.debug && nuxt.options.debug.nitro, rootDir: nuxt.options.rootDir, workspaceDir: nuxt.options.workspaceDir, srcDir: nuxt.options.serverDir, diff --git a/packages/nuxt/src/core/nuxt.ts b/packages/nuxt/src/core/nuxt.ts index 957da98314..fa602a85d7 100644 --- a/packages/nuxt/src/core/nuxt.ts +++ b/packages/nuxt/src/core/nuxt.ts @@ -552,7 +552,7 @@ async function initNuxt (nuxt: Nuxt) { } // Add nuxt app debugger - if (nuxt.options.debug) { + if (nuxt.options.debug && nuxt.options.debug.browser) { addPlugin(resolve(nuxt.options.appDir, 'plugins/debug')) } @@ -811,7 +811,7 @@ export async function loadNuxt (opts: LoadNuxtOptions): Promise { nuxt.hooks.addHooks(opts.overrides.hooks) } - if (nuxt.options.debug) { + if (nuxt.options.debug && nuxt.options.debug.hooks) { createDebugger(nuxt.hooks, { tag: 'nuxt' }) } diff --git a/packages/nuxt/src/pages/module.ts b/packages/nuxt/src/pages/module.ts index cfb390f1d6..1f3c0007f0 100644 --- a/packages/nuxt/src/pages/module.ts +++ b/packages/nuxt/src/pages/module.ts @@ -176,7 +176,7 @@ export default defineNuxtModule({ const options: TypedRouterOptions = { routesFolder: [], dts: resolve(nuxt.options.buildDir, declarationFile), - logs: nuxt.options.debug, + logs: nuxt.options.debug && nuxt.options.debug.log, async beforeWriteFiles (rootPage) { rootPage.children.forEach(child => child.delete()) const pages = nuxt.apps.default?.pages || await resolvePagesRoutes(nuxt) diff --git a/packages/schema/src/config/common.ts b/packages/schema/src/config/common.ts index 59848e08dc..3e12c01eae 100644 --- a/packages/schema/src/config/common.ts +++ b/packages/schema/src/config/common.ts @@ -260,9 +260,30 @@ export default defineUntypedSchema({ * At the moment, it prints out hook names and timings on the server, and * logs hook arguments as well in the browser. * + * You can also set this to an object to enable specific debug options. + * ```js + * { + * log: true, // Log additional information on terminal + * hooks: true, // Log hooks calls and timings + * nitro: true, // Set nitro debug mode + * browser: true, // Log additional information in browser console + * prod: true // Log additional information in production mode (hydration mismatch, etc.) + * } + * ``` + * + * @type {boolean | { log?: boolean, hooks?: boolean, nitro?: boolean, browser?: boolean, prod?: boolean }} */ debug: { - $resolve: val => val ?? isDebug, + $resolve: (val: boolean | { log?: boolean, hooks?: boolean, nitro?: boolean, browser?: boolean, prod?: boolean } | undefined) => { + val ??= isDebug + if (val === false) { + return val + } + if (val === true) { + return { log: true, hooks: true, nitro: true, browser: true, prod: true } + } + return val + }, }, /** diff --git a/packages/schema/src/types/config.ts b/packages/schema/src/types/config.ts index 2d9c1222ef..b3e6c8e7fb 100644 --- a/packages/schema/src/types/config.ts +++ b/packages/schema/src/types/config.ts @@ -76,9 +76,10 @@ export interface NuxtBuilder { } // Normalized Nuxt options available as `nuxt.options.*` -export interface NuxtOptions extends Omit { +export interface NuxtOptions extends Omit { vue: Omit & { config?: Partial> } sourcemap: Required> + debug: Required> builder: '@nuxt/vite-builder' | '@nuxt/webpack-builder' | '@nuxt/rspack-builder' | NuxtBuilder postcss: Omit & { order: Exclude } webpack: ConfigSchema['webpack'] & { diff --git a/packages/webpack/src/presets/vue.ts b/packages/webpack/src/presets/vue.ts index e14632a4fd..05cf6b22ea 100644 --- a/packages/webpack/src/presets/vue.ts +++ b/packages/webpack/src/presets/vue.ts @@ -33,6 +33,6 @@ export function vue (ctx: WebpackConfigContext) { ctx.config.plugins!.push(new webpack.DefinePlugin({ '__VUE_OPTIONS_API__': 'true', '__VUE_PROD_DEVTOOLS__': 'false', - '__VUE_PROD_HYDRATION_MISMATCH_DETAILS__': ctx.nuxt.options.debug, + '__VUE_PROD_HYDRATION_MISMATCH_DETAILS__': ctx.nuxt.options.debug && ctx.nuxt.options.debug.prod, })) } diff --git a/playground/modules/foo.ts b/playground/modules/foo.ts new file mode 100644 index 0000000000..12f9269142 --- /dev/null +++ b/playground/modules/foo.ts @@ -0,0 +1,10 @@ +import { defineNuxtModule, useNuxt } from 'nuxt/kit' + +export default defineNuxtModule({ + setup (options, nuxt) { + nuxt.options.alias['@foo'] = '/path/to/foo' + + const nuxt2 = useNuxt() + nuxt2.options.buildId = 'foo' + }, +})