-
-
Notifications
You must be signed in to change notification settings - Fork 221
Description
Clear and concise description of the problem
Now, when I have the dirs configuration option, this plugin will automatically scan all exports in the files and generate type declarations for each exported content. However, sometimes I don't want to do this because it can directly pollute the namespace in certain scenarios. Therefore, I hope this plugin can support generating type declarations by dividing modules based on files.
Examples, if I have a file like this
// src/utils/image.ts
export function getImageSize() {
return [10, 10];
}and the vite.config.ts like this
export default defineConfig({
plugins: [
vue(),
AutoImport({
dirs: ['src/utils/**'],
}),
],
});It will generate the dts file like this
/* eslint-disable */
/* prettier-ignore */
// @ts-nocheck
// Generated by unplugin-auto-import
export {}
declare global {
const getImageSize: typeof import('./utils/image')['getImageSize']
}But I want
declare global {
const image: typeof import('./utils/image')
}If it can be done, then I can use it like this
const a = image.getImageSize()I think this way, I don't have to worry about namespace issues anymore.
Suggested solution
I think it's able to add a configuration option for each path in dirs like this
export default defineConfig({
plugins: [
vue(),
AutoImport({
dts: 'src/auto-imports.d.ts',
dirs: [
{
dir: 'src/utils/**',
exportAllByFileName: true,
},
],
}),
],
});If exportAllByFileName is true, it will generate dts file just as I said above.
Alternative
No response
Additional context
I tried to make some adjustments and would appreciate it if you could take a look to see if it meets the standards and requirements. Thank you very much.
Validations
- Follow our Code of Conduct
- Read the Contributing Guide.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.