[英]Grunt usemin task not working on nested files while minifying angular files
[英]Grunt - Minifying/processing multiples files into one
我是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' ]);
};
我怎樣才能做到這一點?
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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.