babel-plugin-import
2017-05-24 00:06
260 查看
按需加载插件。只需要引入模块即可,无需单独引入样式。
import {Button} from 'antd';
ReactDom.render(
<div>
<Button>
XXXX
</Button>
</div>);
安装:
装载:
{
"plugins":[["import",options]]
}options 可以使 对象
style可以为true或者‘css’
{
"libraryName":"antd",
"style":true,
}
{
"libraryName": "material-ui",
"libraryDirectory": "components", // default: lib
"camel2DashComponentName": false, // default: true
}
options可以使一个数组
[
{
"libraryName": "antd",
"libraryDirectory": "lib", // default: lib
"style": true
},
{
"libraryName": "antd-mobile",
"libraryDirectory": "component",
},
]
样式:
导入js模块:
["import", { "libraryName": "antd" }]导入js和css模块(LESS/Sass源文件):
["import", { "libraryName": "antd", "style": true }]
导入js和css模块(css 内置文件):
注意:如果webpack配置文件添加了vendor库,babel-plugin-import将不会工作。
import {Button} from 'antd';
ReactDom.render(
<div>
<Button>
XXXX
</Button>
</div>);
安装:
$ cnpm install babel-plugin-import --save-dev
装载:
{
"plugins":[["import",options]]
}options 可以使 对象
style可以为true或者‘css’
{
"libraryName":"antd",
"style":true,
}
{
"libraryName": "material-ui",
"libraryDirectory": "components", // default: lib
"camel2DashComponentName": false, // default: true
}
options可以使一个数组
[
{
"libraryName": "antd",
"libraryDirectory": "lib", // default: lib
"style": true
},
{
"libraryName": "antd-mobile",
"libraryDirectory": "component",
},
]
样式:
导入js模块:
["import", { "libraryName": "antd" }]导入js和css模块(LESS/Sass源文件):
["import", { "libraryName": "antd", "style": true }]
导入js和css模块(css 内置文件):
["import", { "libraryName": "antd", "style": "css" }]
注意:如果webpack配置文件添加了vendor库,babel-plugin-import将不会工作。
相关文章推荐
- 组件库按需加载 借助babel-plugin-import实现
- [转] 组件库按需加载 借助babel-plugin-import实现
- babel-plugin-import不生效的问题
- react中使用AntDesign库 --- babel-plugin-import 配置
- babel-plugin-import不生效的问题
- babel-plugin-module-resolver 模块解析插件
- babel & browserify 报错 'import' and 'export' may appear only with 'sourceType: module' (2:0)
- Importrec Plugin, Visual Protect by sEby
- webpack配置开发环境(html-webpack-plugin、css-loader、less-loader、babel-loader)
- ZProtect ImportREC Fix Plugin 1.0 beta
- eclipse install gradle plugin used to import the gradle project
- Cannot find module 'babel-plugin-transform-es2015
- ImportREC plugin----for PrivateExeProtector.1.8
- Babel Relay Plugin #Facebook Relay文档翻译#
- Java开发Web Service客户端技巧:wsimport、jaxws-maven-plugin、整合Spring
- gulp插件之-----转化es6代码到es5 取消严格模式 remove "use strict" directive Installation npm install babel-plugin-t
- maven import 工程 报错 pom plugin
- babel引起的import无法正常转换成es5的问题
- babel-preset-es2015,babel-polyfill 与 babel-plugin-transform-runtime
- [Javascript AST] 0. Introduction: Write a simple BabelJS plugin