CommonJS
ブラウザ外のJavaScriptの仕様を定めることを目標としたproject
特にmodule system周りの仕様
実装ではなく仕様
MozillaのKevin Dangoorが、2009/1にServerJSとして始めた
2009/8にCommonJSに改名
Common.jsのmodule systemの仕様に則った実装の例
Node.js
Browserify
CommonJSの仕様に則っているとは言わない
Browserifyはrequire('hoge')のような書き方でmoduleを扱うが、これは表面だけ
build時にBrowserifyが、Browserが解釈できる形式に変換する
例
code:math.js
// 定義とexport
module.exports.add = function() {};
code:app.js
// 読み込み
var add = require('math').add;
add(); // 実行
参考
CommonJS - Wikipedia
JavaScriptのモジュール管理(CommonJSとかAMDとかBrowserifyとかwebpack) | tsuchikazu blog
#WIP
最近は下火 #??
module.exports
http://www.commonjs.org/specs/modules/1.0/
#??
ビルドプロセスで依存関係を解決、とは?
https://tsuchikazu.net/javascript-module/
2021/5/14現在、今も健在?
https://simonplend.com/node-js-now-supports-named-imports-from-commonjs-modules-but-what-does-that-mean/
https://redfin.engineering/node-modules-at-war-why-commonjs-and-es-modules-cant-get-along-9617135eeca1
https://qiita.com/qnighy/items/067dd47c48b96e772a4e