Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Feature]:Babel plugin support #320

Closed
1 task
SnowingFox opened this issue Jul 12, 2023 · 4 comments
Closed
1 task

[Feature]:Babel plugin support #320

SnowingFox opened this issue Jul 12, 2023 · 4 comments

Comments

@SnowingFox
Copy link

SnowingFox commented Jul 12, 2023

Describe the feature

In some case, like React Native devlopment, it should use babel instead of webpack, vite ..., so it's necessary to support babel plugin devlopment in unplugin.

Do you have any plan for this feature?

Additional information

  • Would you be willing to help implement this feature?
@antfu
Copy link
Member

antfu commented Jul 12, 2023

I don't feel that are the same category of plugins, how do you expect it to work?

@SnowingFox
Copy link
Author

SnowingFox commented Jul 13, 2023

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;
        }
      }
    },
  }
}

@so1ve
Copy link

so1ve commented Aug 20, 2023

@SnowingFox IMHO this is out-of-scope...

@antfu
Copy link
Member

antfu commented Aug 21, 2023

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.

@antfu antfu closed this as not planned Won't fix, can't repro, duplicate, stale Aug 21, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants