Eri*_*rik 2 javascript backbone.js gruntjs
我有一些javascript代码,我需要重叠到自执行匿名函数,如BackboneJS:
(function(root, factory) {
// Set up Backbone appropriately for the environment. Start with AMD.
if (typeof define === 'function' && define.amd) {
define(['underscore', 'jquery', 'exports'], function(_, $, exports) {
// Export global even in AMD case in case this script is loaded with
// others that may still expect a global Backbone.
root.Backbone = factory(root, exports, _, $);
});
// Next for Node.js or CommonJS. jQuery may not be needed as a module.
} else if (typeof exports !== 'undefined') {
var _ = require('underscore');
factory(root, exports, _);
// Finally, as a browser global.
} else {
root.Backbone = factory(root, {}, root._, (root.jQuery || root.Zepto || root.ender || root.$));
}
}(this, function(root, Backbone, _, $) {
Run Code Online (Sandbox Code Playgroud)
答案是肯定的,如果你想将文件分成几块,然后在连接之后将它放在像这样的函数里面
(function(){
// file 1 content
// file 2 content
})();
Run Code Online (Sandbox Code Playgroud)
你需要grunt.loadNpmTasks('grunt-contrib-concat'); 并定义横幅和页脚:
concat: {
app: {
options: {
separator: ';\n',
banner: '(function(){\n',
footer: '\n})();'
},
src: [
'src/*.js'
],
dest: 'app.js'
}
},
Run Code Online (Sandbox Code Playgroud)