AMD/CMD/commonjs/ESM
js模块化发展史
1 命名空间:
库名.类别名.方法名
2 commonjs :用于后端的node
通过 module.exports 暴露模块接口,通过 require 引入模块,特点:同步执行
,
3 AMD/CMD/UMD :用于前端
AMD(Async Module Definition)使用 define 定义模块,使用 require 加载模块,特点:依赖前置,提前执行
CMD(Common Module Definition)使用define 来定义一个模块,使用require 来加载一个模块,特点:尽可能懒执行
UMD(Universal Module Definition)通用解决方案,三个步奏:判断是否支持 AMD,判断是否支持 CommonJS,如果都没有 使用全局变量
4 ES6 module (EcmaScript Module)export / import,import()