当前位置: 移动技术网 > IT编程>开发语言>JavaScript > AMD/CMD/commonjs/ESM

AMD/CMD/commonjs/ESM

2019年04月06日  | 移动技术网IT编程  | 我要评论

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()




如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网