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

28 lines
703 B
Markdown
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: commonJS和AMD/CMD
date: 2017-08-23 16:49:51
tags: [commonjs, 未完成]
categories: 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
未完待续...