Feature request: Source Maps
Is it possible to get the LESS/SCSS compilers to generate source maps? This would show which LESS/SCSS files the rule(s) originally came from and assist with front-end debugging. If the plugin does not support this currently, is this something we can get the bundled libraries to generate?
I'll try look further into this and post back what I can find.
According to https://github.com/leafo/scssphp/issues/135, SCSS-PHP does not yet support source maps, although it does have some options to output line-numbers in the compiled code for easier debugging. That could possibly be a step in the right direction, but we may need to wait for the library to provide full support before this Craft plugin can also offer it.
Leafo's LESS-PHP (now defunct it seems?) also does not support source maps, however less.php does.
A good reference might be flazzarotto/sass-generator-bundle, which uses both leafo/scssphp and koala-framework/sourcemaps together to generate source-maps.
@SimonEast thank, your comment was very helpful. I was able to make source mapping works with using the flazzarotto/sass-generator-bundle as an example with koala-framework/sourcemaps.
@dstorozhuk Oh wonderful! Are you able to share your code or post a pull request? I was hoping to investigate this myself when I had a few hours, but hadn't found the time.
I did this in scope of my Drupal project. It exists as Drupal 8 module, probably i will share the module on github, abd here only a function which adds the source map.
Sorry, I just realised that this not right repo. I suppose this is leafo/scssphp. )
So here is my gist: https://gist.github.com/dstorozhuk/e90e6b151129f5bb9d20e871e0137d38
The code extends the Leafo\ScssPhp\Server. The most important methods for generating maps is CssServer::compile() and CssServer::generateMap().
OK, no worries. I appreciate you sharing your code anyway. Hopefully it will help myself and others attempting to generate source maps on other projects.
I have made some enhancements to the plugin and got source maps fully working now. :smile:
The last remaining bug I have to resolve is that when minifying the source mapping becomes inaccurate, so I still need to put a bit further work in to resolve that. I will post a pull-request once I get it closer to production-ready.
Managed to finish this off today and SCSS source maps now work nicely. Will send through a pull-request for others' feedback & testing shortly.