Rails 6: How to disable Webpack and use Sprockets instead

I found this link helpful, I will crosspost here:

Use option –skip-webpack-install when generating a new app

Change Gemfile, remove webpacker, add:

gem 'sass-rails', '>= 5'
gem 'sprockets', '~> 4'
gem 'sprockets-rails', :require => 'sprockets/railtie'

Then

bundle update sass-rails sprockets # if you are updating 
bundle install # or simply install

If you are using sprockets 4, change app/assets/config/manifest.js to:

//= link_tree ../images
//= link application.js
//= link application.css

If you are using sprockets 3, add to config/initializers/assets.rb:

# Rails.application.config.assets.precompile += %w( application.js )

Restore app/assets/javascripts/application.js:

//= require rails-ujs
//= require turbolinks
//= require_tree .

Change javascript_pack_tag to javascript_include_tag in app/views/layout/application.html.erb

Leave a Comment

tech