diff --git a/packages/nuxt/src/core/nitro.ts b/packages/nuxt/src/core/nitro.ts index 543cb898ed..dcb308de34 100644 --- a/packages/nuxt/src/core/nitro.ts +++ b/packages/nuxt/src/core/nitro.ts @@ -16,6 +16,18 @@ import { ImportProtectionPlugin } from './plugins/import-protection' export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { // Resolve config const _nitroConfig = ((nuxt.options as any).nitro || {}) as NitroConfig + + const excludePaths = nuxt.options._layers + .flatMap(l => [ + l.cwd.match(/(?<=\/)node_modules\/(.+)$/)?.[1], + l.cwd.match(/\.pnpm\/.+\/node_modules\/(.+)$/)?.[1] + ]) + .filter((dir): dir is string => Boolean(dir)) + .map(dir => escapeRE(dir)) + const excludePattern = excludePaths.length + ? [new RegExp(`node_modules\\/(?!${excludePaths.join('|')})`)] + : [/node_modules/] + const nitroConfig: NitroConfig = defu(_nitroConfig, { debug: nuxt.options.debug, rootDir: nuxt.options.rootDir, @@ -35,14 +47,11 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { name: 'publicAssetsURL', from: resolve(distDir, 'core/runtime/nitro/paths') } - ] + ], + exclude: [...excludePattern, /[\\/]\.git[\\/]/] }, esbuild: { - options: { - exclude: [ - new RegExp(`node_modules\\/(?!${nuxt.options._layers.map(l => l.cwd.match(/(?<=\/)node_modules\/(.+)$/)?.[1]).filter(Boolean).map(dir => escapeRE(dir!)).join('|')})`) - ] - } + options: { exclude: excludePattern } }, analyze: nuxt.options.build.analyze && { template: 'treemap',