gruntjsgrunt-contrib-cssmin

How to structure a Grunt task for develop and release


I cant really seem to figure out how to structure the config for a certain task. Currently I'm trying to do this for cssmin.

This config snippet works fine:

cssmin: {
    options: {
        shorthandCompacting: false,
        roundingPrecision: -1
    },
    target: {
        files: {
            'wwwroot/all.css': ['bower_components/animate/animate.css']
        }
    }
},

And I'm running this like so:

grunt.registerTask('Test', ['cssmin']);

But I want create a develop and release config for this. So I tried the following config styles, all of them said Done, without errors., but none of the configs created a file.

cssmin: {
    options: {
        shorthandCompacting: false,
        roundingPrecision: -1
    },
    dev: {
        target: {
            files: {
                'wwwroot/all.css': ['bower_components/animate/animate.css']
            }
        }
    }
}
grunt.registerTask('Test', ['cssmin:dev']);

And like this:

cssmin: {
    dev: {
        options: {
            shorthandCompacting: false,
            roundingPrecision: -1
        },
        target: {
            files: {
                'wwwroot/all.css': ['bower_components/animate/animate.css']
            }
        }
    }
}
grunt.registerTask('Test', ['cssmin:dev']);

But those configs don't seem to work. They save Done, without errors., but it isn't creating a CSS file like the first config example does.

So isn't this the way you should create a different dev/release type of config? What am I doing wrong here?


Solution

  • When you call cssmin:dev, dev is your target. there is no need to specify the target propriety w/in it again. try this:

    cssmin: {
        dev: {
            options: {
                shorthandCompacting: false,
                roundingPrecision: -1
            },
            files: {
                'wwwroot/all.css': ['bower_components/animate/animate.css']
            }
        },
        build : {
            options: {
                shorthandCompacting: true,
                roundingPrecision: -1
            },
            files: {
                'wwwroot/all.min.css': ['bower_components/animate/animate.css']
            }
        }
    }
    grunt.registerTask('Test', ['cssmin:dev']);