错误
Running "less" task
Running "less:files" (less) task
Verifying property less.files exists in config...OK
Warning: Object #<Object> has no method 'indexOf' Use --force to continue.
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
less: {
files: [
{
expand: true,
cwd: 'public/css',
src: ['*.less'],
dest: 'public/css',
ext: '.css'
}
],
options: {
compress: true,
yuicompress: true,
optimization: 2
}
},
watch: {
files: "public/css/*",
tasks: ["less"]
},
});
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-contrib-less");
grunt.loadNpmTasks("grunt-contrib-requirejs");
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.registerTask('default', ['less', 'watch']);
};
非常感谢任何帮助,谢谢
答案 0 :(得分:6)
files
被解释为上述配置中的目标。因为它位于任务级别而不是目标级别。
只有在您为每个目标定义多个src / dest块时才需要files
属性。
由于您只有一个src / dest块,因此请修改配置以仅使用目标:
less: {
targetname: {
expand: true,
cwd: 'public/css',
src: ['*.less'],
dest: 'public/css',
ext: '.css'
},
options: {
compress: true,
yuicompress: true,
optimization: 2
}
},
名称targetname
是任意的,可以命名为任何名称。
需要files
的示例是以下多个src / dest块配置:
less: {
targetname: {
files: [
{ src: ['*.less'], dest: 'public/css/' },
{ src: ['other/*.less'], dest: 'other/css/' },
]
},
options: {
compress: true,
yuicompress: true,
optimization: 2
}
},