【问题标题】:Grunt Watch Task Not Triggering Uglify TaskGrunt Watch 任务未触发 Uglify 任务
【发布时间】:2015-07-28 04:47:44
【问题描述】:

我正在使用 Grunt 运行一个非常简单的工作流程,在 MAMP 中运行。我正在使用监视任务来触发 Sass 任务,该任务运行两个子任务(将扩展和压缩的样式表放在不同的目录中),以及缩小/连接 JavaScript 文件。 Sass 任务可以正常工作,但 Watch 任务不会看到任何 JavaScript 文件更改以触发 Uglify 任务。这是我的Grunt.js file

module.exports = function(grunt){
    grunt.initConfig({
        pkg : grunt.file.readJSON('package.json'),

        //Sass task
        sass:{
            dev: {
                options: {
                    style: 'expanded',
                    sourcemap: 'none'
                },
                files: {
                    //Destination, Source
                    'human-readable/style-expanded.css': 'sass/style.scss',
                    'human-readable/bootstrap-min.css': 'sass/bootstrap.scss'
                }
            },
            prod:{
                options:{
                    style: 'compressed',
                    sourcemap: 'none'
                },
                files:{
                    //Destination, Source
                    'style.css': 'sass/style.scss',
                    'css/bootstrap.min.css': 'sass/bootstrap.scss'
                }
            }
        },

        //Uglify task
        uglify:{
            options:{
                mangle: false,
                screwIE8: true
            },
            my_target:{
                files:{
                    //Destination, Source
                    'js/main.min.js': ['human-readable/main.js','js/bootstrap.min.js']
                }
            }
        },

        //Watch task
        watch: {
            css: {
                files: '**/*.scss',
                tasks: ['sass']
            },
            scripts: {
                files: '**/*.js',
                tasks: ['uglify']
            }
        }
    });

    grunt.loadNpmTasks('grunt-contrib-sass');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.registerTask('default', ['watch']);

}

想法?

【问题讨论】:

标签: javascript node.js gruntjs grunt-contrib-watch grunt-contrib-uglify


【解决方案1】:

可能是你试图同时看两件事,这可能是问题所在,试试grunt-concurrent 模块,它允许你同时/并行运行 grunt 任务:

grunt.loadNpmTasks('grunt-concurrent');
grunt.initConfig({
    ...
    concurrent: {
        tasks: ['watch:css', 'watch:script']
    }
    ...

grunt.registerTask('default', ['concurrent']);
...

【讨论】:

  • 这非常有效。我不知道手表不能并行运行同时任务。谢谢!
猜你喜欢
  • 2014-09-24
  • 1970-01-01
  • 2018-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-04
  • 1970-01-01
  • 1970-01-01
  • 2013-05-25
相关资源
最近更新 更多