react_on_rails 12.0.0.pre.beta.1 → 12.0.0.pre.beta.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f53b8097c4c41fa99e2e91a3aca2b875725a657fc93092624fd3e6d4f022164f
4
- data.tar.gz: 85d6d6da3bba2c596b80e2fac4b260be0ee300a0acf9db4e9f14144cbf35f1a7
3
+ metadata.gz: 36f887cf3c39cbfcc07631658436609bc247785e98348aa8017cd188dbc6e4ba
4
+ data.tar.gz: 359d97d280a4c6019fd954dd5d2e7f183388b4056a038703550ac08e5725ef06
5
5
  SHA512:
6
- metadata.gz: 6b3b2081577a1f5adee8c818b2bbe9cb10f3f321ba0b2eec5477040af9033bd784f662f6639365f0b197185c7d5d93d58c1f5274c0094bb1998484011d4e3b1a
7
- data.tar.gz: '01965e573de93892c992bb8045615ce792dd41ffae7198a0841eab3bb356d144aa0e8b7265d648c8053e551b2e0d6c80ff08c830d3f95425828e5540d93befcd'
6
+ metadata.gz: 847d326b4b3e529d987b2143a5aeeb6293d4b70f52681368129acddcc87275bd81315b541b0e0b0e76390d3854e5bb0294b21acc2ef92f74b68595c55b00bf2b
7
+ data.tar.gz: 9e0ce34d90525c0e1bfb7794e9381439632b4f93925642ce0e46d1c2ffefe6a3520dea2f3a442c305fd6289836152477fe24fe6bfb21c7bb1208b413981e0a12
@@ -4,7 +4,7 @@ All notable changes to this project's source code will be documented in this fil
4
4
  Migration instructions for the major updates can be found [here](docs/basics/upgrading-react-on-rails.md#upgrading-to-version-9.md). Some smaller migration information can be found here.
5
5
 
6
6
  ## Need Help Migrating?
7
- If you would like help in migrating between React on Rails versions or help with implementing server rendering, please contact [justin@shakacode.com](mailto:justin@shakacode.com) for information about our [ShakaCode Pro Support](https://www.shakacode.com/work/shakacode-pro-support.pdf).
7
+ If you would like help in migrating between React on Rails versions or help with implementing server rendering, please contact [justin@shakacode.com](mailto:justin@shakacode.com) for information about our [React on Rails Pro Support Options](https://www.shakacode.com/react-on-rails-pro).
8
8
 
9
9
  We specialize in helping companies to quickly and efficiently move from versions before 9 to current. The older versions use the Rails asset pipeline to package client assets. The current and recommended way is to use Webpack 4 for asset preparation. You may also need help migrating from the `rails/webpacker`'s Webpack configuration to a better setup ready for Server Side Rendering.
10
10
 
@@ -19,9 +19,11 @@ Changes since last non-beta release.
19
19
  ## UPCOMING 12.0 RELEASE
20
20
 
21
21
  #### Improved
22
- * Generator supports React Hooks
23
-
22
+ ### [12.0.0.pre.beta.2]
23
+ * Changed the precompile task to use the rails/webpacker one by default
24
24
 
25
+ ### [12.0.0.pre.beta.1]
26
+ * Updated generators to use React hooks
25
27
 
26
28
  ### [12.0.0.pre.beta.0]
27
29
  Gem version: 12.0.0.pre.beta.0 and npm version 12.0.0-beta.0 released! Please try this out!
@@ -34,10 +36,13 @@ set JavaScript property `renderFunction` on the function for which you want to r
34
36
  invoked to return the React component. In that case, you won't need to pass any unused params.
35
37
  [PR 1268](https://github.com/shakacode/react_on_rails/pull/1268) by [justin808](https://github.com/justin808)
36
38
 
37
- See [docs/basics/upgrading-react-on-rails](./docs/basics/upgrading-react-on-rails#upgrading-to-v12)
39
+ See [docs/basics/upgrading-react-on-rails](./docs/basics/upgrading-react-on-rails.md#upgrading-to-v12)
38
40
  for details.
39
41
 
40
42
  * Requires the use of rails/webpacker helpers
43
+ * If the webpacker webpack config files exist, then React on Rails will not override the default
44
+ assets:precompile setup by rails/webpacker. The fix is to remove the JS files inside of config/webpack,
45
+ like config/webpack/production.js.
41
46
  * Removed **env_javascript_include_tag** and **env_stylesheet_link_tag** as these are replaced by view helpers
42
47
  from rails/webpacker
43
48
  * Removal of support for old Rubies and Rails.
@@ -921,7 +926,8 @@ Best done with Object destructing:
921
926
  ##### Fixed
922
927
  - Fix several generator related issues.
923
928
 
924
- [Unreleased]: https://github.com/shakacode/react_on_rails/compare/12.0.0-beta.0...master
929
+ [Unreleased]: https://github.com/shakacode/react_on_rails/compare/12.0.0-beta.1...master
930
+ [12.0.0.pre.beta.1]: https://github.com/shakacode/react_on_rails/compare/12.0.0-beta.0...12.0.0-beta.1
925
931
  [12.0.0.pre.beta.0]: https://github.com/shakacode/react_on_rails/compare/11.3.0...12.0.0-beta.0
926
932
  [11.3.0]: https://github.com/shakacode/react_on_rails/compare/11.2.2...11.3.0
927
933
  [11.2.2]: https://github.com/shakacode/react_on_rails/compare/11.2.1...11.2.2
@@ -61,8 +61,11 @@ ReactOnRails.configure do |config|
61
61
  #
62
62
  config.node_modules_location = "client" # If using webpacker you should use "".
63
63
 
64
- # This configures the script to run to build the production assets by webpack. Set this to nil
64
+ # This configures the script to run to build the production assets by webpack . Set this to nil
65
65
  # if you don't want react_on_rails building this file for you.
66
+ # Note, if you want to use this command then you should remove the file
67
+ # config/webpack/production.js
68
+ # If that file exists, React on Rails thinks that you'll use the rails/webpacker bin/webpack compiler.
66
69
  config.build_production_command = "RAILS_ENV=production bin/webpack"
67
70
 
68
71
  ################################################################################
@@ -89,7 +92,9 @@ ReactOnRails.configure do |config|
89
92
  # Normally, you have different bundles for client and server, thus, the default is false.
90
93
  # Furthermore, if you are not hashing the server bundle (not in the manifest.json), then React on Rails
91
94
  # will only look for the server bundle to be created in the typical file location, typically by
92
- # a `webpack --watch` process.
95
+ # a `webpack --watch` process.
96
+ # If true, ensure that in config/webpacker.yml that you have both dev_server.hmr and
97
+ # dev_server.inline set to false.
93
98
  config.same_bundle_for_client_and_server = false
94
99
 
95
100
  # If set to true, this forces Rails to reload the server bundle if it is modified
@@ -134,6 +139,7 @@ ReactOnRails.configure do |config|
134
139
  # Replace the following line to the location where you keep translation.js & default.js for use
135
140
  # by the npm packages react-intl. Be sure this directory exists!
136
141
  # config.i18n_dir = Rails.root.join("client", "app", "libs", "i18n")
142
+ #
137
143
  # If not using the i18n feature, then leave this section commented out or set the value
138
144
  # of config.i18n_dir to nil.
139
145
  #
@@ -141,11 +147,11 @@ ReactOnRails.configure do |config|
141
147
  # that will source for automatic generation on translations.js & default.js
142
148
  # By default(without this option) all yaml files from Rails.root.join("config", "locales")
143
149
  # and installed gems are loaded
144
- config.i18n_yml_dir = Rails.root.join("config", "locales", "client")
150
+ config.i18n_yml_dir = Rails.root.join("config", "locales")
145
151
 
146
152
  # Possible output formats are js and json
147
153
  # The default format is json
148
- config.i18n_output_format = 'js'
154
+ config.i18n_output_format = 'json'
149
155
 
150
156
  ################################################################################
151
157
  ################################################################################
@@ -186,7 +192,7 @@ ReactOnRails.configure do |config|
186
192
  # CONFIGURE YOUR SOURCE FILES
187
193
  # The test helper needs to know where your JavaScript files exist. The value is configured
188
194
  # by your config/webpacker.yml source_path:
189
- # source_path: client/app/javascript # if using recommended /client directory
195
+ # source_path: client/app # if using recommended /client directory
190
196
  #
191
197
  # Define the files we need to check for webpack compilation when running tests.
192
198
  # The default is `%w( manifest.json )` as will be sufficient for most webpacker builds.
@@ -0,0 +1,49 @@
1
+ # HMR and Hot Reloading with the webpack-dev-server
2
+
3
+ The webpack-dev-server provides:
4
+
5
+ 1. Speedy compilation of client side assets
6
+ 2. Optional HMR which means that the page will reload automatically when after
7
+ compilation completes. Note, some developers do not like this, as you'll
8
+ abruptly lose any tweaks within the Chrome development tools.
9
+ 3. Optional hot-reloading. The older react-hot-loader has been deprecated in
10
+ favor of [fast-refresh](https://reactnative.dev/docs/fast-refresh).
11
+ For use with webpack, see [react-refresh-webpack-plugin](https://github.com/pmmmwh/react-refresh-webpack-plugin).
12
+
13
+ If you are ***not*** using server-side rendering (***not*** using `prerender: true`),
14
+ then you can follow all the regular docs for using the `bin/webpack-dev-server`
15
+ during development.
16
+
17
+
18
+ # Server Side Rendering with the Default rails/webpacker bin/webpack-dev-server
19
+
20
+ If you are using server-side rendering, then you have a couple options. The
21
+ recommended technique is to have a different webpack configuration for server
22
+ rendering.
23
+
24
+
25
+
26
+
27
+ ## If you use the same Webpack setup for your server and client bundles
28
+ If you do use the webpack-dev-server for prerendering, be sure to set the
29
+ `config/initializers/react_on_rails.rb` setting of
30
+
31
+ ```
32
+ config.same_bundle_for_client_and_server = true
33
+ ```
34
+
35
+ `dev_server.hmr` maps to [devServer.hot](https://webpack.js.org/configuration/dev-server/#devserverhot).
36
+ This must be false if you're using the webpack-dev-server for client and server bundles.
37
+
38
+ `dev_server.inline` maps to [devServer.inline](https://webpack.js.org/configuration/dev-server/#devserverinline).
39
+ This must also be false.
40
+
41
+ If you don't configure these two to false, you'll see errors like:
42
+
43
+ * "ReferenceError: window is not defined" (if hmr is true)
44
+ * "TypeError: Cannot read property 'prototype' of undefined" (if inline is true)
45
+
46
+
47
+
48
+
49
+
@@ -1,9 +1,32 @@
1
1
  # RSpec Configuration
2
2
  _Click [here for minitest](./minitest-configuration.md)_
3
3
 
4
+ # If your webpack configurations correspond to rails/webpacker's default setup
5
+ If you're able to configure your webpack configuration to be run by having your webpack configuration
6
+ returned by the files in `/config/webpack`, then you have 2 options to ensure that your files are
7
+ compiled by webpack before running tests and during production deployment:
8
+
9
+ 1. **Use rails/webpacker's compile option**: Configure your `config/webpacker.yml` so that `compile: true` is for `test` and `production`
10
+ environments. Ensure that your `source_path` is correct, or else `rails/webpacker` won't correctly
11
+ detect changes.
12
+ 2. **Use the react_on_rails settings and helpers**. Use the settings in `config/initializers/react_on_rails.rb`. Refer to [docs/configuration](./configuration.md).
13
+
14
+ ```yml
15
+ config.build_production_command = "RAILS_ENV=production bin/webpack"
16
+ config.build_test_command = "RAILS_ENV=test bin/webpack"
17
+ ```
18
+
19
+ Which should you use? If you're already using the `rails/webpacker` way to configure webpack, then
20
+ you can keep things simple and use the `rails/webpacker` options.
21
+
22
+ # Checking for stale assets using React on Rails
23
+
4
24
  Because you will probably want to run RSpec tests that rely on compiled webpack assets (typically, your integration/feature specs where `js: true`), you will want to ensure you don't accidentally run tests on missing or stale webpack assets. If you did use stale Webpack assets, you will get invalid test results as your tests do not use the very latest JavaScript code.
5
25
 
6
- ReactOnRails provides a helper method called `ReactOnRails::TestHelper.configure_rspec_to_compile_assets`. Call this method from inside of the `RSpec.configure` block in your `spec/rails_helper.rb` file, passing the config as an argument. See file [lib/react_on_rails/test_helper.rb](../../lib/react_on_rails/test_helper.rb) for more details. You can customize this to your particular needs by replacing any of the default components used by `ReactOnRails::TestHelper.configure_rspec_to_compile_assets`.
26
+ As mentioned above, you can configure `compile: true` in `config/webpacker.yml` _if_ you've got configuration for
27
+ your webpack in the standard `rails/webpacker` spot of `config/webpack/<NODE_ENV>.js`
28
+
29
+ ReactOnRails also provides a helper method called `ReactOnRails::TestHelper.configure_rspec_to_compile_assets`. Call this method from inside of the `RSpec.configure` block in your `spec/rails_helper.rb` file, passing the config as an argument. See file [lib/react_on_rails/test_helper.rb](../../lib/react_on_rails/test_helper.rb) for more details. You can customize this to your particular needs by replacing any of the default components used by `ReactOnRails::TestHelper.configure_rspec_to_compile_assets`.
7
30
 
8
31
  ```ruby
9
32
  RSpec.configure do |config|
@@ -26,36 +49,25 @@ Please take note of the following:
26
49
 
27
50
  - This utility uses your `build_test_command` to build the static generated files. This command **must not** include the `--watch` option. If you have different server and client bundle files, this command **must** create all the bundles. If you are using webpacker, the default value will come from the `config/webpacker.yml` value for the `public_output_path` and the `source_path`
28
51
 
29
- - If you add an older file to your source files, that is already older than the produced output files, no new recompilation is done. The solution to this issue is to clear out your directory of webpack generated files when adding new source files that may have older dates. This is actually a common occurrence when you've built your test generated files and then you sync up your repository files.
52
+ - If you add an older file to your source files, that is already older than the produced output files, no new recompilation is done. The solution to this issue is to clear out your directory of webpack generated files when adding new source files that may have older dates. This can happen when you've built your test generated files and then you sync up your repository files.
30
53
 
31
- - By default, the webpack processes look for the `config.generated_assets_dir` folder for generated files, configured via setting `webpack_generated_files`, in the `config/react_on_rails.rb`. If the `config.generated_assets_dir` folder is missing, is empty, or contains files in the `config.webpack_generated_files` list with `mtime`s older than any of the files in your `client` folder, the helper will recompile your assets. You can override the location of these files inside of `config/initializers/react_on_rails.rb` by passing a filepath (relative to the root of the app) to the `generated_assets_dir` configuration option.
54
+ - By default, the webpack processes look in the webpack generated files folder, configured via the `config/webpacker.yml` config values of `public_root_path` and `public_output_path`. If the webpack generated files folder is missing, is empty, or contains files in the `config.webpack_generated_files` list with `mtime`s older than any of the files in your `client` folder, the helper will recompile your assets.
32
55
 
33
56
  The following `config/react_on_rails.rb` settings **must** match your setup:
34
57
  ```ruby
35
- # Directory where your generated assets go. All generated assets must go to the same directory.
36
- # Configure this in your webpack config files. This relative to your Rails root directory.
37
- # We recommend having different generated assets dirs per Rails env.
38
- config.generated_assets_dir = File.join(%w[public webpack], Rails.env)
39
-
40
58
  # Define the files we need to check for webpack compilation when running tests.
41
- # Generally, the manifest.json is good enough for this check if using webpacker
42
59
  config.webpack_generated_files = %w( manifest.json )
43
60
 
44
61
  # OR if you're not hashing the server-bundle.js, then you should include your server-bundle.js in the list.
45
62
  # config.webpack_generated_files = %w( server-bundle.js manifest.json )
46
63
 
47
- # OR if you're not using webpacker, your setup might look like.
48
- # config.webpack_generated_files = %w( client-bundle.js server-bundle.js )
49
-
50
64
  # If you are using the ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
51
65
  # with rspec then this controls what yarn command is run
52
66
  # to automatically refresh your webpack assets on every test run.
53
67
  config.build_test_command = "yarn run build:test"
54
68
  ```
55
69
 
56
- If you want to speed up the re-compiling process so you don't wait to run your tests to build the files, you can run your test compilation with the "watch" flags.
57
-
58
- [spec/dummy](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy) contains examples of how to set the proc files for this purpose.
70
+ If you want to speed up the re-compiling process so you don't wait to run your tests to build the files, you can run your test compilation with the "watch" flags. For example, `yarn run build:test --watch`
59
71
 
60
72
  ![2016-01-27_02-36-43](https://cloud.githubusercontent.com/assets/1118459/12611951/7c56d070-c4a4-11e5-8a80-9615f99960d9.png)
61
73
 
@@ -5,8 +5,14 @@ If you would like help in migrating between React on Rails versions or help with
5
5
 
6
6
  We specialize in helping companies to quickly and efficiently move from versions before 9 to current. The older versions use the Rails asset pipeline to package client assets. The current and recommended way is to use Webpack 4 for asset preparation. You may also need help migrating from the `rails/webpacker`'s Webpack configuration to a better setup ready for Server Side Rendering.
7
7
 
8
- ## Upgrading to v13
8
+ ## Upgrading to v12
9
9
  * Make sure that you are on a relatively more recent version of rails and webpacker.
10
+ * If the webpacker webpack config files exist, then React on Rails will not override the default
11
+ assets:precompile setup by rails/webpacker. The fix is to remove the JS files inside of config/webpack,
12
+ like config/webpack/production.js.
13
+ * If you're using the internalization helper, then set `config.i18n_output_format = 'js'`. You can
14
+ later update to the default JSON format as you will need to update your usage of that file.
15
+
10
16
  * Updated API for ReactOnRails.register.
11
17
 
12
18
  In order to solve the issues regarding React Hooks compatibility, the number of parameters
@@ -119,31 +119,13 @@ foreman start -f Procfile.dev-hmr
119
119
 
120
120
  Visit [http://localhost:3000/hello_world](http://localhost:3000/hello_world) and see your **React On Rails** app running!
121
121
 
122
- *Note, foreman may default to PORT 5000 unless you set the value of PORT in your environment or in the Procfile.*
123
-
124
122
  # HMR vs. React Hot Reloading
125
123
 
126
- First, check that the `hmr` option is `true` in your `config/webpacker.yml` file.
127
-
128
- The basic setup will have HMR working with the default webpacker setup. The basic HMR will cause
129
- a full page refresh each time you save a file. You also lose any state on your page during the refresh. Don't try to use HMR
130
-
131
- ### Custom IP & PORT setup (Cloud9 example)
132
-
133
- In case you are running some custom setup with different IP or PORT you should also edit Procfile.dev. For example to be able to run on free Cloud9 IDE we are putting IP 0.0.0.0 and PORT 8080. The default generated file `Procfile.dev` uses `-p 3000`.
134
-
135
- ``` Procfile.dev
136
- web: rails s -p 8080 -b 0.0.0.0
137
- ```
124
+ First, check that the `hmr` and the `inline` options are `true` in your `config/webpacker.yml` file.
138
125
 
139
- Then visit https://your-shared-addr.c9users.io:8080/hello_world
140
-
141
- ## RubyMine
142
-
143
- It's super important to exclude certain directories from RubyMine or else it will slow to a crawl as it tries to parse all the npm files.
144
-
145
- * Generated files, per the settings in your `config/webpacker.yml`, which default to `public/packs` and `public/packs-test`
146
- * `node_modules`
126
+ The basic setup will have HMR working with the default webpacker setup. The basic
127
+ [HMR](https://webpack.js.org/concepts/hot-module-replacement/), without a special
128
+ React setup, will cause a full page refresh each time you save a file.
147
129
 
148
130
  ## Deploying to Heroku
149
131
 
@@ -166,17 +148,16 @@ Set heroku to use multiple buildpacks:
166
148
 
167
149
  ### Swap out sqlite for postgres by doing the following:
168
150
 
169
- 1. Delete the line with `sqlite` and replace it with:
151
+ Run these two commands:
170
152
 
171
- ```ruby
172
- gem 'pg'
173
153
  ```
174
-
175
- 2. Run `bundle`
154
+ bundle remove sqlite3
155
+ bundle add pg
156
+ ```
176
157
 
177
158
  ![07](https://cloud.githubusercontent.com/assets/20628911/17465015/1f2f4042-5cf4-11e6-8287-2fb077550809.png)
178
159
 
179
- 3. Replace your `database.yml` file with this (assuming your app name is "ror").
160
+ ### Replace your `database.yml` file with this (assuming your app name is "ror").
180
161
 
181
162
  ```yml
182
163
  default: &default
@@ -204,7 +185,6 @@ production:
204
185
  Then you need to setup postgres so you can run locally:
205
186
 
206
187
  ```
207
- bundle
208
188
  rake db:setup
209
189
  rake db:migrate
210
190
  ```
@@ -228,7 +208,7 @@ Create `/Procfile`. This is what Heroku uses to start your app.
228
208
  web: bundle exec puma -C config/puma.rb
229
209
  ```
230
210
 
231
- Note, newer versions of Rails create this file automatically. However, the [docs on Heroku](https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#config) have something a bit different, so please make it conform to those docs. As of 2018-10-13, the docs looked like this:
211
+ Note, newer versions of Rails create this file automatically. However, the [docs on Heroku](https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#config) have something a bit different, so please make it conform to those docs. As of 2020-06-04, the docs looked like this:
232
212
 
233
213
  `config/puma.rb`
234
214
  ```rb
@@ -249,6 +229,15 @@ on_worker_boot do
249
229
  end
250
230
  ```
251
231
 
232
+ Next, update your `package.json` to specify the version of yarn and node. Add this section:
233
+
234
+ ```json
235
+ "engines": {
236
+ "node": "13.9.0",
237
+ "yarn": "1.22.4"
238
+ },
239
+ ```
240
+
252
241
  Then after all changes are done don't forget to commit them with git and finally you can push your app to Heroku!
253
242
 
254
243
  ```
@@ -339,6 +328,27 @@ So you get some basics from HMR with no code changes. If you want to go further,
339
328
 
340
329
  React on Rails will automatically handle disabling server rendering if there is only one bundle file created by the Webpack development server by rails/webpacker.
341
330
 
331
+
332
+ ### Custom IP & PORT setup (Cloud9 example)
333
+
334
+ In case you are running some custom setup with different IP or PORT you should also edit Procfile.dev. For example to be able to run on free Cloud9 IDE we are putting IP 0.0.0.0 and PORT 8080. The default generated file `Procfile.dev` uses `-p 3000`.
335
+
336
+ ``` Procfile.dev
337
+ web: rails s -p 8080 -b 0.0.0.0
338
+ ```
339
+
340
+ Then visit https://your-shared-addr.c9users.io:8080/hello_world
341
+
342
+ ## RubyMine
343
+
344
+ It's super important to exclude certain directories from RubyMine or else it will slow to a crawl as it tries to parse all the npm files.
345
+
346
+ * Generated files, per the settings in your `config/webpacker.yml`, which default to `public/packs` and `public/packs-test`
347
+ * `node_modules`
348
+
349
+
350
+
351
+
342
352
  ## Conclusion
343
353
 
344
354
  * Browse the docs either on the [gitbook](https://shakacode.gitbooks.io/react-on-rails/content/) or in the [docs directory on github](https://github.com/shakacode/react_on_rails/tree/master/docs)
@@ -1,18 +1,26 @@
1
+ # Procfile for development using HMR
2
+
1
3
  web: rails s -p 3000
2
4
 
3
5
  # Note, hot and live reloading don't work with the default generator setup on
4
6
  # top of the rails/webpacker Webpack config with server rendering.
5
7
  # If you have server rendering enabled (prerender is true), you either need to
6
- # a. Skip using the webpack-dev-server. bin/webpack --watch is typically
8
+ # a. Ensure that you have dev_server.hmr and dev_server.inline BOTH set to false,
9
+ # and you have this option in your config/initializers/react_on_rails.rb:
10
+ # config.same_bundle_for_client_and_server = true
11
+ # If you have either config/webpacker.yml option set to true, you'll see errors like
12
+ # "ReferenceError: window is not defined" (if hmr is true)
13
+ # "TypeError: Cannot read property 'prototype' of undefined" (if inline is true)
14
+ # b. Skip using the webpack-dev-server. bin/webpack --watch is typically
7
15
  fast enough.
8
- # b. See the React on Rails README for a link to documentation for how to setup
9
- # SSR with HMR and React hot loading
10
- # Otherwise, you will have an error. If you want HMR and Server Rendering, see
11
- # the example in the https://github.com/shakacode/react-webpack-rails-tutorial
12
- web: rails s -p 3000
16
+ # c. See the React on Rails README for a link to documentation for how to setup
17
+ # SSR with HMR and React hot loading using the webpack-dev-server only for the
18
+ # client bundles and a static file for the server bundle.
13
19
 
14
- # Run the hot reload server for client development
20
+ # Run the webpack-dev-server for client and maybe server files
15
21
  webpack-dev-server: bin/webpack-dev-server
16
22
 
17
- # Keep the JS fresh for server rendering. Remove if not server rendering
18
- rails-server-assets: SERVER_BUNDLE_ONLY=yes bin/webpack --watch
23
+ # Keep the JS fresh for server rendering. Remove if not server rendering.
24
+ # Especially if you have not configured generation of a server bundle without a hash.
25
+ # as that will conflict with the manifest created by the bin/webpack-dev-server
26
+ # rails-server-assets: SERVER_BUNDLE_ONLY=yes bin/webpack --watch
@@ -6,7 +6,8 @@
6
6
  ReactOnRails.configure do |config|
7
7
  # This configures the script to run to build the production assets by webpack. Set this to nil
8
8
  # if you don't want react_on_rails building this file for you.
9
- config.build_production_command = "RAILS_ENV=production NODE_ENV=production bin/webpack"
9
+ # If nil, then the standard rails/webpacker assets:precompile will run
10
+ # config.build_production_command = nil
10
11
 
11
12
  ################################################################################
12
13
  ################################################################################
@@ -4,6 +4,14 @@ require "erb"
4
4
 
5
5
  module ReactOnRails
6
6
  module Locales
7
+ def self.compile
8
+ if ReactOnRails.configuration.i18n_output_format&.downcase == "js"
9
+ ReactOnRails::Locales::ToJs.new
10
+ else
11
+ ReactOnRails::Locales::ToJson.new
12
+ end
13
+ end
14
+
7
15
  class Base
8
16
  def initialize
9
17
  return if i18n_dir.nil?
@@ -30,7 +30,7 @@ module ReactOnRails
30
30
  # Be sure we don't do this again.
31
31
  self.class.has_been_run = true
32
32
 
33
- ReactOnRails::Locales::ToJs.new
33
+ ReactOnRails::Locales.compile
34
34
 
35
35
  stale_gen_files = webpack_assets_status_checker.stale_generated_webpack_files
36
36
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReactOnRails
4
- VERSION = "12.0.0-beta.1"
4
+ VERSION = "12.0.0-beta.2"
5
5
  end
@@ -1,13 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Important: The default assets:precompile is modified ONLY if the rails/webpacker webpack config
4
+ # does not exist!
5
+
3
6
  require "active_support"
4
7
 
5
- if Rake::Task.task_defined?("assets:precompile")
6
- Rake::Task["assets:precompile"].enhance do
7
- Rake::Task["react_on_rails:assets:webpack"].invoke
8
+ ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
9
+ ENV["NODE_ENV"] ||= "development"
10
+ webpacker_webpack_config_abs_path = File.join(Rails.root, "config/webpack/#{ENV["NODE_ENV"]}.js")
11
+ webpack_config_path = Pathname.new(webpacker_webpack_config_abs_path).relative_path_from(Rails.root).to_s
12
+
13
+ unless File.exists?(webpacker_webpack_config_abs_path)
14
+ if Rake::Task.task_defined?("assets:precompile")
15
+ Rake::Task["assets:precompile"].enhance do
16
+ Rake::Task["react_on_rails:assets:webpack"].invoke
17
+ puts "Invoking task wepacker:clean from React on Rails"
18
+ Rake::Task["webpacker:clean"].invoke
19
+ end
20
+ else
21
+ Rake::Task.define_task("assets:precompile" => ["react_on_rails:assets:webpack"])
8
22
  end
9
- else
10
- Rake::Task.define_task("assets:precompile" => ["react_on_rails:assets:webpack"])
11
23
  end
12
24
 
13
25
  # Sprockets independent tasks
@@ -18,6 +30,9 @@ namespace :react_on_rails do
18
30
  Uses command defined with ReactOnRails.configuration.build_production_command
19
31
 
20
32
  sh "#{ReactOnRails::Utils.prepend_cd_node_modules_directory('<ReactOnRails.configuration.build_production_command>')}"
33
+
34
+ Note: This command is not automatically added to assets:precompile if the rails/webpacker
35
+ configuration file #{webpack_config_path} exists.
21
36
  DESC
22
37
  task webpack: :locale do
23
38
  if ReactOnRails.configuration.build_production_command.present?
@@ -12,10 +12,6 @@ namespace :react_on_rails do
12
12
  the "ReactOnRails.configuration.i18n_dir".
13
13
  DESC
14
14
  task locale: :environment do
15
- if ReactOnRails.configuration.i18n_output_format&.downcase == "js"
16
- ReactOnRails::Locales::ToJs.new
17
- else
18
- ReactOnRails::Locales::ToJson.new
19
- end
15
+ ReactOnRails::Locales.compile
20
16
  end
21
17
  end
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-on-rails",
3
- "version": "12.0.0-beta.1",
3
+ "version": "12.0.0-beta.2",
4
4
  "description": "react-on-rails JavaScript for react_on_rails Ruby gem",
5
5
  "main": "node_package/lib/ReactOnRails.js",
6
6
  "directories": {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 12.0.0.pre.beta.1
4
+ version: 12.0.0.pre.beta.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Gordon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-14 00:00:00.000000000 Z
11
+ date: 2020-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -359,6 +359,7 @@ files:
359
359
  - docs/basics/configuration.md
360
360
  - docs/basics/deployment.md
361
361
  - docs/basics/generator-details.md
362
+ - docs/basics/hmr-and-hot-reloading-with-the-webpack-dev-server.md
362
363
  - docs/basics/i18n.md
363
364
  - docs/basics/installation-into-an-existing-rails-app.md
364
365
  - docs/basics/migrating-from-react-rails.md