I'm migrating a Rails 5.2 app to 6.0 for ActionMailbox, ActionText, and multiple databases. However, I don't know webpack and would like to use Sprockets instead.
How do I properly remove webpack from Rails 6 and install Sprockets? rails new app
installs webpack files right away. Is there a way to default to sprockets easily?
Rails (Ruby) was supposed to be convention over configuration, but Webpack (Javascript) cancels this by adding a lot of config and complexity.
Sprockets is a Ruby library for compiling and serving web assets. Sprockets allows to organize an application's JavaScript files into smaller more manageable chunks that can be distributed over a number of directories and files.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With