Open mscarchilli opened 9 years ago
I think we should have the .map file at the same location as the generated CSS file. This keeps things consistent and the configuration easier to read.
...
files: {
'some/path/custom.css': 'another/path/file.scss'
}
...
This should generate some/path/custom.css
and some/path/custom.css.map
.
This will not always work depending on the project you are working on and how it is organized. Being able to set the path for the sourcemap is more useful. This way you get the best of both worlds. Default could be the same location as the CSS, but add the option to set it to another. Some other Grunt plugins already have this ability.
Okay - so the .map should be generated at the same location as the CSS by default - but we need some mechanism to put .map files in another location.
I looked into this for a bit today and here are my findings.
grunt-contrib-sass depends on Ruby's sass
executable. Version 3.4 of this executable has support for generating sourcemaps - but no way to specify the location of the .map file. This means we're limited by the original script and not this plugin.
The other plugins use the C/C++ libsass
which supports writing the map to a different location.
To get the sourceMapDest
property for this plugin working, we would have to move the generated map to the specified destination after sass
finishes execution.
Here's what I have right now:
module.exports = function(grunt) {
grunt.initConfig({
sass: {
options: {
sourcemap: 'auto',
sourcemapDest: 'something/other/'
},
dist: {
files: {
'something/test.css': 'custom.scss'
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.registerTask('default', ['sass']);
};
custom.scss
is parsed and something/test.css
is generated. The sourcemap something/test.css.map
is also generated at the same time. The plugin then notices you've set sourcemapDest
- so it moves the .map file to this directory.
Potential issue: The file something/test.css
needs to be updated with the new sourcemap path. This can be resolved by running the css file through a find & replace operation.
Is this a good way to solve this issue?
This should be fixed in Ruby Sass, not here. → https://github.com/sass/sass/issues/new
Looks good so far. @sindresorhus , which aspect of all of this should be fixed in Ruby Sass?
Setting custom path for sourcemap file
I exposed a file name flag in the sass
binary on my local machine. Let's see if this gets accepted into Sass.
https://github.com/liquidmetal/sass/commit/5bfe9ccd09d6ae056b83ce9ec2842fb1472d8f55
If it does, we can have a new parameter: sourcemapFilename
that contains the output map file name.
Awaiting on https://github.com/sass/sass/pull/1844 to proceed.
Would you please add this as a feature for the sourcemap options in a future release? Thank you!