New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CommonJS模块化规范和ES6模块化规范 #8

Open
zhaoqize opened this Issue Dec 12, 2017 · 0 comments

Comments

Projects
None yet
1 participant
@zhaoqize
Owner

zhaoqize commented Dec 12, 2017

CommonJS模块化规范

关键字:module exports require global

模块的设计思想,是尽量的静态化,使得 编译时 就能确定模块的依赖关系,以及输入和输出的变量

ES6模块化规范

关键字:export import

CommonJS 和 AMD 模块,都只能在 运行时 确定这些东西

目前阶段,通过 Babel 转码,CommonJS 模块的require命令ES6 模块的import命令,可以写在同一个模块里面,但是最好不要这样做。
因为import静态解析 阶段执行,所以它是一个模块之中最早执行的。
下面的代码可能不会得到预期结果。

require('core-js/modules/es6.symbol'); // 运行时执行
require('core-js/modules/es6.promise'); // 运行时执行

import React from 'React';  // 静态解析(编译)时执行

两者不是一个概念的东西。

@zhaoqize zhaoqize added the Blog label Dec 12, 2017

@zhaoqize zhaoqize added Tip and removed Blog labels Jan 2, 2018

@zhaoqize zhaoqize added JS Tip and removed Tip labels Aug 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment