gruntjssource-mapsgrunt-contrib-cssmin

How can I control grunt-contrib-cssmin sourcemap URLs?


I am trying to configure my Gruntfile to auto-generate sourcemaps for my CSS files. I have several unminified CSS files which I combine into one minified file, but I would like to reference the unminified files for debugging in dist/src/_assets/css/ via the sourcemap. I am using grunt-contrib-cssmin version 0.14.0 and grunt 0.4.5.

My goal project structure is roughly:

My grunt-contrib-cssmin config is:

        cssmin: {
            options: {
                keepSpecialComments: false,
                sourceMap: true
            },
            build: {
                files: {
                    'dist/_assets/css/portfolio.css': [
                        'src/_assets/css/bootstrap.css',
                        'src/_assets/css/font-awesome.css',
                        'src/_assets/css/portfolio.css'
                    ]
                }
            }
        },

I have a separate copy task that copies bootstrap.css, font-awesome.css, and portfolio.css to dist/src/_assets/css, but for some reason, the sourcemap is trying to reference dist/_assets/css/src/_assets/css/ instead of dist/src/_assets/css. Is there any way I can modify the directory the sourcemap is looking at without having to modify the sourcemap manually? This is pretty confusing to me because essentially the same settings in grunt-contrib-uglify do exactly what I want regarding sourcemaps (i.e. they reference dist/src/_assets/js).


Solution

  • Well, I gave up on trying to configure the sourcemap paths directly in grunt-contrib-cssmin and just used grunt-text-replace to get my paths squared away:

    replace: {
        build: {
            src: 'dist/_assets/css/portfolio.css.map',
            dest: 'dist/_assets/css/',
            replacements: [
                {
                    from: 'src/_assets/css/',
                    to: '../../../src/_assets/css/'
                }
            ]
        }
    },