npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

babel-plugin-import-billd

v0.0.8

Published

billd's mini babel-plugin-import

Readme

简介

参考了babel-plugin-import,实现了我认为核心的三个配置项:libraryNamelibraryDirectorystyle

babel 插件简介

https://github.com/jamiebuilds/babel-handbook/blob/master/translations/zh-Hans/plugin-handbook.md#babel-%E7%9A%84%E5%A4%84%E7%90%86%E6%AD%A5%E9%AA%A4

  • Babel 的三个主要处理步骤分别是: 解析(parse),转换(transform),生成(generate)
  • 转换步骤接收 AST 并对其进行遍历,在此过程中对节点进行添加、更新及移除等操作。 这是 Babel 或是其他编译器中最复杂的过程 同时也是插件将要介入工作的部分

可以得出结论,babel 插件主要是操作 ast,而操作 ast 其实就是操作 visitor

案例

最粗浅的理解就是在编译阶段,将以下代码(或者说是这个文件):

import { Button } from 'ant-design-vue';
console.log(Button);

转换为;

import Button from 'ant-design-vue/es/button';
import 'ant-design-vue/es/button/style.css';
console.log(Button);

或者转换为:

import Button from 'ant-design-vue/lib/button';
import 'ant-design-vue/lib/button/style.css';
console.log(Button);

安装

npm i babel-plugin-import-billd --save-dev

使用

babel.config.js:

  • libraryName
  • libraryDirectory
  • style

这三个属性的具体行为基本和 babel-plugin-import 一致

plugins: [
  // ...
  [
    'import-billd',
    // Options在 babel@7+ 中不能是数组,但是可以添加带名字的插件来支持多个依赖。
    { libraryName: 'ant-design-vue', libraryDirectory: 'lib', style: 'css' },
    'aaa', // 这个名字可以随便起
  ],
  [
    'import-billd',
    { libraryName: 'antd', libraryDirectory: 'lib', style: true },
    'bbb',
  ],
],

测试

由于现代的组件库大多数都实现了原生的 ES modules 的 tree shaking,因此我们需要下载旧版的组件库才能测试出效果,这里我使用了 ant-design-vue 的 1.1.0 版本以及 antd 的 2.13.14 版本进行测试。

当遇到下面的代码时,会仅仅将 Button 和 Switch 进行打包:

import { Button, Switch } from 'ant-design-vue';
console.log(Button, Switch);

参考

源码

https://github.com/galaxy-s10/babel-plugin-import-billd