MJingv / jehol-person-blog

Jehol's Blog 🙋 (hexo+react)
https://mjingv.github.io/JeholBlog/
0 stars 1 forks source link

module的前生今世 #50

Open MJingv opened 5 years ago

MJingv commented 5 years ago

https://www.ruanyifeng.com/blog/2020/08/how-nodejs-use-es6-module.html

AMD - 异步(浏览器)

    define(id?, dependencies?, factory);

CJS - 同步(服务器)

module.exports = xx;

const a = require('./a');

rules

require

ES6 Module

NPM

dependencies

These packages are required by your application in production.

npm install <package_name> --save

devDependencies

These packages are only needed for development and testing. npm install <package_name> --save-dev

Command Line Flags

Putting --foo bar on the command line sets the foo configuration parameter to "bar".

MJingv commented 5 years ago

Module 的加载实现

浏览器加载

<script type="module" src="./foo.js" defer></script>

ES6 模块与 CommonJS 模块的差异

Node 加载

内部变量

ES6 模块加载 CommonJS 模块