//安裝babel-plugin-import
第一步:npm install babel-plugin-import --save
第二步:暴露webpack.config.js運行:npm run eject 注意:如果用git管理代碼,記得一定要提交才能安裝
第三步:在webpack.config.js中的module下的oneOf數組里加入下面代碼:
{
test: /(\.jsx|\.js)$/,
exclude: /node_modules/,
loader: 'babel-loader',
query:
{
plugins: [
[
"import",
{ libraryName: "antd", style: 'css' }
] //antd按需加載
]
},
},
{//CSS處理
test: /\.css$/,
loader: "style-loader!css-loader?modules",
exclude: /node_modules/,
},
{//antd樣式處理
test: /\.css$/,
exclude: /src/,
use: [
{ loader: "style-loader", },
{
loader: "css-loader",
options: {
importLoaders: 1
}
}
]
},
重啟項目即可;