Short answer:
Add the following additional option to your less
Task in Gruntfile.js
:
...
options: {
...
sourceMapURL: '../../styles.map'
},
...
Long answer:
When running the lessc
command via the CLI, (as per your example), notice the the following comment is written to the resultant prod.css
:
/*# sourceMappingURL=../../styles.map */
However, when running the grunt
task, (using your current config), the following comment is written into the resultant prod.css
:
/*# sourceMappingURL=styles.map */
Note the missing ../../
- therefore prod.css
can't find styles.map
This is why your SourceMap isn't working and not so much to do with the "file:"
missing in styles.map
when run via grunt
. The .css
file ultimately points to the .map
file - not vice versa.
Even after running the lessc
command via the CLI then deleting the "file:"
part from styles.map
you will find that the SourceMap still works in the browser. Indicating that the "file:"
part, whether included in the .map
file or not, has no effect on preventing the SourceMap from working.
Besides, as noted in the most recent proposed SourceMap spec (v.3) the "file:"
part is optional:
Line 3: An optional name of the generated code that this source map is associated with.
Explicitly defining the sourceMapURL
in your grunt Task options will entail having to keep a flat folder structure inside the dest/assets/
directory if you intend on using multiple .less
files. (I.e. You'll need to avoid saving any resultant .css
files in subfolders)