webpack 配置antd

webpack配置antd

webpack配置文件 wepack.config.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//省略
module:{
rules: [{
test: /\.js[x]?$/,
use:['babel-loader?cacheDirectory=true'],
include:path.join(__dirname,'./src/')
},{
test: /\.css$/,
use: [
{
loader: "style-loader"
}, {
loader: "css-loader"
},
]
},]
},
//省略

bable配置文件 .bablerc:

1
2
3
4
5
6
7
8
9
10
11
12
13
{
"presets": [
"es2015",
"react",
"stage-0"
],
"plugins": [[
"import", {
"libraryName": "antd",
"style": "css"
}]
]
}

babel-plugin-import 插件用法:https://github.com/ant-design/babel-plugin-import#usage