我是Grunt的新手,我迷失了它的所有选择。 我试图做两件事:
这是我当前的Gruntfile.js:
module.exports = function (grunt) {
grunt.initConfig({
// define source files and their destinations
uglify: {
files: {
src: 'js/*.js', // source files mask
dest: 'jsm/', // destination folder
expand: true, // allow dynamic building
flatten: true, // remove all unnecessary nesting
ext: '.min.js' // replace .js to .min.js
}
},
watch: {
js: { files: 'js/*.js', tasks: [ 'uglify' ] },
}
});
// load plugins
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-uglify');
// register at least this one task
grunt.registerTask('default', [ 'uglify' ]);
};
我怎么能实现这个目标?
答案 0 :(得分:1)
grunt.initConfig({
concat: {
dist: {
src: ['files/**.min.js'],
dest: 'project.js',
},
}
});
您应该将所有文件包装在匿名函数中并使用var
定义变量,这样就不会在文件之间产生变量冲突。
(function(){
// foo has function scope
var foo = 3;
console.log(foo);
// FOO is a global variable and
// can be accessed between files
window.FOO = 3;
console.log(FOO);
}).call()