【问题标题】:Grunt watch not running tasksGrunt watch 不运行任务
【发布时间】:2014-12-08 17:25:49
【问题描述】:

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

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

我也尝试了 less:development 但仍然没有运气。 顺便说一句,我更改的每个文件都得到了 livereload,尽管在监视任务中我只配置了较少的位置..

提前致谢!

'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']);
};

【问题讨论】:

    标签: javascript node.js gruntjs less


    【解决方案1】:

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

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

    你的 less 任务已经通过你的配置定义了!删除那条线,你可能会很好......

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

    错误:

    /style/*.less'

    正确:

    /style/*.less'

    【讨论】:

    • 查看我的编辑。确保您的路径等设置正确!
    猜你喜欢
    • 2015-06-04
    • 2013-05-25
    • 2015-12-29
    • 1970-01-01
    • 2017-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多