Closed SnowingFox closed 1 year ago
I don't feel that are the same category of plugins, how do you expect it to work?
I don't feel that are the same category of plugins, how do you expect it to work?
We don't necessarily need to be compatible with unplugin devlope system like transform
, resolveId
..., we just need to provide a entry for babel plugin so that developers can resuse their logic and maintain their code in a same repository instead of creating a new repository to do some repeat thing.
Take your unplugin-auto-import
repository as an example
import insertImport from './insert'
export const unplugin = createUnplugin((options: UserOptions) => {
return {
name: 'auto-import',
transformInclude(id) {
return id.endsWith('.ts')
},
transform(code) {
return insertImport(code)
},
babel: {
visitor: {
Identifier(path, { opts: options, file }) {
let { node: identifier, scope } = path;
let { declarations } = options;
let filename = file.opts.filename
? basename(file.opts.filename)
: "";
declarations.some(handleDeclaration, {
path,
identifier,
filename,
});
},
handleDeclaration(declaration) {
insertImport(declaration);
return true;
}
}
},
}
}
@SnowingFox IMHO this is out-of-scope...
Yeah. As unplugin
we certainly don't want to couple with one single parser, as there are many more to choose, or simply no parsers at all. Close as I'd consider it out-of-scope. Thanks.
Describe the feature
In some case, like React Native devlopment, it should use
babel
instead ofwebpack
,vite
..., so it's necessary to support babel plugin devlopment in unplugin.Do you have any plan for this feature?
Additional information