功能需求:同事在做antd-table 导出功能,使用js-export-excel 插件。但是无法导出样式,集成xlsx-style 可以实现但是出现了如下bug
ERROR Failed to compile with 1 errors 下午4:51:30
This relative module was not found:
* ./cptable in ./node_modules/xlsx-style/dist/cpexcel.js
大体意识是找不到cptable 模块在cpexcel.js 里。
按照报错分析,顺腾摸瓜,摸到这里来了。
就是require 找不到路径模块,看看是否全局已加载。
看到github issue 分析,可以利用webpack externals解决这个问题。
在umi 配置文件里写上下面的话就行:
externals: {
'./cptable': 'var cptable'
},