ant Design初体验 之报错 ERROR in ./node_modules/antd/lib/button/style/index.less Module parse failed: /Us

使用ant design 按需加载时,比如按需加载Button

import Button from 'antd/lib/button';
import 'antd/lib/button/style/css';

后台运行webpack文件会报错
ERROR in ./node_modules/antd/lib/button/style/index.less
Module parse failed: /Users/mac/source/9-06/node_modules/antd/lib/button/style/index.less Unexpected character '@' (1:0)
You may need an appropriate loader to handle this file type.
| @import "../../style/themes/default";
| @import "../../style/mixins/index";
| @import "./mixin";
 @ ./node_modules/antd/lib/button/style/index.js 5:0-23
 @ ./src/js/components/indexbody.js
 @ ./src/js/index.js

ERROR in ./node_modules/antd/lib/style/index.less
Module parse failed: /Users/mac/source/9-06/node_modules/antd/lib/style/index.less Unexpected character '@' (1:0)
You may need an appropriate loader to handle this file type.
| @import "./themes/default";
| @import "./core/index";
| 
 @ ./node_modules/antd/lib/button/style/index.js 3:0-33
 @ ./src/js/components/indexbody.js
 @ ./src/js/index.js
百度了一下,最相关的解答是处理less,不仅要安装less-loader还要安装less。

https://github.com/webpack-contrib/less-loader/issues/89

这里写到 npm@3 does not resolve peerDependencies。


所以我重新安装了less和less-loader试试

npm install less less-loader --save
再次webpack 成功。


你可能感兴趣的:(学习笔记)