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)?

6

2 Answers

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 webpackergem 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:

  • Add <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> to /app/views/layouts/application.html.erb
  • Create /app/assets/javascripts/application.js (contents, e.g. here)
  • Add //= link_directory ../javascripts .js to app/assets/config/manifest.js

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.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy