babel-plugin-demand

1.1.0 • Public • Published

babel-plugin-demand

用于公共 js 库按需加载的babel插件

NPM version Build Status

Install

npm i babel-plugin-demand -D

Usage

.babelrc 或者 babel-loader 文件中配置

{
  "plugins": [
    [
      "demand", {
        packageName: 'xx-sdk',
        redirect: 'lib'
        // ...options
      }
    ]
  ]
}

Example

import { foo } from 'xx-sdk'
foo()

上述代码会被转为

import _foo from 'xx-sdk/lib/foo'
_foo()

options

参数名称 类型 含义 是否必填 默认值
packageName String js 包的名字
redirect String 函数所在的目录 'lib'
moreRedirect Array redirect目录不存在时,自动检索该数组中的路径 []
camel2Dash Boolean 驼峰文件名是否需要转为'-'连接 false

more

  • 编译过程中 ast 的 types 可以参考doc文件下的 ast-types

Package Sidebar

Install

npm i babel-plugin-demand

Weekly Downloads

0

Version

1.1.0

License

ISC

Unpacked Size

8.69 kB

Total Files

4

Last publish

Collaborators

  • httpsxiao