Skip to content

Commit

Permalink
🐛 fix assets compilation failing in prod
Browse files Browse the repository at this point in the history
Assets compilation was failing because tailwind css is trying to be compressed by sassc. Read: thoughtbot/administrate#2091

I have updated test and production enviroments and added a test that checks that no errors ocurs on the precompile task and that production config is matching tests in this specific scenario
  • Loading branch information
AlejandroMI committed Feb 2, 2023
1 parent 8e4fdb5 commit d90016c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
5 changes: 3 additions & 2 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?

# Compress CSS using a preprocessor.
# config.assets.css_compressor = :sass
# There's a compatibility issue if you turn Sass on,
# because SassC doesn't understand the modern CSS syntax used by Tailwind. Defaulting to nil
config.assets.css_compressor = nil

# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
Expand Down
4 changes: 4 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
# Tell Active Support which deprecation messages to disallow.
config.active_support.disallowed_deprecation_warnings = []

# There's a compatibility issue if you turn Sass on,
# because SassC doesn't understand the modern CSS syntax used by Tailwind. Defaulting to nil
config.assets.css_compressor = nil

# Raises error for missing translations.
# config.i18n.raise_on_missing_translations = true

Expand Down
19 changes: 19 additions & 0 deletions spec/tasks/assets_precompile_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'rails_helper'
require 'rake'

Rails.application.load_tasks if Rake::Task.tasks.empty?

RSpec.describe "assets", type: :task do
describe 'rake assets:precompile' do
let(:task) { Rake::Task["assets:precompile"] }

it 'does not throw an error when disabling css compressor' do
expect { task.invoke }.not_to raise_error
end

it 'makes sure that compressor is disabled in production' do
file = File.read("config/environments/production.rb")
expect(file).to include("config.assets.css_compressor = nil")
end
end
end

0 comments on commit d90016c

Please sign in to comment.