andreyfedoseev / django-static-precompiler

Django Static Precompiler provides template tags and filters to compile CoffeeScript, LiveScript, SASS / SCSS, LESS, Stylus, Babel and Handlebars. It works with both inline code and external files.
Other
222 stars 60 forks source link

Switch to Dart Sass as Ruby Sass has reached EOL #148

Closed mclrc closed 1 year ago

mclrc commented 2 years ago

Ruby Sass has reached EOL and the official Sass website only provides instructions for installing the NPM package (Dart Sass) Due to these lines in scss.py

   11         args = [
   12             self.executable,
   13             "--sourcemap={0}".format("auto" if self.is_sourcemap_enabled else "none"),
   14         ] + self.get_extra_args()
   15

sass is being passed --sourcemap, with an argument, either auto or none which is incompatible with Dart Sass.

$ sass --version
1.52.3 compiled with dart2js 2.17.3
$ sass --help
...
━━━ Source Maps ━━━━━━━━━━━━━━━━━━━━━━━━
    --[no-]source-map          Whether to generate source maps.
                               (defaults to on)
...

This results in an error during compilation which is hard for a consumer to pinpoint, as it is simply a StaticCompilationError without any further information.

The only reason I figured out what the problem was and which version of sass was expected is because I had a look at the docker image used for the tests. If switching to Dart Sass is currently not desirable, I think clarifying the expected version of sass in the docs would be a very good idea as I (and presumably others) would have been able to fix my problem much quicker.

With minor changes, e. g. passing either --no-source-map or --source-map, the StaticCompilationErrors cease and everything behaves as expected. There may be other compatibility issues between Dart and Ruby Sass, but I haven't encountered any in my use. If you like, I could start work on a PR.

I apologize if I missed something in the docs or anything like that, I'm quite new to all this.

Thanks for this great library, and have a nice day!

andreyfedoseev commented 1 year ago

I think Dart Sass support can be enabled by creating a new custom compiler, probably by sub-classing the included SCSS compiler (see libsass.SCSS for an example).

I don't mind including that new compiler to the project and you're welcome to work on a PR.

andreyfedoseev commented 1 year ago

I'm planning to include this in the next release, but I don't have an ETA yet. I'd appreciate if someone created a working PR work that, this may speed things up.

andreyfedoseev commented 1 year ago

Fixed in https://github.com/andreyfedoseev/django-static-precompiler/releases/tag/2.4