twbs / bootstrap-sass

Official Sass port of Bootstrap 2 and 3.
http://getbootstrap.com/css/#sass
MIT License
12.59k stars 3.53k forks source link

Removal of sassc dependency #1235

Open marcrohloff opened 2 years ago

marcrohloff commented 2 years ago

Can the sassc dependency be removed?

We are using dartsass and would rather not have this as an explicit dependency

Deele commented 2 years ago

AFAIK, this project does not support DartSass and is using sassc/LibSass (C++ one, not Ruby one).

DartSass is very different from LibSass, don't expect this project to work properly with it.

marcrohloff commented 2 years ago

I realize that. It would be nice to not have the unneeded dependency since sassc is no longer maintained and it seems to be working fine for us. Changing to a newer version of bootstrap but that is a much bigger project

jgraichen commented 1 year ago

Version 3.4.2 did break support for sassc/libsass by introducing math.div. Everyone will have to upgrade to dartsass/dartsass-sprockets now. Using sassc will not work anymore at all.

rgaufman commented 6 months ago

Any update on this? - is there an alternative gem that doesn't use the deprecated sassc?

nimmolo commented 5 months ago

@rgaufman I can confirm that switching from sassc to dartsass-sprockets works for our Rails 7 app.

But if we try to switch to dartsass-rails, assets:precompile fails.

Reading through the code of this gem, it seems that sprockets-rails is not a dependency. Is there anyone who has gotten this to work with dartsass-rails? (I started a new issue for this in #1247)

mhenrixon commented 2 months ago

@rgaufman I can confirm that switching from sassc to dartsass-sprockets works for our Rails 7 app.

But if we try to switch to dartsass-rails, assets:precompile fails.

Reading through the code of this gem, it seems that sprockets-rails is not a dependency. Is there anyone who has gotten this to work with dartsass-rails? (I started a new issue for this in #1247)

I have the following setup:

# Gemfile
gem "addressable"
gem "bcrypt"
gem "bootsnap", require: false
gem "coffee-rails"
gem "dartsass-ruby"
gem "dartsass-sprockets"
gem "mini_racer"
gem "rails", "~> 6.1"
gem "responders"
gem "sass"
gem "uglifier"

gem "ace-rails-ap", "~> 4.4"
gem "bootstrap-sass", "~> 3.4"
gem "bourbon"
gem "chosen-rails"
gem "ckeditor_rails"
gem "jquery-rails"
gem "jquery-ui-rails"
gem "select2-rails"

Don't judge; I recently upgraded everything and haven't gotten around to dropping jQuery or upgrading Bootstrap.

# config/assets.rb
Rails.application.config.assets.digest = true
Rails.application.config.assets.css_compressor = :sassc

Using liquid and such, I had to update my importer:

# app/utils/sass_importer.rb

class SassImporter < SassC::Importer
  def initialize(options)
    @options   = options
    @site_id   = options[:site_id]
    @syntax    = options[:syntax]
    @css_files = options[:css_files].to_a
  end

  def imports(path, parent_path)
    parent_name = parent_path.split("/").last
    return unless (template = find_template(path))

    content = if template.tpl_ext == "sass"
      SassC::Sass2Scss.convert(template.raw_content)
    else
      template.raw_content
    end

    SassC::Importer::Import.new(
      path,
      source: content,
    )
  end

  private

  attr_reader :site_id, :syntax, :css_files

  def find_template(path)
    css_files.find { |t| t.name == path }
  end
end

Now I had to change some imports etc during the upgrade but dartsass-ruby is working great for us with dartsass-sprockets.

It isn't ideal and eventually, I'd love to kill all traces of sprockets.

Unfortunately, dartsass-rails aren't very good yet. I tried it, and it fails to build, and it produced cryptic error messages. You would likely be better off using dartsass on the JS side then (yarn, bun, etc).