fix(nuxt): exclude non-cwd auto-imports and don't process all files (#5421)

This commit is contained in:
Daniel Roe 2022-06-12 21:12:43 +01:00 committed by GitHub
parent 67d804400b
commit 59da4c6dd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 8 deletions

View File

@ -15,13 +15,8 @@ export const TransformPlugin = createUnplugin(({ ctx, options, sourcemap }: {ctx
const exclude = options.transform?.exclude || [/[\\/]node_modules[\\/]/]
const include = options.transform?.include || []
// Custom includes
if (include.some(pattern => id.match(pattern))) {
return true
}
// Exclude node_modules by default
if (exclude.some(pattern => id.match(pattern))) {
// Custom includes - exclude node_modules by default
if (exclude.some(pattern => id.match(pattern)) && !include.some(pattern => id.match(pattern))) {
return false
}

View File

@ -143,7 +143,7 @@ export async function loadNuxt (opts: LoadNuxtOptions): Promise<Nuxt> {
options._modules.push([autoImportsModule, {
transform: {
include: options._layers
.filter(i => i.cwd)
.filter(i => i.cwd && i.cwd.includes('node_modules'))
.map(i => new RegExp(`(^|\\/)${escapeRE(i.cwd.split('node_modules/').pop())}(\\/|$)(?!node_modules\\/)`))
}
}])