用不同的选项调用grunt concat两次

时间:2014-11-10 08:09:38

标签: gruntjs grunt-contrib-concat

我有不同的选项来连接JS文件和CSS文件。

如何配置grunt来运行这样的配置?

这不起作用:

concat: {
    js: { // Custom options for JS
        options: {
            separator: '\n',
            sourceMap: true,
            banner: '...',
        },
        core: {
            src: ['src/core/*.js', 'src/core/**/*.js'],
            dest: 'assets/xxxx.js'
        }
    },
    css: { // Default options for CSS
        core: {
            src: ['src/core/*.css', 'src/core/**/*.css'],
            dest: 'assets/xxxx.css'
        }
    }
}

1 个答案:

答案 0 :(得分:3)

这很丑陋,但确实有效:

grunt.loadNpmTasks('grunt-contrib-concat');

grunt.renameTask('concat', 'concatCss');
grunt.loadNpmTasks('grunt-contrib-concat');
// The task is then loaded two times, under 'concat' and 'concatCss' names.

...
concat: {  
    options: {
        separator: '\n',
        sourceMap: true,
        banner: '...',
    },
    core: {
        src: ['src/core/*.js', 'src/core/**/*.js'],
        dest: 'assets/xxxx.js'
    },
concatCss: { // Default options for CSS
    core: {
        src: ['src/core/*.css', 'src/core/**/*.css'],
        dest: 'assets/xxxx.css'
    }
}