babel模块化导入插件,实现了按需加载的功能来满足常规业务需求。
npm install babel-plugin-auto-import-jweboy --save-dev
yarn add babel-plugin-auto-import-jweboy --dev
在.babelrc增加配置
{
"plugins": ["auto-import-jweboy", options]
}
options是一个对象类型
模块化导入js
{
"libraryName": "test-ui"
}
模块化按需导入js、css
{
"libraryName": "test-ui",
"style": true
}
{ "libraryName": "test-ui" }
Before compiling:
import { Button } from 'test-ui'
After compilation:
var _Button = _interopRequireDefault(require("test-ui/lib/Button"));
{ "libraryName": "test-ui", "style": true }
Before compiling:
import { Button } from 'test-ui'
After compilation:
require("test-ui/lib/Button/style");
var _Button = _interopRequireDefault(require("test-ui/lib/Button"));