我正在为节点中的JavaScript寻找一个简单的JavaScript require / concat工具。
例如,假设我有4个JS文件:
each.js
function each(arr, fn, scope) {
for (var i = 0, l = arr.length; i < l; i++) {
fn.call(scope, arr[i], i, arr);
}
}
on.js
// addEventListener wrapper:
function on(target, type, callback) {
target.addEventListener(type, callback, false);
}
onEach.js
// require: each.js
// require: on.js
// Add an event listener to multiple elements:
function onEach(targets, type, callback) {
each(targets, function(target) {
on(target, type, callback);
});
}
all.js
// require: each.js
// require: on.js
// require: onEach.js
最后两个文件有依赖项。我想知道是否有一个命令行节点工具将使用连接来构建这些工具,以使用适当的依赖项替换每个需要注释/语句/函数的调用。 each.js和on.js的构建版本将保持不变,onEach.js和all.js的内置版本将如下所示:
function each(arr, fn, scope) {
for (var i = 0, l = arr.length; i < l; i++) {
fn.call(scope, arr[i], i, arr);
}
}
// addEventListener wrapper:
function on(target, type, callback) {
target.addEventListener(type, callback, false);
}
// Add an event listener to multiple elements:
function onEach(targets, type, callback) {
each(targets, function(target) {
on(target, type, callback);
});
}
我查看了grunt,gulp,RequireJS以及其他一些工具,但我还没有找到我喜欢的设置。任何建议,将不胜感激。 :)
答案 0 :(得分:0)
我认为Browserify实际上是一个很好的解决方案。我知道你在评论中提到它不是,但你看过这些选择吗?
--no-builtins
Turn off builtins. This is handy when you want to run a bundle in node which
provides the core builtins.
--no-commondir
Turn off setting a commondir. This is useful if you want to preserve the
original paths that a bundle was generated with.
--bare
Alias for both --no-builtins, --no-commondir, and sets --insert-global-vars
to just "__filename,__dirname". This is handy if you want to run bundles in
node.