mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-24 22:55:13 +00:00
fix(nuxt): respect ignorelist when scanning auto-imports (#22782)
This commit is contained in:
parent
23723305da
commit
b5ce892864
@ -1,4 +1,4 @@
|
||||
import { addTemplate, addVitePlugin, addWebpackPlugin, defineNuxtModule, resolveAlias, tryResolveModule, updateTemplates, useNuxt } from '@nuxt/kit'
|
||||
import { addTemplate, addVitePlugin, addWebpackPlugin, defineNuxtModule, isIgnored, resolveAlias, tryResolveModule, updateTemplates, useNuxt } from '@nuxt/kit'
|
||||
import { isAbsolute, join, normalize, relative, resolve } from 'pathe'
|
||||
import type { Import, Unimport } from 'unimport'
|
||||
import { createUnimport, scanDirExports } from 'unimport'
|
||||
@ -92,7 +92,9 @@ export default defineNuxtModule<Partial<ImportsOptions>>({
|
||||
// Clear old imports
|
||||
imports.length = 0
|
||||
// Scan `composables/`
|
||||
const composableImports = await scanDirExports(composablesDirs)
|
||||
const composableImports = await scanDirExports(composablesDirs, {
|
||||
fileFilter: file => !isIgnored(file)
|
||||
})
|
||||
for (const i of composableImports) {
|
||||
i.priority = i.priority || priorities.find(([dir]) => i.from.startsWith(dir))?.[1]
|
||||
}
|
||||
|
@ -889,6 +889,13 @@ describe('composable tree shaking', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('ignore list', () => {
|
||||
it('should ignore composable files in .nuxtignore', async () => {
|
||||
const html = await $fetch('/ignore/composables')
|
||||
expect(html).toContain('was import ignored: true')
|
||||
})
|
||||
})
|
||||
|
||||
describe('server tree shaking', () => {
|
||||
it('should work', async () => {
|
||||
const html = await $fetch('/client')
|
||||
|
1
test/fixtures/basic/.nuxtignore
vendored
Normal file
1
test/fixtures/basic/.nuxtignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
composables/ignored.*
|
3
test/fixtures/basic/composables/ignored.ts
vendored
Normal file
3
test/fixtures/basic/composables/ignored.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
export function useIgnoredImport () {
|
||||
|
||||
}
|
9
test/fixtures/basic/pages/ignore/composables.vue
vendored
Normal file
9
test/fixtures/basic/pages/ignore/composables.vue
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
const wasImportIgnored = typeof useIgnoredImport === 'undefined'
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
was import ignored: {{ wasImportIgnored }}
|
||||
</div>
|
||||
</template>
|
Loading…
Reference in New Issue
Block a user