Skip to content

Commit 64bb72f

Browse files
committed
Upgrade to react_on_rails 16.4.0, shakapacker 9.7, and rspack v2
1 parent 1e191ab commit 64bb72f

13 files changed

Lines changed: 705 additions & 932 deletions

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
55

66
ruby "3.4.6"
77

8-
gem "react_on_rails", "16.4.0.rc.9"
9-
gem "shakapacker", "9.6.1"
8+
gem "react_on_rails", "16.4.0"
9+
gem "shakapacker", "9.7.0"
1010

1111
# Bundle edge Rails instead: gem "rails", github: "rails/rails"
1212
gem "listen"

Gemfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ GEM
293293
erb
294294
psych (>= 4.0.0)
295295
tsort
296-
react_on_rails (16.4.0.rc.9)
296+
react_on_rails (16.4.0)
297297
addressable
298298
connection_pool
299299
execjs (~> 2.5)
@@ -384,7 +384,7 @@ GEM
384384
websocket (~> 1.0)
385385
semantic_range (3.1.1)
386386
sexp_processor (4.17.1)
387-
shakapacker (9.6.1)
387+
shakapacker (9.7.0)
388388
activesupport (>= 5.2)
389389
package_json
390390
rack-proxy (>= 0.6.1)
@@ -483,7 +483,7 @@ DEPENDENCIES
483483
rails-html-sanitizer
484484
rails_best_practices
485485
rainbow
486-
react_on_rails (= 16.4.0.rc.9)
486+
react_on_rails (= 16.4.0)
487487
redcarpet
488488
redis (~> 5.0)
489489
rspec-rails (~> 6.0.0)
@@ -495,7 +495,7 @@ DEPENDENCIES
495495
scss_lint
496496
sdoc
497497
selenium-webdriver (~> 4)
498-
shakapacker (= 9.6.1)
498+
shakapacker (= 9.7.0)
499499
spring
500500
spring-commands-rspec
501501
stimulus-rails (~> 1.3)

Procfile.dev

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
# You can run these commands in separate shells
33
#
44
# Note: bin/dev runs precompile tasks (rescript + locale) BEFORE starting these processes.
5-
# This ensures all generated files exist before webpack starts watching.
5+
# This ensures all generated files exist before Rspack starts watching.
66
#
77
# ReScript watch mode (no clean - bin/dev already did the clean build)
88
rescript: yarn res:watch
99
# redis: redis-server # Run Redis as a system service instead (brew services start redis)
1010
rails: bundle exec thrust bin/rails server -p 3000
11-
# Client webpack dev server with HMR
11+
# Client Rspack dev server with HMR
1212
wp-client: RAILS_ENV=development NODE_ENV=development bin/shakapacker-dev-server
13-
# Server webpack watcher for SSR bundle
13+
# Server Rspack watcher for SSR bundle
1414
wp-server: SERVER_BUNDLE_ONLY=yes bin/shakapacker --watch

Procfile.dev-prod-assets

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
web: bundle exec thrust bin/rails server -p 3001
33
redis: redis-server
44

5-
# Next line runs a watch process with webpack to compile the changed files.
6-
# When making frequent changes to client side assets, you will prefer building webpack assets
5+
# Next line runs a watch process with Rspack to compile changed files.
6+
# When making frequent changes to client side assets, you will prefer building Rspack assets
77
# upon saving rather than when you refresh your browser page.
88
# Note, if using React on Rails localization you will need to run
99
# `bundle exec rake react_on_rails:locale` before you run bin/shakapacker
10-
webpack: sh -c 'bundle exec rake react_on_rails:locale && rm -rf public/packs/* || true && bin/shakapacker -w'
10+
rspack: sh -c 'bundle exec rake react_on_rails:locale && rm -rf public/packs/* || true && bin/shakapacker -w'

Procfile.dev-static

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
web: bundle exec thrust bin/rails server -p 3000
33
redis: redis-server
44

