antd使用babel-plugin-import出错

使用babel-plugin-import进行antd资源按需加载时,如下配置:图片描述

这样配置可以使用,但仅仅引入了js文件,css仍旧无法引入。但是如下配置,图片描述

控制台出现错误:图片描述

那位伙伴知道怎么处理吗?

阅读 7.6k
1 个回答

您好,请看控制台错误提示信息You may need an appropriate loader to handle this file type.出现该问题的原因应该是您webpack的loaders配置加入了exclude(将antd资源排除其外)和include(未能将antd资源包含其内)。大体说下错误示例和正确示例(仅供参考)。
错误示例:
` {

exclude: /^node_modules$/, // 将antd资源排除其外
test: /\.less$/, 
loader: ExtractTextPlugin.extract('style', ['css', 'autoprefixer', 'less']),
include: [APP_PATH] // 未能将antd资源包含其内

}`
正确示例:
`{

test: /\.less$/, // 去掉exclude: /^node_modules$/和include: [APP_PATH]是为了babel-plugin-import按需加载antd资源
loader: ExtractTextPlugin.extract('style', ['css', 'autoprefixer', 'less'])

}`

关键点有两处:exclude 和 include,希望对您有帮助。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题