antd和antd-mobile样式的按需加载配置
在开发react+antd(antd-mobile)+webpack 的项目中想要配置antd(antd-mobile)的样式按需加载,在网上找到两种解决方式都是利用babel-plugin-import插件 配置在不同的地方:
1、.babelrc
{
"plugins": [
["import", { "libraryName": "antd-mobile", "style": "css" }] // `style: true` 会加载 less 文件
]
}
结果就报错了
2、babel-loader option
配置了之后根本比起作用
不知道我这两种配置都分别错在了哪里,附上我的package.json的配置文件,麻烦大神们看下是否有冲突
{
"name": "my-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "cross-env NODE_ENV=development node build/webpack.dev.js --host 0.0.0.0",
"start": "cross-env NODE_ENV=development node build/webpack.dev.js",
"build": "cross-env NODE_ENV=produce node build/webpack.produce.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"autoprefixer": "^7.1.1",
"babel-core": "^6.25.0",
"babel-eslint": "^7.1.1",
"babel-loader": "^7.1.1",
"babel-plugin-import": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"cross-env": "^5.0.1",
"css-loader": "^0.28.4",
"eslint": "^3.19.0",
"eslint-config-standard": "^6.2.1",
"eslint-friendly-formatter": "^2.0.7",
"eslint-loader": "^1.7.1",
"eslint-plugin-html": "^2.0.0",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-react": "^7.1.0",
"eslint-plugin-standard": "^2.0.1",
"extract-text-webpack-plugin": "^2.1.0",
"file-loader": "^0.11.2",
"html-webpack-plugin": "^2.29.0",
"image-webpack-loader": "^3.3.1",
"jsx-loader": "^0.13.2",
"less": "^2.7.2",
"less-loader": "^4.0.5",
"postcss-loader": "^0.9.1",
"precss": "^1.4.0",
"react-hot-loader": "^1.3.1",
"style-loader": "^0.18.2",
"uglifyjs-webpack-plugin": "^0.4.6",
"url-loader": "^0.5.9",
"webpack": "^2.2.1",
"webpack-dev-server": "^2.5.1"
},
"dependencies": {
"antd": "^2.12.1",
"antd-mobile": "^2.1.8",
"axios": "^0.16.2",
"echarts": "^3.6.2",
"jquery": "^3.2.1",
"moment": "^2.20.1",
"rc-form": "^2.2.0",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-redux": "^4.4.0",
"react-router": "^3.0.0",
"redux": "^3.7.2",
"redux-thunk": "^2.2.0"
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
antd, antd-mobile 一起用,这样试下:
我的最终解决方法
在package.json里添加的antd样式
在main.js路由配置里引入了antd-mibile的样式