咕噜咕噜地看着不运行任务

Grunt watch not running tasks

本文关键字:运行 任务      更新时间:2023-09-26

我正在尝试运行一个带有livereload和更少内容的grunt服务器。在grunt less它确实编译了我的较少文件,但是当更改较少的文件时,我得到的只是

>> File "app'style'componenets'components.less" changed.

我也尝试了更少的开发,但仍然没有运气。顺便说一句,我在我更改的每个文件上都实时加载,尽管在监视任务中我只配置了较少的位置。

提前感谢!

'use strict';
// Gruntfile with the configuration of grunt-express and grunt-open. No livereload yet!
module.exports = function(grunt) {
    // Load Grunt tasks declared in the package.json file
    require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
    console.log(__dirname + '''app''');
    // Configure Grunt 
    grunt.initConfig({
        // grunt-express will serve the files from the folders listed in `bases`
        // on specified `port` and `hostname`
        express: {
            all: {
                options: {
                    bases: ['app'],
                    port: 8080,
                    hostname: "0.0.0.0",
                    livereload: true
                }
            }
        },
        less: {
            development: {
                options: {
                    compress: true,
                    yuicompress: true
                },
                files: {
                    // target.css file: source.less file
                    "app/main.css": "app/style/main.less"
                }
            }
        },
        // grunt-watch will monitor the projects files
        watch: {
            less: {
                files: ['<%= express.all.options.base%>/style/*.less', '<%= express.all.options.base%>/style/componenets/*.less'],
                tasks: ['less']
            }
        },
        // grunt-open will open your browser at the project's URL
        open: {
            all: {
                // Gets the port from the connect configuration
                path: 'http://localhost:<%= express.all.options.port%>/#/'
            }
        }
    });
    // Creates the `server` task
    grunt.registerTask('server', [
        'express',
        'open',
        'watch'
    ])
    // Creates the `less` task
    grunt.registerTask('less', ['less']);
};

为什么别名任务在gruntfile的末尾?

// Creates the `less` task
grunt.registerTask('less', ['less']);

您的 Less 任务已经通过您的配置定义! 删除那行,你可能很好...

编辑:您的 less 配置中至少有 1 个错别字:

错:

<%= express.all.options.base %>/style/*.less'

正确:

<%= express.all.options.bases %>/style/*.less'