本文适合阅读对象:
使用create-react-app生成项目,并且在运行npm run eject之后,还想集成antd(antd-mobile)
1.安装babel-plugin-import:
npm install babel-plugin-import --save-dev
2.修改config/webpack.config.dev.js
和config/webpack.config.prod.js
:
找到这2个文件,并且在这2个文件中,找到以下部分:
// Process JS with Babel.
{
test: /\.(js|jsx|mjs)$/,
include: paths.appSrc,
loader: require.resolve('babel-loader'),
options: {
// 加上下面的plugins
plugins: [
['import', { libraryName: 'antd-mobile', style: 'css' }]// antd或antd-mobile
],
// This is a feature of `babel-loader` for webpack (not Babel itself).
// It enables caching results in ./node_modules/.cache/babel-loader/
// directory for faster rebuilds.
cacheDirectory: true,
},
},