nicenote/source/_posts/commonJS和AMD-CMD.md
2018-05-26 17:58:20 +08:00

703 B
Executable File
Raw Blame History

title date tags categories
commonJS和AMD/CMD 2017-08-23 16:49:51
commonjs
未完成
JS

一. CommonJS

node.js的模块系统就是参照CommonJS规范实现的。在CommonJS中有一个全局性方法require()用于加载模块。假定有一个数学模块math.js就可以像下面这样加载。NodeJS是CommonJS规范的实现webpack 也是以CommonJS的形式来书写。

var math = require('math')

1. 原理

浏览器兼不兼容commonJS在于是否缺少这几个环境变量

  • module
  • export
  • require
  • global

2. browsertify

将 npm包 编译成可以被 html 页面引入的 js模块

一个类似的库browser-unpack

未完待续...