grunt-contrib-sass prevent sourcemap

2.6k Views Asked by At

My Grunt setup is using sass to compile my .scss files to src/.css and cssmin to combine and minify my src/.css files to main.css.

I want to use the new sourcemap feature in SASS, but I'm not sure if it will really do anything for me considering cssmin will be putting all my css files into the main.css.

Does anyone have any insight into this?

I'm also, for now trying to turn off the sourcemap in grunt-contrib-sass and it won't take. Here's the relevant code in my Gruntfile.js:

sass: {
  dist: {
    options: {
      sourcemap: 'none'
    },
    files: [{
      expand: true,
      cwd: 'stylesheets/scss',
      src: ['**/*.scss'],
      dest: 'stylesheets/src',
      ext: '.css'
    }]
  }
},

from: github.com/gruntjs/grunt-contrib-sass

4

There are 4 best solutions below

0
On

Adding sourceMap: true as below solved the problem for me (NB: I'm using grunt.loadNpmTasks('grunt.sass')):

sass: {
  options: {
    includePaths: ['bower_components/foundation/scss'],
    imagePath: '/images'
  },
  dist: {
    options: {
      outputStyle: 'nested',
      sourceMap: true
    },
    files: [{
    expand: true,
            cwd: 'scss',
    src: ['[^_]*.scss'],
    dest: '../public/css/',
    ext: '.css'
    }]
  }
}

Hope that helps someone.

1
On

I just had this problem and the other solutions didn't help me. Here's how I fixed it:

options: {
  "sourcemap=none": ''
}

Using sass version 3.4.2, and npm update didn't help

0
On

I ran into the same problem. As suggested in the above comment by @imjared, updating grunt-contrib-watch and grunt-contrib-sass did the trick.

https://www.npmjs.org/doc/cli/npm-update.html

0
On

I know this question is old... but the issue actually bumped me just yesterday 2023.12.31. Sadly... grunt-contrib-sass no longer seems to be maintained.

By enabling grunt --verbose you can get a gist of what is going on in the background.

Running "sass:dist" (sass) task
Verifying property sass.dist exists in config...OK
Files: src/sass/app.scss -> assets/css/app.min.css
Options: style="compressed", sourcemap="none"
Writing assets/css/app.css...OK
Command: sass src/sass/app.scss assets/css/app.min.css --style=compressed --sourcemap=none
Could not find an option named "sourcemap".

Clearly the option sourcemap is no longer valid... Currently the sass docs want you to run it this way:

sass --no-source-map style.scss style.css

I was able to coerce grunt-contrib-sass to disable source maps like this:

sass: {
  dist: {
    options: {
      style: 'compressed',
      'no-source-map': true,
    },
    files: {
      'assets/css/app.min.css': 'src/sass/app.scss',
    },
  },
},

As you can see in the grunt --verbose output:

Running "sass:dist" (sass) task
Verifying property sass.dist exists in config...OK
Files: src/sass/app.scss -> assets/css/app.min.css
Options: style="compressed", no-source-map
Command: sass src/sass/app.scss assets/css/app.min.css --style=compressed --no-source-map
File public/assets/css/app.min.css created

It's probably a short term fix... just my two cents...