grunt watch编译较少但不生成css

时间:2017-12-17 06:02:20

标签: gruntjs grunt-contrib-less

Grunt watch编译了我的LESS文件,但没有生成CSS文件。我不知道问题是什么。任何人都可以帮忙吗?

这是我的咕噜声代码:

    {
      test: /\.(png|jpg)$/,
      loader: 'url?limit=25000'
    }

这是我的module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-less'); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), less: { options: { paths: 'less', yuicompress: true }, files: { 'styles.css': 'less/button.less' } }, watch: { less: { files: 'less/*.less', tasks: 'less' } } }); } 代码:

package.json

请参阅下面的文件夹结构:

enter image description here

Grunt Watch工作正常:

enter image description here

1 个答案:

答案 0 :(得分:0)

Grunt希望您的less任务配置包含一个或多个_targets。每个可以任意命名的目标都有一个files对象。

您的配置中,Grunt认为files目标,因此控制台输出显示为Running less:files的原因。当Grunt在files目标中找不到files对象时,它会继续前进。

要修复配置,必须添加将包装files对象的目标对象。例如,

less: {
    options: {
        paths: 'less',
        yuicompress: true
    },
    dev: {
        files: {
            'styles.css': 'less/button.less'
        }
    }
},

有关Grunt任务配置和目标的更多信息,请参阅documentation