Define Auto-import Presets
mainUnimport supports two main types of presets to automate import registration:
InlinePreset
Allows you to define a group of imports manually. Each preset can contain nested imports.
PackagePreset
Automatically extracts exports from a specific npm package.
package: The name of the package.url: The path of the importer (defaults toprocess.cwd()).ignore: A RegExp, string, or function to exclude specific names from being auto-imported.cache: Whether to use a local cache (defaults totrue).
// Example of an InlinePreset structure
const myPreset: InlinePreset = {
from: 'my-library',
imports: [
{ name: 'funcA' },
{ name: 'funcB', as: 'otherName' }
]
};
// Example of a PackagePreset
const pkgPreset: PackagePreset = {
package: 'lodash-es',
ignore: ['cloneDeep']
};