atlaschiew / react-study

happy reacting
0 stars 0 forks source link

commonjs? esmodule? #8

Open atlaschiew opened 1 year ago

atlaschiew commented 1 year ago

es-module 模块化 以前javascript是没有模块体系的,后来js社区提出了三种模块化方案,主要是CommonJS,AMD,CMD三大规范。比如nodejs的模块系统require、webpack等都是以CommonJS规范来实现的;requirejs是基于AMD规范来实现的,seajs是基于CMD规范实现的。

但这些都不是最好的方式,于是es6提出了官方的es-module模块化方案,成为浏览器和服务器通用的模块解决方案。

es-module主要由两个命令构成:export和import,即导出和导入。

使用es-module时,可以说一个js文件就是一个模块,文件内的变量、函数、类需要export,然后才能在另一个模块中使用import来引用。

atlaschiew commented 6 months ago

https://dev.to/iggredible/what-the-heck-are-cjs-amd-umd-and-esm-ikm