You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Server-Side Rendering of React via the [react_on_rails gem](https://github.com/shakacode/react_on_rails)
6
6
* 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
30
30
31
31
For more information, see the [React on Rails Pro Docs](https://www.shakacode.com/react-on-rails-pro/).
32
32
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.
35
35
* Better performance client and server side.
36
36
37
37
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.
77
77
+[Technologies Involved](#technologies-involved)
78
78
+[Basic Demo Setup](#basic-demo-setup)
79
79
+[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)
81
81
+[Rails Integration](#rails-integration)
82
-
+[Webpack](#webpack)
82
+
+[Rspack](#rspack-with-shakapacker)
83
83
+[Configuration Files](#configuration-files)
84
84
+[Additional Resources](#additional-resources)
85
85
+[Thruster HTTP/2 Proxy](#thruster-http2-proxy)
@@ -95,13 +95,13 @@ You can see this tutorial live here: [http://reactrails.com/](http://reactrails.
95
95
96
96
## Demoed Functionality
97
97
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.
100
100
- 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!
101
101
- 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 devserver. 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/).
105
105
- Easily enable retrofitting such a JS framework into an existing Rails app. You don't need a brand new single page app!
106
106
- Example setting up Ruby and JavaScript linting in a real project, with corresponding CI rake tasks.
107
107
- Enabling the i18n functionality with [react-intl](https://github.com/yahoo/react-intl).
@@ -115,11 +115,11 @@ See package.json and Gemfile for versions
@@ -128,7 +128,7 @@ See package.json and Gemfile for versions
128
128
129
129
### Prerequisites
130
130
- 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
132
132
- Postgres v9.2 or above
133
133
- Redis. Check that you have Redis installed by running `which redis-server`. If missing and on MacOS, install with Homebrew (`brew install redis`)
134
134
-[Yarn](https://yarnpkg.com/).
@@ -148,8 +148,12 @@ See package.json and Gemfile for versions
148
148
- To start all development processes: `foreman start -f Procfile.dev`
149
149
- To start only all Rails development processes: `foreman start -f Procfile.hot`
150
150
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
+
151
155
## 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!**
@@ -164,54 +168,44 @@ See package.json and Gemfile for versions
164
168
165
169
+ Be sure to see [Integration Test Notes](./docs/integration-test-notes.md) for advice on running your integration tests.
166
170
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)`
168
172
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.
169
173
170
-
## Webpack and Rspack
174
+
## Rspack with Shakapacker
171
175
172
-
_Converted to use Shakapacker with support for both Webpack and Rspack bundlers_.
176
+
_This project is standardized on Rspack with Shakapacker._
173
177
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`:
175
179
176
180
```yaml
177
-
# Use Rspack (default - faster builds)
178
181
assets_bundler: rspack
179
-
180
-
# Or use Webpack (classic, stable)
181
-
assets_bundler: webpack
182
182
```
183
183
184
-
### Performance Comparison
185
-
186
-
Measured bundler compile times for this project (client + server bundles):
184
+
### Version Targets
187
185
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)
192
190
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
199
192
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
201
196
202
197
### Configuration Files
203
198
204
199
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
@@ -253,7 +247,7 @@ For detailed information, troubleshooting, and advanced configuration options, s
253
247
This example project uses mainly Tailwind CSS for styling.
254
248
Besides this, it also demonstrates Sass and CSS modules, particularly for some CSS transitions.
255
249
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!
257
251
258
252
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:
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.
278
272
279
273
## Process management during development
280
274
```
281
275
bundle exec foreman start -f <Procfile>
282
276
```
283
277
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.
286
280
287
281
## Contributors
288
282
[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