fix(nuxt): don't exclude pnpm layers from nitro esbuild/imports (#9952)

This commit is contained in:
Yasser Lahbibi 2023-02-07 18:18:47 +01:00 committed by GitHub
parent 1b888b4223
commit e451a9965e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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, <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',