gruntjs - 运行多个相同任务类型的 Grunt 任务

标签 gruntjs grunt-contrib-concat

我需要能够在 Grunt (grunt-contrib-concat) 中运行多个相同类型任务的任务。我在下面尝试了几件事,但都没有奏效。任何关于如何做到这一点的想法表示赞赏。

concat: {
    dist: {
        src: [
            'js/foo1/bar1.js',
            'js/foo1/bar2.js'
        ],
        dest: 'js/foo1.js',
        src: [
            'js/foo2/bar1.js',
            'js/foo2/bar2.js'
        ],
        dest: 'js/foo2.js'
    }
}

和..
concat: {
    dist: {
        src: [
            'js/foo1/bar1.js',
            'js/foo1/bar2.js'
        ],
        dest: 'js/foo1.js'
    }
},
concat: {
    dist: {
        src: [
            'js/foo2/bar1.js',
            'js/foo2/bar2.js'
        ],
        dest: 'js/foo2.js'
    }
}

和..
concat: {
    dist: {
        src: [
            'js/foo1/bar1.js',
            'js/foo1/bar2.js'
        ],
        dest: 'js/foo1.js'
    },
    dist: {
        src: [
            'js/foo2/bar1.js',
            'js/foo2/bar2.js'
        ],
        dest: 'js/foo2.js'
    }
}

最佳答案

首先为任务定义两个目标:

concat: {
    dist1: {
        src: [
            'js/foo1/bar1.js',
            'js/foo1/bar2.js'
        ],
        dest: 'js/foo1.js'
    },
    dist2: {
        src: [
            'js/foo2/bar1.js',
            'js/foo2/bar2.js'
        ],
        dest: 'js/foo2.js'
    }
}

然后注册一个运行两者的新任务:
grunt.registerTask('dist', ['concat:dist1', 'concat:dist2']);

然后运行使用
grunt dist

关于gruntjs - 运行多个相同任务类型的 Grunt 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22539733/

相关文章:

javascript - Durandal View 偶尔无法正确加载,并且在缩小时总是无法正确加载

javascript - 运行 Grunt Express Server 会导致错误 : ENOENT: no such file or directory, open 'static/test.json'

node.js - 将 Sails.js 项目部署到 Google 云 : "Fatal error: Unable to find local grunt."

javascript - Gruntjs:复制文件时替换模板

gruntjs - 为什么在工作流程中将供应商 CSS 和 JS 与自定义 CSS 和 JS 分开?

javascript - Gruntjs angularjs cordova 图像未加载

javascript - 将 grunt 添加到基于 AngularJS 构建的现有应用程序

gruntjs - 如何在缩小文件的末尾添加构建时间戳

javascript - Grunt 不观察 JS 文件

gruntjs - 为什么建议先使用 concat,然后使用 uglify,而后者可以两者兼得?