Search code examples
gruntjsgrunt-contrib-concat

Invoking grunt concat two times with different options


I have different options to concat JS files and CSS files.

How can I configure grunt to run such a configuration ?

This doesn't work :

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'
        }
    }
}

Solution

  • This is ugly, but it works :

    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'
        }
    }