Reputation: 262
I am starting a new Rails 6 application. If I understood correctly, Webpack(er) (gem webpacker
) has replaced Sprockets as the new standard for including/minifying JS (source).
Furthermore, Rails 6 now both requires Node.js and Yarn.
Am I correct in assuming that the Node.js and Yarn dependencies are only due to the inclusion of Webpack, or do other components of Rails 6 also need them?
Are there any possible drawbacks in removing Webpack and Node and Yarn from the Rails 6 app and continuing to use the Rails Asset Pipeline (apart from missing Webpack features)?
Upvotes: 4
Views: 5580
Reputation: 366
It's in fact possible to run Rails 6 and higher with gem 'sprockets', '~> 4', gem 'sprockets-rails', :require => 'sprockets/railtie' and gem 'sassc-rails' for css and already migrate to gem "importmap-rails" for the javascript. I am updating my apps from 5.2. to 7.1. and it is much less work intensive (if you want to do it version by version) than introducing webpacker and then getting rid of it again for Rails 7. gem sassc-rails has not been maintained since 2019, so I will move forward to Rails 7.1. quickly and then use dartsass-sprockets instead.
Upvotes: 1
Reputation: 64
Yes, you can drop gems from Gemfile, delete the created node_modules folder and package.json file.
After that run bundle to clean up the Gemfile.lock and start code the old way with normal views and templates. Mention, that you will have to add js engine like Google V8.
In fact webpacker and node are not required to run a rails 6 application.
Upvotes: 4
Reputation: 262
It's possible to run Rails 6 without the webpacker
gem, Node.js and Yarn (see this Rails issue).
However, the --skip-webpack-install
option of Rails new
still includes the webpacker
gem in the Gemfile and sets up the resulting project with webpacker configuration (only rails webpacker:install
is not run).
If the Rails Asset Pipeline using Sprockets is to be used, the --skip-javascript
option is recommended and manual changes are necessary, in particular:
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
to /app/views/layouts/application.html.erb
/app/assets/javascripts/application.js
(contents, e.g. here)//= link_directory ../javascripts .js
to app/assets/config/manifest.js
Upvotes: 9