4.Node项目如何支持ES Module,即:CommonJs中如何支持ES Module
1. 模块化的发展历程(由先到后):
-
CMD/AMD/require.js
-
CommonJS
用require()
加载模块,用module.exports
/exports.x
来输出模块
-
ES Module
用import
加载模块,用export default
/export
来输出
2. CommonJS中使用ES Module防范
方案一:利用webpack打包编译成commonJs
假设当前目录结构为
- project-test/
- bin/
- index