基本上,一开始一切正常,但修改后,CSS没有更新。
首先,我的包裹详情:
"node" : "0.10.21"
[...]
"grunt": "~0.4.1",
"grunt-contrib-uglify": "~0.2.7",
"grunt-contrib-jshint": "~0.7.1",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-less": "~0.8.1"
接下来,我的 gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
options: {
separator: ''
},
dist: {
src: [ 'src/js/libs/jquery-2.0.3.min.js',
'src/js/libs/**/*.js',
'src/js/app/**/*.js'],
dest: 'public/js/combo.js'
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
},
dist: {
files: {
'public/js/combo.min.js': ['public/js/combo.js']
}
}
},
less: {
compile: {
options: {
compress:true
},
files: {
'public/css/application.css': ['src/css/application.less']
}
}
},
jshint: {
files: ['gruntfile.js', 'src/js/**/*.js','src/css/**/*.less','public/index.html'],
options: {
globals: {
jQuery: true,
console: true,
module: true,
document: true
}
}
},
watch: {
files: ['<%= jshint.files %>'],
tasks: ['default']
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['concat','uglify','less','watch']);
};
解释
首先,一切正常,创建了所有文件:
Running "concat:dist" (concat) task
File "public/js/combo.js" created.
Running "uglify:dist" (uglify) task
File "public/js/combo.min.js" created.
Running "less:compile" (less) task
App runnning on http://localhost:3000
File public/css/application.css created.
Running "watch" task
Waiting...
但是,如果我在我的 *.less 文件中进行修改:
OK
>> File "src\css\application.less" changed.
Running "concat:dist" (concat) task
Completed in 2.039s at Tue Nov 12 2013 11:44:53 GMT-0500 (Eastern Standard Time) - Waiting...
因此,watch检测到了修改,但我的CSS文件没有更新,我不知道为什么。我尝试了几种无贡献的实现,并且保持相同的方式。我想我做错了什么但是什么?
PS:concat和uglify工作得很好。