按webpack文档上的说明,按需加载ES6模块时,其默认导出值要通过module.default方式获得,但是非ES6模块的导出值,则直接是导出对象。那如果加载不是自己写的模块,怎么知道它是ES6模块还是普通commonjs模块呢,总不可能打开源文件去看吧。
https://webpack.js.org/guides...
Note that when using import() on ES6 modules you must reference the .default property as it's the actual module object that will be returned when the promise is resolved.
可以参考react-router文档上的做法,如果想要取得模块默认导出值,那么判断返回值是否存在.default属性即可。
https://reacttraining.com/rea...