Skip to content

Commit 04ac7b1

Browse files
committed
React on Rails v9 on rails/webpacker v3
* See CHANGELOG.md for summary of changes * Change webpack-bundle to hello-world-bundle See https://github.com/shakacode/react-on-rails-v9-rc-generator/pulls for examples of new generator output. * Remove gen examples optimizations for spec Older optimizations were for times npm was super slow.
1 parent b36ac23 commit 04ac7b1

File tree

101 files changed

+1023
-1462
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+1023
-1462
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ node_package/webpack.config.js
1313
**/app/assets/javascripts/application.js
1414
**/coverage/**
1515
**/cable.js
16+
**/public/packs*/*

CHANGELOG.md

+146-16
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,143 @@ Changes since last non-beta release.
88

99
*Please add entries here for your pull requests.*
1010

11-
### [9.0.0.beta.1]
12-
- Switch over to using Webpacker
11+
- Fix regression where `react_component(... prerender: true)` wouldn't find the generated asset bundle, because it wasn't looking for the hashed path.
1312

14-
- If using the WebpackConfigLoader, you will need to rename the following object properties:
15-
- hotReloadingUrl devServerUrl
16-
- hotReloadingHostname devServerHost
17-
- hotReloadingPort devServerPort
1813

19-
- Find your webpacker_lite.yml and rename it to webpacker.yml
14+
## 9.0 from 8.x. Upgrade Instructions
15+
All 9.0.0 beta versions can be viewed in [PR 908](https://github.com/shakacode/react_on_rails/pull/908)
16+
17+
For an example of upgrading, see [react-webpack-rails-tutorial/pull/416](https://github.com/shakacode/react-webpack-rails-tutorial/pull/416).
18+
19+
- Breaking Configuration Changes
20+
1. Added `config.node_modules_location` which defaults to `""` if Webpacker is installed. You may want to set this to 'client'` to `config/initializers/react_on_rails.rb` to keep your node_modules inside of `/client`
21+
2. Renamed
22+
* config.npm_build_test_command ==> config.build_test_command
23+
* config.build_production_command ==> config.build_production_command
24+
25+
- Update the gemfile. Switch over to using the webpacker gem.
26+
27+
```rb
28+
gem "webpacker"
29+
```
30+
31+
- Update for the renaming in the `WebpackConfigLoader` in your webpack configuration.
32+
You will need to rename the following object properties:
33+
- webpackOutputPath ==> output.path
34+
- webpackPublicOutputDir ==> output.publicPath
35+
- hotReloadingUrl ==> output.publicPathWithHost
36+
- hotReloadingHostname ==> settings.dev_server.host
37+
- hotReloadingPort ==> settings.dev_server.port
38+
- hmr ==> settings.dev_server.hmr
39+
- manifest ==> Remove this one. We use the default for Webpack of manifest.json
40+
- env ==> Use `const { env } = require('process');`
41+
- devBuild ==> Use `const devBuild = process.env.NODE_ENV !== 'production';`
42+
43+
- Edit your Webpack.config files:
44+
- Change your Webpack output to be like:
45+
```
46+
const webpackConfigLoader = require('react-on-rails/webpackConfigLoader');
47+
const configPath = resolve('..', 'config');
48+
const { output, settings } = webpackConfigLoader(configPath);
49+
const hmr = settings.dev_server.hmr;
50+
const devBuild = process.env.NODE_ENV !== 'production';
51+
52+
output: {
53+
filename: isHMR ? '[name]-[hash].js' : '[name]-[chunkhash].js',
54+
chunkFilename: '[name]-[chunkhash].chunk.js',
55+
56+
publicPath: output.publicPath,
57+
path: output.path,
58+
},
59+
```
60+
- Change your ManifestPlugin definition to something like the following
61+
```
62+
new ManifestPlugin({
63+
publicPath: output.publicPath,
64+
writeToFileEmit: true
65+
}),
66+
67+
```
68+
69+
- Find your `webpacker_lite.yml` and rename it to `webpacker.yml`
70+
- Consider copying a default webpacker.yml setup such as https://github.com/shakacode/react-on-rails-v9-rc-generator/blob/master/config/webpacker.yml
71+
- If you are not using the webpacker webpacker setup, be sure to put in `compile: false` in the `default` section.
72+
- Alternately, if you are updating from webpacker_lite, you can manually change these:
73+
- Add a default setting
74+
```
75+
cache_manifest: false
76+
```
77+
- For production, set:
78+
```
79+
cache_manifest: true
80+
```
2081
- Add a section like this under your development env:
2182
```
2283
dev_server:
2384
host: localhost
24-
port: 8080
25-
https: false
26-
# Can be enabled by export WEBPACKER_HMR=TRUE in env
27-
hot: false
85+
port: 3035
86+
hmr: false
2887
```
29-
- remove `hot_reloading_host` and `hot_reloading_enabled_by_default`
30-
- rename `webpack_public_output_dir` to `public_output_path`
88+
Set hmr to your preference.
89+
- See the example `spec/dummy/config/webpacker.yml`.
90+
- Remove keys `hot_reloading_host` and `hot_reloading_enabled_by_default`. These are replaced by the `dev_server` key.
91+
- Rename `webpack_public_output_dir` to `public_output_path`.
92+
93+
- Edit your Procfile.dev
94+
- Remove the env value WEBPACKER_DEV_SERVER as it's not used
95+
- For hot loading:
96+
- Set the `hmr` key in your `webpacker.yml` to `true`.
97+
98+
99+
#### Troubleshooting
100+
101+
102+
103+
### [9.0.0]
104+
*Diffs for the beta to master*
105+
106+
### [9.0.0-beta.12]
107+
- Updated for latest rails/webpacker using the official gem
108+
- hot reloading working in generator
109+
110+
### [9.0.0-beta.11]
111+
- Updated for latest rails_webpacker.
112+
- hot reloading working in spec/dummy
113+
114+
### [9.0.0-beta.10]
115+
- Updated for the latest rails/webpacker. Added the cache_manifest setting.
116+
117+
### [9.0.0-beta.9]
118+
- Fixes precompile task going to Webpacker's. You need to set `custom_compile: true` in your `webpacker.yml`.
119+
- Changed webpack-bundle.js name to hello-world-bundle.js
120+
- Update for latest from rails/webpacker
121+
gem "webpacker", git: "https://github.com/shakacode/webpacker.git",
122+
branch: "issue-464-merge-webpacker-lite-into-webpacker-v3"
123+
124+
### [9.0.0-beta.8]
125+
- bugfix for server rendering
126+
127+
### [9.0.0-beta.7]
128+
- Depend on updated rails/webpacker in branch
129+
130+
gem "webpacker", git: "https://github.com/shakacode/webpacker.git",
131+
branch: "issue-464-merge-webpacker-lite-into-webpacker-v2"
132+
133+
134+
### [9.0.0-beta.6]
135+
- Change "hot" to "hmr".
136+
137+
### [9.0.0-beta.3]
138+
- Fix typo on webpackConfigLoader.js
139+
140+
### [9.0.0-beta.3]
141+
- Fix typo on webpackConfigLoader.js
142+
143+
### [9.0.0-beta.2]
144+
- Fixed problems when running in development mode for both the generator and spec/dummy.
145+
146+
### [9.0.0-beta.1]
147+
- First version of depending on Webpacker rather than Webpacker Lite
31148
32149
### [8.0.7]
33150
#### fixed
@@ -333,7 +450,7 @@ No changes.
333450
- See [shakacode/react-webpack-rails-tutorial/pull/287](https://github.com/shakacode/react-webpack-rails-tutorial/pull/287) for an example of upgrading from v5.
334451
335452
- To configure the asset compliation you can either
336-
1. Specify a `config/react_on_rails` setting for `npm_build_production_command` to be nil to turn this feature off.
453+
1. Specify a `config/react_on_rails` setting for `build_production_command` to be nil to turn this feature off.
337454
2. Specify the script command you want to run to build your production assets, and remove your assets.rake file.
338455
339456
- If you are using the ReactOnRails test helper, then you will need to add the 'config.npm_build_test_command' to your config to tell react_on_rails what command to run when you run rspec.
@@ -344,7 +461,7 @@ Here is the addition to the generated config file:
344461
```ruby
345462
# This configures the script to run to build the production assets by webpack. Set this to nil
346463
# if you don't want react_on_rails building this file for you.
347-
config.npm_build_production_command = "npm run build:production"
464+
config.build_production_command = "npm run build:production"
348465
349466
# If you are using the ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
350467
# with rspec then this controls what npm command is run
@@ -651,7 +768,20 @@ Best done with Object destructing:
651768
##### Fixed
652769
- Fix several generator related issues.
653770

654-
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/8.0.7...master
771+
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/rails-webpacker...9.0.0-beta.11
772+
[9.0.0]: https://github.com/shakacode/react_on_rails/compare/master...9.0.0-beta.11
773+
[9.0.0-beta.12]: https://github.com/shakacode/react_on_rails/compare/9.0.0-beta.11...9.0.0-beta.12
774+
[9.0.0-beta.11]: https://github.com/shakacode/react_on_rails/compare/9.0.0-beta.10...9.0.0-beta.11
775+
[9.0.0-beta.10]: https://github.com/shakacode/react_on_rails/compare/9.0.0-beta.9...9.0.0-beta.10
776+
[9.0.0-beta.9]: https://github.com/shakacode/react_on_rails/compare/9.0.0-beta.8...9.0.0-beta.9
777+
[9.0.0-beta.8]: https://github.com/shakacode/react_on_rails/compare/9.0.0-beta.7...9.0.0-beta.8
778+
[9.0.0-beta.7]: https://github.com/shakacode/react_on_rails/compare/9.0.0-beta.6...9.0.0-beta.7
779+
[9.0.0-beta.6]: https://github.com/shakacode/react_on_rails/compare/9.0.0-beta.5...9.0.0-beta.6
780+
[9.0.0-beta.5]: https://github.com/shakacode/react_on_rails/compare/9.0.0-beta.4...9.0.0-beta.5
781+
[9.0.0-beta.4]: https://github.com/shakacode/react_on_rails/compare/9.0.0-beta.3...9.0.0-beta.4
782+
[9.0.0-beta.3]: https://github.com/shakacode/react_on_rails/compare/9.0.0-beta.2...9.0.0-beta.3
783+
[9.0.0-beta.2]: https://github.com/shakacode/react_on_rails/compare/9.0.0-beta.1...9.0.0-beta.2
784+
[9.0.0-beta.1]: https://github.com/shakacode/react_on_rails/compare/master...9.0.0-beta.1
655785
[8.0.7]: https://github.com/shakacode/react_on_rails/compare/8.0.6...8.0.7
656786
[8.0.6]: https://github.com/shakacode/react_on_rails/compare/8.0.5...8.0.6
657787
[8.0.5]: https://github.com/shakacode/react_on_rails/compare/8.0.3...8.0.5

CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ When making doc changes, we want the change to work on both the gitbook and the
4646

4747
```sh
4848
cd react_on_rails/
49-
bundle && yarn && rake examples:prepare_all && rake node_package && rake
49+
bundle && yarn && rake examples:gen_all && rake node_package && rake
5050
```
5151

5252
In order to run tests in browser
@@ -145,7 +145,7 @@ yarn run install-react-on-rails
145145
```
146146
_Note: this runs npm under the hood as explained in **Test NPM for react-on-rails** section above_
147147

148-
From now on, the example and dummy apps will use your local node_package folder as the react-on-rails node package. This will also be done automatically for you via the `rake examples:prepare_all` rake task.
148+
From now on, the example and dummy apps will use your local node_package folder as the react-on-rails node package. This will also be done automatically for you via the `rake examples:gen_all` rake task.
149149

150150
*Side note: It's critical to use the alias section of the webpack config to avoid a double inclusion error. This has already been done for you in the example and dummy apps, but for reference:*
151151

Gemfile

+5-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ gem "chromedriver-helper"
3838
gem "launchy"
3939
gem "poltergeist"
4040
gem "selenium-webdriver"
41-
gem "webpacker", git: "https://github.com/shakacode/webpacker.git",
42-
branch: "issue-464-merge-webpacker-lite-into-webpacker"
41+
gem "webpacker", "~> 3.0"
4342

43+
# TODO: remove once we get out of beta.
44+
# gem 'webpacker', path: "../../forks/webpacker"
45+
46+
gem "equivalent-xml", github: "mbklein/equivalent-xml"
4447
gem "rainbow"

README.md

+20-13
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ Turn on HMR (Hot reloading)
2424

2525
---------------
2626

27-
2827
## Thank you from Justin Gordon and [ShakaCode](http://www.shakacode.com)
2928

3029
Thank you for considering using [React on Rails](https://github.com/shakacode/react_on_rails).
@@ -166,10 +165,18 @@ To upgrade existing apps to React on Rails 8 see the [Installation Overview](doc
166165
1. Add the following to your Gemfile and `bundle install`. We recommend fixing the version of React on Rails, as you will need to keep the exact version in sync with the version in your `client/package.json` file.
167166

168167
```ruby
169-
gem "react_on_rails", "8.0.0"
168+
gem "react_on_rails", "9.0.0"
169+
gem "webpacker", "~> 3.0"
170170
```
171171

172-
2. Commit this to git (you cannot run the generator unless you do this or pass the option `--ignore-warnings`).
172+
2. Run the following 2 commands to install Webpacker with React:
173+
```
174+
bundle exec rails webpacker:install
175+
bundle exec rails webpacker:install:react
176+
177+
```
178+
179+
2. Commit this to git (or else you cannot run the generator unless you pass the option `--ignore-warnings`).
173180

174181
3. See help for the generator:
175182

@@ -183,13 +190,7 @@ To upgrade existing apps to React on Rails 8 see the [Installation Overview](doc
183190
rails generate react_on_rails:install
184191
```
185192

186-
5. Bundle and NPM install. Make sure you are on a recent version of node. Please use at least Node v5. Bundle is for adding execJs. You can remove that if you are sure you will not server render.
187-
188-
```bash
189-
bundle && yarn
190-
```
191-
192-
6. Ensure that you have `foreman` installed: `gem install foreman`.
193+
5. Ensure that you have `foreman` installed: `gem install foreman`.
193194

194195
7. Start your Rails server:
195196

@@ -259,6 +260,11 @@ cd client && yarn add react-on-rails
259260
260261
That will install the latest version and update your package.json.
261262
263+
## Webpacker Configuration
264+
265+
React on Rails users should set configuration value `compile` to false, as React on Rails handles compilation for test and production environments.
266+
267+
262268
## How it Works
263269
The generator installs your webpack files in the `client` folder. Foreman uses webpack to compile your code and output the bundled results to `app/assets/webpack`, which are then loaded by sprockets. These generated bundle files have been added to your `.gitignore` for your convenience.
264270
@@ -423,12 +429,12 @@ end
423429
In this case, a prop and value for `somethingUseful` will go into the railsContext passed to all react_component and redux_store calls. You may set any values available in the view rendering context.
424430

425431
### Globally Exposing Your React Components
426-
Place your JavaScript code inside of the provided `client/app` folder. Use modules just as you would when using webpack alone. The difference here is that instead of mounting React components directly to an element using `React.render`, you **register your components to ReactOnRails and then mount them with helpers inside of your Rails views**.
432+
Place your JavaScript code inside of the default `app/javascript` folder. Use modules just as you would when using webpack alone. The difference here is that instead of mounting React components directly to an element using `React.render`, you **register your components to ReactOnRails and then mount them with helpers inside of your Rails views**.
427433

428434
This is how to expose a component to the `react_component` view helper.
429435

430436
```javascript
431-
// client/app/bundles/HelloWorld/startup/HelloWorld.jsx
437+
// app/javascript/packs/hello-world-bundle.js
432438
import HelloWorld from '../components/HelloWorld';
433439
import ReactOnRails from 'react-on-rails';
434440
ReactOnRails.register({ HelloWorld });
@@ -591,7 +597,7 @@ If you are using [jquery-ujs](https://github.com/rails/jquery-ujs) for AJAX call
591597
## Deployment
592598
* Version 6.0 puts the necessary precompile steps automatically in the rake precompile step. You can, however, disable this by setting certain values to nil in the [config/initializers/react_on_rails.rb](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/config/initializers/react_on_rails.rb).
593599
* `config.symlink_non_digested_assets_regex`: Set to nil to turn off the setup of non-js assets.
594-
* `npm_build_production_command`: Set to nil to turn off the precompilation of the js assets.
600+
* `build_production_command`: Set to nil to turn off the precompilation of the js assets.
595601
* See the [Heroku Deployment](./docs/additional-reading/heroku-deployment.md) doc for specifics regarding Heroku. The information here should apply to other deployments.
596602

597603
## Integration with Node.js for Server Rendering
@@ -628,6 +634,7 @@ If you want to use a node server for server rendering, [get in touch](mailto:jus
628634
+ **Development**
629635
+ [React on Rails Basic Installation Tutorial](./docs/tutorial.md) ([live demo](https://hello-react-on-rails.herokuapp.com))
630636
+ [Installation Overview](./docs/basics/installation-overview.md)
637+
+ [Configuration](./docs/basics/configuration.md)
631638
+ [Migration from react-rails](./docs/basics/migrating-from-react-rails.md)
632639
+ [Recommended Project Structure](./docs/additional-reading/recommended-project-structure.md)
633640
+ [Generator Tips](./docs/basics/generator.md)

Rakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Rake will automatically load any *.rake files inside of the "rakelib" folder
44
# See rakelib/
55
tasks = %w[run_rspec lint]
6-
prepare_for_ci = %w[node_package dummy_apps examples]
6+
prepare_for_ci = %w[node_package dummy_apps]
77

88
if ENV["USE_COVERALLS"] == "TRUE"
99
require "coveralls/rake/task"
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Asset Pipeline
2+
3+
The plumbing of webpack produced assets through the asset pipeline is deprecated as of v9.0.
4+
5+
The information in this document is here for those that have not yet upgraded.
6+
7+
8+
9+
10+
This option still works for your `/config/initializers/react_on_rails.rb` if you are still using the
11+
asset pipeline.
12+
```
13+
################################################################################
14+
# MISCELLANEOUS OPTIONS
15+
################################################################################
16+
# If you want to use webpack for CSS and images, and still use the asset pipeline,
17+
# see https://github.com/shakacode/react_on_rails/blob/master/docs/additional-reading/rails-assets.md
18+
# And you will use a setting like this.
19+
config.symlink_non_digested_assets_regex = /\.(png|jpg|jpeg|gif|tiff|woff|ttf|eot|svg|map)/
20+
```

0 commit comments

Comments
 (0)