AutoMin-Craft icon indicating copy to clipboard operation
AutoMin-Craft copied to clipboard

Feature request: Source Maps

Open SimonEast opened this issue 9 years ago • 9 comments

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.

SimonEast avatar Jan 03 '17 05:01 SimonEast

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.

SimonEast avatar Jan 03 '17 05:01 SimonEast

A good reference might be flazzarotto/sass-generator-bundle, which uses both leafo/scssphp and koala-framework/sourcemaps together to generate source-maps.

SimonEast avatar Jan 03 '17 05:01 SimonEast

@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 avatar Feb 27 '17 21:02 dstorozhuk

@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.

SimonEast avatar Feb 27 '17 23:02 SimonEast

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.

dstorozhuk avatar Feb 28 '17 06:02 dstorozhuk

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().

dstorozhuk avatar Feb 28 '17 07:02 dstorozhuk

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.

SimonEast avatar Mar 03 '17 03:03 SimonEast

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.

SimonEast avatar May 07 '17 06:05 SimonEast

Managed to finish this off today and SCSS source maps now work nicely. Will send through a pull-request for others' feedback & testing shortly.

SimonEast avatar Jun 22 '17 07:06 SimonEast