5-
# Next line runs a watch process with webpack to compile the changed files.
6-
# When making frequent changes to client side assets, you will prefer building webpack assets
5+
# Next line runs a watch process with Rspack to compile changed files.
6+
# When making frequent changes to client side assets, you will prefer building Rspack assets
77
# upon saving rather than when you refresh your browser page.
88
# Note, if using React on Rails localization you will need to run
99
# `bundle exec rake react_on_rails:locale` before you run bin/shakapacker
1010
# Sleep 5 to allow other rescript files to build
11-
webpack: sleep 5 && sh -c 'bundle exec rake react_on_rails:locale && rm -rf public/packs/* || true && bin/shakapacker -w'
11+
rspack: sleep 5 && sh -c 'bundle exec rake react_on_rails:locale && rm -rf public/packs/* || true && bin/shakapacker -w'

Procfile.dev-static-assets

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
web: bundle exec thrust bin/rails server -p 3000
33
redis: redis-server
44

5-
# Next line runs a watch process with webpack to compile the changed files.
6-
# When making frequent changes to client side assets, you will prefer building webpack assets
5+
# Next line runs a watch process with Rspack to compile changed files.
6+
# When making frequent changes to client side assets, you will prefer building Rspack assets
77
# upon saving rather than when you refresh your browser page.
88
# Note, if using React on Rails localization you will need to run
99
# `bundle exec rake react_on_rails:locale` before you run bin/shakapacker
10-
webpack: sh -c 'bundle exec rake react_on_rails:locale && rm -rf public/packs/* || true && bin/shakapacker -w'
10+
rspack: sh -c 'bundle exec rake react_on_rails:locale && rm -rf public/packs/* || true && bin/shakapacker -w'

