Skip to content

Instantly share code, notes, and snippets.

@suisho
Last active August 29, 2015 14:28
Show Gist options
  • Save suisho/082047e2af95e2b7461b to your computer and use it in GitHub Desktop.
Save suisho/082047e2af95e2b7461b to your computer and use it in GitHub Desktop.
Browserifyのオプションつけるとどんな出力になるのかを検証する。 ref: http://qiita.com/inuscript/items/1fe19d32011e39ed8e2b
(function e(t, n, r) {
// 省略
})({
1: [function(require, module, exports) {
var $ = require("jquery")
console.log($(".foo"))
}, {
"jquery": undefined
}]
}, {}, [1]);
console.log("entry1だよ!")
var lib = require("../lib/somelib")
lib()
console.log("entry1だよ!")
var lib = require("../lib/somelib")
lib()
browserify -e ./src/entry.js -i ./lib/somelib.js
<script type="text/javascript" src="./build/require.js"></script>
<script type="text/javascript" src="./build/entry.js"></script>
$ browserify -r jquery
$ browserify -r ./lib/somelib.js
$ browserify ./src/entry-jquery.js -u jquery -x ./lib/somelib.js
<script type="text/javascript" src="../build/jquery-bundle.js"></script>
<script type="text/javascript" src="../build/require-bundle.js"></script>
<script type="text/javascript" src="../build/entry-jquery.js"></script>
$ browserify ./lib/standalone.js -s standalone
(function(f) {
// 省略
// window.standalone = module
// になるようなコードが書かれている
})(function() {
// 省略
})({
1: [function(require, module, exports) {
module.exports = function() {
console.log("Standaloneなモジュールだよ”")
}
}, {}]
}, {}, [1])(1)
});
$ browserify -e ./src/entry1.js
$ browserify -e ./src/entry.js -i ./lib/somelib.js
(function e(t, n, r) {
// 省略
})({
1: [function(require, module, exports) {
}, {}],
2: [function(require, module, exports) {
console.log("entry1だよ!")
var lib = require("../lib/somelib")
lib()
}, {
"../lib/somelib": 1
}]
}, {}, [2]);
$ browserify -e ./src/ignore.js -i iconv
(function e(t, n, r) {
// 省略
})({
1: [function(require, module, exports) {
module.exports = function() {
console.log("somelibだよ!")
}
}, {}],
2: [function(require, module, exports) {
console.log("entry1だよ!")
var lib = require("../lib/somelib")
lib()
}, {
"../lib/somelib": 1
}]
}, {}, [2]);
$ browserify -e ./src/entry.js -e ./src/entry3.js
(function e(t, n, r) {
// 省略
})({
1: [function(require, module, exports) {
module.exports = function() {
console.log("somelibだよ!")
}
}, {}],
2: [function(require, module, exports) {
console.log("entry1だよ!")
var lib = require("../lib/somelib")
lib()
}, {
"../lib/somelib": 1
}],
3: [function(require, module, exports) {
console.log("entry3だよ!")
}, {}]
}, {}, [2, 3]);
$ browserify -r ./lib/somelib.js
$ browserify -e ./src/entry1.js -x ./lib/**/*.js
(function e(t, n, r) {
// 省略
})({
1: [function(require, module, exports) {
}, {}],
2: [function(require, module, exports) {
console.log("entry1だよ!")
var lib = require("../lib/somelib")
lib()
}, {
"../lib/somelib": 1
}]
}, {}, [2]);
<script type="text/javascript" src="./build/require.js"></script>
<script type="text/javascript" src="./build/entry.js"></script>
(function e(t, n, r) {
// 省略
})({
1: [function(require, module, exports) {
module.exports = function() {
console.log("somelibだよ!")
}
}, {}],
2: [function(require, module, exports) {
console.log("entry1だよ!")
var lib = require("../lib/somelib")
lib()
}, {
"../lib/somelib": 1
}],
3: [function(require, module, exports) {
console.log("entry3だよ!")
}, {}]
}, {}, [2, 3]);
require = (function e(t, n, r) {
// 省略
})({
"/lib/somelib.js": [function(require, module, exports) {
module.exports = function() {
console.log("somelibだよ!")
}
}, {}]
}, {}, []);
module.exports = function(){
console.log("somelibだよ!")
}
(function(f) {
// 省略
// window.standalone = module
// になるようなコードが書かれている
})(function() {
// 省略
})({
1: [function(require, module, exports) {
module.exports = function() {
console.log("Standaloneなモジュールだよ”")
}
}, {}]
}, {}, [1])(1)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment