按需加载第三方模块,如何知道第三方模板是ES6模块还是普通模块?

按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.
clipboard.png

阅读 3.9k
1 个回答

可以参考react-router文档上的做法,如果想要取得模块默认导出值,那么判断返回值是否存在.default属性即可。
https://reacttraining.com/rea...

clipboard.png

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