README.md

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![Code Climate](https://codeclimate.com/github/shakacode/react-webpack-rails-tutorial/badges/gpa.svg)](https://codeclimate.com/github/shakacode/react-webpack-rails-tutorial) [![Coverage Status](https://coveralls.io/repos/shakacode/react-webpack-rails-tutorial/badge.svg?branch=master&service=github)](https://coveralls.io/github/shakacode/react-webpack-rails-tutorial?branch=master)
22

3-
# React, Redux, Tailwind CSS, ES7, Webpack, Ruby on Rails Demo
3+
# React, Redux, Tailwind CSS, ES2024, Rspack, Ruby on Rails Demo
44

55
* Server-Side Rendering of React via the [react_on_rails gem](https://github.com/shakacode/react_on_rails)
66
* Live at [www.reactrails.com](http://www.reactrails.com/)
@@ -30,8 +30,8 @@ React on Rails Pro provides Node server rendering and other performance enhancem
3030

3131
For more information, see the [React on Rails Pro Docs](https://www.shakacode.com/react-on-rails-pro/).
3232

33-
* Optimizing your front end setup with Webpack v5+ and Shakapacker for React on Rails including code splitting with loadable-components.
34-
* Upgrading your app to use the current Webpack setup that skips the Sprockets asset pipeline.
33+
* Optimizing your front end setup with Rspack + Shakapacker for React on Rails, including SSR and code splitting.
34+
* Upgrading your app to the current React on Rails 16.4 / Shakapacker 9.7 stack with modern asset builds.
3535
* Better performance client and server side.
3636

3737
ShakaCode can also help you with your custom software development needs. We specialize in marketplace and e-commerce applications that utilize both Rails and React. We can even leverage our code for [HiChee.com](https://hichee.com) for your app!
@@ -77,9 +77,9 @@ You can see this tutorial live here: [http://reactrails.com/](http://reactrails.
7777
+ [Technologies Involved](#technologies-involved)
7878
+ [Basic Demo Setup](#basic-demo-setup)
7979
+ [Basic Command Line](#basic-command-line)
80-
+ [Javascript Development without Rails](#javascript-development-without-rails-using-the-webpack-dev-server)
80+
+ [Javascript Development without Rails](#javascript-development-without-rails-using-the-rspack-dev-server)
8181
+ [Rails Integration](#rails-integration)
82-
+ [Webpack](#webpack)
82+
+ [Rspack](#rspack-with-shakapacker)
8383
+ [Configuration Files](#configuration-files)
8484
+ [Additional Resources](#additional-resources)
8585
+ [Thruster HTTP/2 Proxy](#thruster-http2-proxy)
@@ -95,13 +95,13 @@ You can see this tutorial live here: [http://reactrails.com/](http://reactrails.
9595

9696
## Demoed Functionality
9797

98-
- Example of using the [react_on_rails gem](https://github.com/shakacode/react_on_rails) for easy react/webpack integration with Rails.
99-
- Example of React with [CSS Modules](http://glenmaddern.com/articles/css-modules) inside of Rails using Webpack as described in [Smarter CSS builds with Webpack](http://bensmithett.com/smarter-css-builds-with-webpack/).
98+
- Example of using the [react_on_rails gem](https://github.com/shakacode/react_on_rails) for easy React + Rspack integration with Rails.
99+
- Example of React with [CSS Modules](http://glenmaddern.com/articles/css-modules) inside Rails using modern Shakapacker/Rspack builds.
100100
- Example of enabling hot reloading of both JS and CSS (modules) from your Rails app in development mode. Change your code. Save. Browser updates without a refresh!
101101
- Example of React/Redux with Rails Action Cable.
102-
- Example of Rails 7 with ReactJs/Redux/React-Router with Webpack and ES7.
103-
- Enabling development of a JS client independently from Rails using the [Webpack Dev Server](https://webpack.js.org/configuration/dev-server/). You can see this by starting the app and visiting http://localhost:4000
104-
- Enabling the use of npm modules and [Babel](https://babeljs.io/) with a Rails application using [Webpack](https://webpack.github.io/).
102+
- Example of Rails 8 with ReactJs/Redux/React-Router with Rspack and modern JavaScript.
103+
- Enabling development of a JS client independently from Rails using the Rspack dev server. You can see this by starting the app and visiting http://localhost:4000
104+
- Enabling the use of npm modules and [Babel](https://babeljs.io/) with a Rails application using [Rspack](https://rspack.dev/).
105105
- Easily enable retrofitting such a JS framework into an existing Rails app. You don't need a brand new single page app!
106106
- Example setting up Ruby and JavaScript linting in a real project, with corresponding CI rake tasks.
107107
- Enabling the i18n functionality with [react-intl](https://github.com/yahoo/react-intl).
@@ -115,11 +115,11 @@ See package.json and Gemfile for versions
115115
1. [Redux](https://github.com/reactjs/redux)
116116
1. [react-router](https://github.com/reactjs/react-router)
117117
1. [react-router-redux](https://github.com/reactjs/react-router-redux)
118-
1. [Webpack with hot-reload](https://github.com/webpack/docs/wiki/hot-module-replacement-with-webpack) (for local dev)
118+
1. [Rspack with hot-reload](https://rspack.dev/guide/features/dev-server) (for local dev)
119119
1. [Babel transpiler](https://github.com/babel/babel)
120-
1. [Ruby on Rails 7](http://rubyonrails.org/) for backend app and comparison with plain HTML
120+
1. [Ruby on Rails 8](http://rubyonrails.org/) for backend app and comparison with plain HTML
121121
1. [Thruster](https://github.com/basecamp/thruster) - Zero-config HTTP/2 proxy for optimized asset delivery
122-
1. [Heroku for Rails 7 deployment](https://devcenter.heroku.com/articles/getting-started-with-rails7)
122+
1. [Heroku deployment guide](https://devcenter.heroku.com/articles/getting-started-with-rails7)
123123
1. [Deployment to the ControlPlane](.controlplane/readme.md)
124124
1. [Turbolinks 5](https://github.com/turbolinks/turbolinks)
125125
1. [Tailwind CSS](https://github.com/tailwindlabs/tailwindcss)
@@ -128,7 +128,7 @@ See package.json and Gemfile for versions
128128

129129
### Prerequisites
130130
- Node `v22.3.0` or above. Be sure that you have Node installed! We suggest using [nvm](https://github.com/creationix/nvm) and running `nvm list` to check the active Node version. See this article [Updating and using nvm](http://forum.shakacode.com/t/updating-and-using-nvm/293).
131-
- Ruby 3.3.3 or above
131+
- Ruby 3.4.6 or above
132132
- Postgres v9.2 or above
133133
- Redis. Check that you have Redis installed by running `which redis-server`. If missing and on MacOS, install with Homebrew (`brew install redis`)
134134
- [Yarn](https://yarnpkg.com/).
@@ -148,8 +148,12 @@ See package.json and Gemfile for versions
148148
- To start all development processes: `foreman start -f Procfile.dev`
149149
- To start only all Rails development processes: `foreman start -f Procfile.hot`
150150

151+
## Javascript Development without Rails using the Rspack Dev Server
152+
153+
Start the full development stack with `foreman start -f Procfile.dev`, then open <http://localhost:4000> to iterate on the JavaScript client with hot reloading.
154+
151155
## Rails Integration
152-
**We're now using Webpack for all Sass and JavaScript assets so we can do CSS Modules within Rails!**
156+
**We're now using Rspack for all Sass and JavaScript assets so we can do CSS Modules within Rails!**
153157

154158
+ **Production Deployment**: [heroku-deployment.md](https://github.com/shakacode/react_on_rails/blob/master/docs/additional-reading/heroku-deployment.md).
155159
+ Configure Buildpacks
@@ -164,54 +168,44 @@ See package.json and Gemfile for versions
164168
165169
+ Be sure to see [Integration Test Notes](./docs/integration-test-notes.md) for advice on running your integration tests.
166170
167-
+ **Testing Mode**: When running tests, it is useful to run `foreman start -f Procfile.spec` in order to have webpack automatically recompile the static bundles. Rspec is configured to automatically check whether or not this process is running. If it is not, it will automatically rebuild the webpack bundle to ensure you are not running tests on stale client code. This is achieved via the `ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)`
171+
+ **Testing Mode**: When running tests, it is useful to run `foreman start -f Procfile.spec` in order to have Rspack automatically recompile the static bundles. Rspec is configured to automatically check whether or not this process is running. If it is not, it will automatically rebuild the bundle to ensure you are not running tests on stale client code. This is achieved via the `ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)`
168172
line in the `rails_helper.rb` file. If you are using this project as an example and are not using RSpec, you may want to implement similar logic in your own project.
169173
170-
## Webpack and Rspack
174+
## Rspack with Shakapacker
171175
172-
_Converted to use Shakapacker with support for both Webpack and Rspack bundlers_.
176+
_This project is standardized on Rspack with Shakapacker._
173177
174-
This project supports both Webpack and Rspack as JavaScript bundlers via [Shakapacker](https://github.com/shakacode/shakapacker). Switch between them by changing the `assets_bundler` setting in `config/shakapacker.yml`:
178+
Bundler selection is fixed in `config/shakapacker.yml`:
175179
176180
```yaml
177-
# Use Rspack (default - faster builds)
178181
assets_bundler: rspack
179-
180-
# Or use Webpack (classic, stable)
181-
assets_bundler: webpack
182182
```
183183

184-
### Performance Comparison
185-
186-
Measured bundler compile times for this project (client + server bundles):
184+
### Version Targets
187185

188-
| Build Type | Webpack | Rspack | Improvement |
189-
|------------|---------|--------|-------------|
190-
| Development | ~3.1s | ~1.0s | **~3x faster** |
191-
| Production (cold) | ~22s | ~10.7s | **~2x faster** |
186+
- `react_on_rails` gem: `16.4.0`
187+
- `react-on-rails` npm package: `16.4.0`
188+
- `shakapacker` gem/npm package: `9.7.0`
189+
- `@rspack/core` and `@rspack/cli`: `2.0.0-beta.7` (latest published v2 prerelease at the time of this update)
192190

193-
**Benefits of Rspack:**
194-
- 67% faster development builds (saves ~2.1s per incremental build)
195-
- 51% faster production builds (saves ~11s on cold builds)
196-
- Faster incremental rebuilds during development
197-
- Reduced CI build times
198-
- Drop-in replacement - same configuration files work for both bundlers
191+
### Why Rspack
199192

200-
_Note: These are actual bundler compile times. Total build times including package manager overhead may vary._
193+
- Faster dev/test/prod compile times
194+
- Better incremental rebuild performance for local development
195+
- One bundler path for browser bundles and SSR bundles
201196

202197
### Configuration Files
203198

204199
All bundler configuration is in `config/webpack/`:
205-
- `webpack.config.js` - Main entry point (auto-detects Webpack or Rspack)
200+
- `webpack.config.js` - Main Shakapacker entry point
206201
- `commonWebpackConfig.js` - Shared configuration
207202
- `clientWebpackConfig.js` - Client bundle settings
208203
- `serverWebpackConfig.js` - Server-side rendering bundle
209204
- `development.js`, `production.js`, `test.js` - Environment-specific settings
210205

211206
### Additional Resources
212-
- [Webpack Docs](https://webpack.js.org/)
213-
- [Webpack Cookbook](https://christianalfoni.github.io/react-webpack-cookbook/)
214-
- Good overview: [Pete Hunt's Webpack Howto](https://github.com/petehunt/webpack-howto)
207+
- [Shakapacker Documentation](https://github.com/shakacode/shakapacker)
208+
- [Rspack Documentation](https://rspack.dev/)
215209

216210
## Thruster HTTP/2 Proxy
217211

@@ -253,7 +247,7 @@ For detailed information, troubleshooting, and advanced configuration options, s
253247
This example project uses mainly Tailwind CSS for styling.
254248
Besides this, it also demonstrates Sass and CSS modules, particularly for some CSS transitions.
255249

256-
We're using Webpack to handle Sass assets so that we can use CSS modules. The best way to understand how we're handling assets is to close follow this example. We'll be working on more docs soon. If you'd like to give us a hand, that's a great way to learn about this!
250+
We're using Rspack to handle Sass assets so that we can use CSS modules. The best way to understand how we're handling assets is to closely follow this example. We'll be working on more docs soon. If you'd like to give us a hand, that's a great way to learn about this!
257251

258252
For example in [client/app/bundles/comments/components/CommentBox/CommentBox.jsx](client/app/bundles/comments/components/CommentBox/CommentBox.jsx), see how we use standard JavaScript import syntax to refer to class names that come from CSS modules:
259253

@@ -274,15 +268,15 @@ export default class CommentBox extends React.Component {
274268
```
275269

276270
### Fonts with SASS
277-
The tutorial makes use of a custom font OpenSans-Light. We're doing this to show how to add assets for the CSS processing. The font files are located under [client/app/assets/fonts](client/app/assets/fonts) and are loaded by both the Rails asset pipeline and the Webpack HMR server.
271+
The tutorial makes use of a custom font OpenSans-Light. We're doing this to show how to add assets for the CSS processing. The font files are located under [client/app/assets/fonts](client/app/assets/fonts) and are loaded by both the Rails asset pipeline and the Rspack HMR server.
278272

279273
## Process management during development
280274
```
281275
bundle exec foreman start -f <Procfile>
282276
```
283277

284-
1. [`Procfile.dev`](Procfile.dev): Starts the Webpack Dev Server and Rails with Hot Reloading.
285-
1. [`Procfile.static`](Procfile.dev-static): Starts the Rails server and generates static assets that are used for tests.
278+
1. [`Procfile.dev`](Procfile.dev): Starts the Rspack Dev Server and Rails with Hot Reloading.
279+
1. [`Procfile.dev-static`](Procfile.dev-static): Starts the Rails server and generates static assets that are used for tests.
286280

287281
## Contributors
288282
[The Shaka Code team!](http://www.shakacode.com/about/), led by [Justin Gordon](https://github.com/justin808/), along with with many others. See [contributors.md](docs/contributors.md)

0 commit comments

Comments
 (0)