React + umi引用xlsx或者mp4文件提示需要安装lo
2022-11-22 本文已影响0人
燕自浩
前言:当我们在项目中直接使用文件(xlsx|pdf|word|mp4)会提示需要加载loader该如何处理,老项目可能没有内置file的处理插件需要我们手动做如下处理,如果是一些新启的项目一般不会遇到这种问题

解决方案:
npm install file-loader
- 找到
umi
配置文件一般路径为config/config.ts
- 添加代码
chainWebpack(config) {
config.module
.rule('file-loader')
.test(/\.(pdf|docx|doc|xlsx|mp4)$/)
.use('file-loader?name=[path][name].[ext]')
.loader('file-loader')
.end();
},
重启项目即可