react_on_rails 12.6.0 → 13.0.0.beta.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +1 -0
  3. data/Gemfile.development_dependencies +2 -2
  4. data/README.md +1 -4
  5. data/docs/deployment/heroku-deployment.md +1 -1
  6. data/docs/guides/configuration.md +3 -3
  7. data/docs/guides/hmr-and-hot-reloading-with-the-webpack-dev-server.md +4 -4
  8. data/docs/guides/how-react-on-rails-works.md +1 -1
  9. data/docs/guides/rspec-configuration.md +1 -1
  10. data/docs/guides/tutorial.md +15 -19
  11. data/docs/guides/upgrading-react-on-rails.md +15 -0
  12. data/docs/guides/webpack-configuration.md +1 -1
  13. data/docs/javascript/converting-from-custom-webpack-config-to-rails-webpacker-config.md +2 -2
  14. data/lib/generators/react_on_rails/base_generator.rb +9 -8
  15. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +2 -2
  16. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-static +2 -2
  17. data/lib/generators/react_on_rails/templates/base/base/babel.config.js.tt +25 -8
  18. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +2 -2
  19. data/lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt +1 -1
  20. data/lib/generators/react_on_rails/templates/base/base/config/webpack/development.js.tt +1 -1
  21. data/lib/generators/react_on_rails/templates/base/base/config/webpack/serverWebpackConfig.js.tt +1 -1
  22. data/lib/generators/react_on_rails/templates/base/base/config/webpack/webpack.config.js.tt +15 -0
  23. data/lib/generators/react_on_rails/templates/base/base/config/webpacker.yml +2 -2
  24. data/lib/react_on_rails/configuration.rb +8 -44
  25. data/lib/react_on_rails/helper.rb +2 -2
  26. data/lib/react_on_rails/locales/base.rb +1 -3
  27. data/lib/react_on_rails/react_component/render_options.rb +1 -1
  28. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +5 -5
  29. data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +3 -3
  30. data/lib/react_on_rails/test_helper.rb +2 -2
  31. data/lib/react_on_rails/version.rb +1 -1
  32. data/lib/react_on_rails/webpacker_utils.rb +2 -7
  33. data/package.json +1 -1
  34. data/rakelib/example_type.rb +5 -2
  35. data/rakelib/examples.rake +2 -9
  36. data/rakelib/task_helpers.rb +0 -7
  37. data/react_on_rails.gemspec +0 -1
  38. metadata +5 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5490e90d68dc9b21393bc6640239432d50872526c092fb88d47aa2c70625bf53
4
- data.tar.gz: aa540a9735ca1f6e4ffc1609591ffd2882c73102775f335ee4465cecda4c113b
3
+ metadata.gz: cdfa729f75cfd337b3436fe6e310d7e6a7789455fcba1baa729a2288d98c646f
4
+ data.tar.gz: 54495ad6beed806991e973866a4ccd62fd7b41d3141cbaec2e71a07e13999563
5
5
  SHA512:
6
- metadata.gz: 9b1bb61ac6ce06aebb68769082403c20665ec89f27672e21a3a40d3f92fa11db7305b24470861f9028985e79c88fb43f4be76684f14eb02928e723030bf7ae23
7
- data.tar.gz: 45e79902586891bab920ab9e0588bc970bd4f72fd502bad16db63d3194b3650e66119bd0b4dd8892fb3884a8dec9d9d055229954eae9081e6f4d9b20b0d5519d
6
+ metadata.gz: d0610cfa82d1d1b60f09f1586fb966dcfa12daf8549762f09e74a1fc00df6e0c8374138950e5195db0bed8501f7d8f3a1f62d90a9a779e6b652a0ada08d19d4e
7
+ data.tar.gz: 9e87301d7790829e6fe2391a68cf8de6e5724777e11b955b112783c7cfec13820d5a0c28691c5f2851ec49c92ab20e886b8c2a7b4c3fe2cfcec727d662cc4490
data/.circleci/config.yml CHANGED
@@ -317,6 +317,7 @@ workflows:
317
317
  - build-dummy-app-webpack-test-bundles:
318
318
  requires:
319
319
  - install-dummy-app-node-packages
320
+ - install-dummy-app-ruby-gems
320
321
  - package-js-tests:
321
322
  requires:
322
323
  - install-package-node-packages
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- gem "webpacker", "6.0.0.rc.6"
3
+ gem "shakapacker", ">= 6.1.1"
4
4
  gem "bootsnap", require: false
5
5
  gem "rails", "~> 7.0"
6
6
  gem "sqlite3"
@@ -21,7 +21,7 @@ gem "sprockets", "~> 4.0"
21
21
 
22
22
  gem "amazing_print"
23
23
 
24
- gem "mini_racer", "~> 0.5"
24
+ gem "mini_racer", ">= 0.6.2"
25
25
 
26
26
  group :development, :test do
27
27
  gem "listen"
data/README.md CHANGED
@@ -14,13 +14,10 @@
14
14
  # News
15
15
  * ShakaCode now maintains the official successor to `rails/webpacker`, [`shakapacker`](https://github.com/shakacode/shakapacker).
16
16
  * Project is updated to support Rails 7!
17
- * **React and Webpack with Ruby on Rails**: The current version of https://github.com/rails/webpacker will soon ship. While it won't be the default for Rails 7, it is not "deprecated." The core webpack configuration has become slimmer, allowing easier extension. If you want to get started today, use the master branch of [shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh) with `gem "webpacker", "6.0.0.rc.6"` Any updates to get to v6 from this point forward should be simple.
18
-
19
- If you have time, please comment on Justin's final proposals for Webpacker v6: [webpacker/pulls/justin808](https://github.com/rails/webpacker/pulls/justin808).
20
17
 
21
18
  -----
22
19
 
23
- *These are the docs for React on Rails 12. To see the version 11 docs, [click here](https://github.com/shakacode/react_on_rails/tree/11.3.0).*
20
+ *These are the docs for React on Rails 13. To see the older docs: [v12](https://github.com/shakacode/react_on_rails/tree/12.6.0) and [v11](https://github.com/shakacode/react_on_rails/tree/11.3.0).*
24
21
 
25
22
  #### About
26
23
  React on Rails integrates Rails with (server rendering of) Facebook's [React](https://github.com/facebook/react) front-end framework.
@@ -22,7 +22,7 @@ Alternatively, you can specify `config.build_production_command` to have
22
22
  react_on_rails invoke a command for you during assets:precompile.
23
23
 
24
24
  ```
25
- config.build_production_command = "RAILS_ENV=production bin/webpack"
25
+ config.build_production_command = "RAILS_ENV=production NODE_ENV=production bin/webpacker"
26
26
  ```
27
27
 
28
28
  ### Consider Removing Webpacker's clean task
@@ -72,7 +72,7 @@ ReactOnRails.configure do |config|
72
72
  # to have react_on_rails invoke a command for you during assets:precompile.
73
73
  # The command is either a script or a module containing a class method `call`
74
74
  # In this example, the module BuildProductionCommand would have a class method `call`.
75
- config.build_production_command = "RAILS_ENV=production bin/webpack"
75
+ config.build_production_command = "RAILS_ENV=production bin/webpacker"
76
76
 
77
77
  # See bottom for an example of the BuildProductionCommand module.
78
78
  # config.build_production_command = BuildProductionCommand
@@ -203,7 +203,7 @@ ReactOnRails.configure do |config|
203
203
  # with rspec then this controls what yarn command is run
204
204
  # to automatically refresh your webpack assets on every test run.
205
205
  #
206
- config.build_test_command = "RAILS_ENV=test bin/webpack"
206
+ config.build_test_command = "RAILS_ENV=test bin/webpacker"
207
207
 
208
208
  # CONFIGURE YOUR SOURCE FILES
209
209
  # The test helper needs to know where your JavaScript files exist. The value is configured
@@ -238,7 +238,7 @@ module BuildProductionCommand
238
238
  include FileUtils
239
239
  # The call method will be called during assets:precompile
240
240
  def self.call
241
- sh "bin/webpack"
241
+ sh "bin/webpacker"
242
242
  end
243
243
  end
244
244
  ```
@@ -11,10 +11,10 @@ The webpack-dev-server provides:
11
11
  For use with webpack, see **Client Side rendering and HMR using react-refresh-webpack-plugin** section bellow or visit [react-refresh-webpack-plugin](https://github.com/pmmmwh/react-refresh-webpack-plugin) for additional details.
12
12
 
13
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`
14
+ then you can follow all the regular docs for using the `bin/webpacker-dev-server`
15
15
  during development.
16
16
 
17
- # Server Side Rendering with the Default rails/webpacker bin/webpack-dev-server
17
+ # Server Side Rendering with the Default rails/webpacker bin/webpacker-dev-server
18
18
 
19
19
  If you are using server-side rendering, then you have a couple options. The
20
20
  recommended technique is to have a different webpack configuration for server
@@ -41,7 +41,7 @@ If you don't configure these two to false, you'll see errors like:
41
41
 
42
42
  # Client Side rendering with HMR using react-refresh-webpack-plugin
43
43
  ## Basic installation
44
- To enable HMR functionality you have to use `./bin/webpack-dev-server`
44
+ To enable HMR functionality you have to use `./bin/webpacker-dev-server`
45
45
  1. In `config/webpacker.yml` set **hmr** and **inline** `dev_server` properties to true.
46
46
  ```
47
47
  dev_server:
@@ -59,7 +59,7 @@ To enable HMR functionality you have to use `./bin/webpack-dev-server`
59
59
 
60
60
  3. HMR is for use with the webpack-dev-server, so we only add this for the webpack-dev-server.
61
61
  ```
62
- const { devServer } = require('@rails/webpacker')
62
+ const { devServer } = require('shakapacker')
63
63
 
64
64
  const isWebpackDevServer = process.env.WEBPACK_DEV_SERVER
65
65
 
@@ -32,7 +32,7 @@ Each time you change your client code, you will need to re-generate the bundles
32
32
 
33
33
  For example, you might create a [Procfile.dev](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/Procfile.dev).
34
34
 
35
- On production deployments that use asset precompilation, such as Heroku deployments, `rails/webpacker`, by default, will automatically run webpack to build your JavaScript bundles, running the command `bin/webpack` in your app.
35
+ On production deployments that use asset precompilation, such as Heroku deployments, `rails/webpacker`, by default, will automatically run webpack to build your JavaScript bundles, running the command `bin/webpacker` in your app.
36
36
 
37
37
  However, if you want to run a custom command to run webpack to build your bundles, then you will:
38
38
  1. Define `config.build_production_command` in your [config/initializers/react_on_rails.rb](https://www.shakacode.com/react-on-rails/docs/guides/configuration/)
@@ -12,7 +12,7 @@ compiled by webpack before running tests and during production deployment:
12
12
  2. **Use the react_on_rails settings and helpers**. Use the settings in `config/initializers/react_on_rails.rb`. Refer to [docs/configuration](https://www.shakacode.com/react-on-rails/docs/guides/configuration/).
13
13
 
14
14
  ```yml
15
- config.build_test_command = "NODE_ENV=test RAILS_ENV=test bin/webpack"
15
+ config.build_test_command = "NODE_ENV=test RAILS_ENV=test bin/webpacker"
16
16
  ```
17
17
 
18
18
  Which should you use? If you're already using the `rails/webpacker` way to configure webpack, then
@@ -4,7 +4,7 @@
4
4
 
5
5
  -----
6
6
 
7
- *Updated for Ruby 2.7.1, Rails 6.0.3.1, React on Rails v12.5.0, and Webpacker v6*
7
+ *Updated for Ruby 2.7.1, Rails 6.0.3.1, React on Rails v12.5.0, and Shakapacker v6*
8
8
 
9
9
  This tutorial guides you through setting up a new or existing Rails app with **React on Rails**, demonstrating Rails + React + Redux + Server Rendering.
10
10
 
@@ -21,18 +21,16 @@ By the time you read this, the latest may have changed. Be sure to check the ver
21
21
  * https://rubygems.org/gems/react_on_rails
22
22
  * https://www.npmjs.com/package/react-on-rails
23
23
 
24
- _Note: some of the screen images below show the "npm" command. react_on_rails 6.6.0 and greater uses `yarn`._
25
-
26
24
  ## Setting up your environment
27
25
 
28
- Trying out **React on Rails** is super easy, so long as you have the basic prerequisites. This includes the basics for Rails 6.x and node version 13+. I recommend `rvm` and `nvm` to install Ruby and Node, and [brew](https://brew.sh/) to install [yarn](https://yarnpkg.com/en/docs/install#mac-tab). Rails can be installed as an ordinary gem.
26
+ Trying out **React on Rails** is super easy, so long as you have the basic prerequisites. This includes the basics for Rails 6.x and node version 14+. I recommend `rvm` or `rbevn` and `nvm` to install Ruby and Node. Rails can be installed as an ordinary gem.
29
27
 
30
28
  ```
31
29
  nvm install node # download and install latest stable Node
32
30
  nvm alias default node # make it default version
33
31
  nvm list # check
34
32
 
35
- brew install yarn # you can use other installer if desired
33
+ brew install yarn # you can use other installer if desired, such as yvm
36
34
  rvm install 2.7 # download and install latest stable Ruby (update to exact version)
37
35
  rvm use 2.7 --default # use it and make it default
38
36
  rvm list # check
@@ -46,40 +44,37 @@ Then we need to create a fresh Rails application as following.
46
44
 
47
45
  First be sure to run `rails -v` and check you are using Rails 5.1.3 or above. If you are using an older version of Rails, you'll need to install webpacker with react per the instructions [here](https://github.com/rails/webpacker).
48
46
 
49
- ```
47
+ ```bash
50
48
  cd <directory where you want to create your new Rails app>
51
49
 
52
50
  # Any name you like for the rails app
53
51
  # Skip javascript so will add that next and get the current version
54
- rails new --skip-sprockets --skip-turbolinks --javascript=webpack test-react-on-rails
52
+ rails new --skip-turbolinks --skip-javascript test-react-on-rails
55
53
 
56
54
  cd test-react-on-rails
57
55
  ```
58
56
 
59
- ## Add the webpacker and react_on_rails gems
57
+ ## Add the shakapacker and react_on_rails gems
60
58
  To avoid issues regarding inconsistent gem and npm versions, you should specify the exact versions
61
59
  of both the gem and npm package. In other words, don't use the `^` or `~` in the version specifications.
62
- _Use the latest version for react_on_rails._
60
+ _Use the latest version for `react_on_rails` and `shakapacker`._
63
61
 
64
62
  ```
65
- gem 'react_on_rails', '12.5.0' # prefer exact gem version to match npm version
63
+ gem 'react_on_rails', '13.0.0' # prefer exact gem version to match npm version
64
+ gem 'shakapacker', '6.1.1' # prefer exact gem version to match npm version
65
+
66
66
  ```
67
67
 
68
68
  Note: The latest released React On Rails version is considered stable. Please use the latest
69
69
  version to ensure you get all the security patches and the best support.
70
70
 
71
- ```bash
72
- bundle add webpacker --git=https://github.com/rails/webpacker.git
73
- bundle add react_on_rails --version=12.5.0 --strict
74
- ```
75
-
76
- ## Run the webpacker generator
71
+ ## Run the webpacker (shakapacker) generator
77
72
 
78
73
  ```terminal
79
74
  bundle exec rails webpacker:install
80
75
  ```
81
76
 
82
- Let's commit everything before installing React on Rails.
77
+ **Let's commit everything before installing React on Rails.**
83
78
 
84
79
  ```
85
80
  # Here are git commands to make a new git repo and commit everything.
@@ -98,10 +93,11 @@ If you want the redux install: `rails generate react_on_rails:install --redux`
98
93
  The generator will add `mini_racer`'s latest version. If you're using linux & encounter issues installing `libv8`, here's [a common solution](https://github.com/rubyjs/mini_racer/issues/218).
99
94
 
100
95
  ```
101
- rails generate react_on_rails:install
96
+ bundle exec rails generate react_on_rails:install
102
97
  ```
103
98
 
104
- Enter `a` to replace all configuration files required by the project.
99
+ Enter `a` to replace all configuration files required by the project. You can check the diffs
100
+ before you commit to see what changed.
105
101
 
106
102
  Then run the server with one of the following options:
107
103
 
@@ -5,6 +5,21 @@ 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 upgrade. 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
9
+
10
+ ### Breaking Change
11
+ Previously, the gem `webpacker` was a Gem dependency.
12
+
13
+ v13 has changed slightly to switch to `shakapacker`.
14
+
15
+ For details, see see the [Shakapacker guide to upgrading](https://github.com/shakacode/shakapacker/blob/master/docs/v6_upgrade.md)
16
+
17
+ In summary:
18
+
19
+ 1. Change the gem reference from 'webpacker' to 'shakapacker'
20
+ 2. Change the npm reference from '@rails/webpacker' to 'shakapacker'
21
+ 3. Other updates, depending on what version of rails/webpacker that you had.
22
+
8
23
  ## Upgrading to v12
9
24
  ### Recent versions
10
25
  Make sure that you are on a relatively more recent version of rails and webpacker. Yes, the [rails/webpacker](https://github.com/rails/webpacker) gem is required!
@@ -33,7 +33,7 @@ Until version 9, all React on Rails apps used the `/client` directory for config
33
33
  You can access values in the `config/webpacker.yml`
34
34
 
35
35
  ```js
36
- const { config, devServer } = require('@rails/webpacker');
36
+ const { config, devServer } = require('shakapacker');
37
37
  ```
38
38
 
39
39
  You will want consider using some of the same values set in these files:
@@ -4,7 +4,7 @@
4
4
  and avoid any duplicates. We don't want different versions of the same packages.
5
5
  We want the versions from rails/webpacker unless we specifically want to override them.
6
6
  2. Search the rails/webpacker repo for anything you're not sure about in terms of package names.
7
- 3. run `bin/webpack` and make sure there are zero errors
7
+ 3. run `bin/webpacker` and make sure there are zero errors
8
8
  4. update webpack plugins and loaders to current or close to current
9
- 5. Make sure that your bin/webpack and bin/webpacker match the latest on
9
+ 5. Make sure that your bin/webpacker and bin/webpacker match the latest on
10
10
  https://github.com/rails/webpacker/tree/master/lib/install/bin
@@ -54,6 +54,7 @@ module ReactOnRails
54
54
  config/webpack/development.js
55
55
  config/webpack/production.js
56
56
  config/webpack/serverWebpackConfig.js
57
+ config/webpack/webpack.config.js
57
58
  config/webpack/webpackConfig.js]
58
59
  config = {
59
60
  message: "// The source code including full typescript support is available at:"
@@ -136,28 +137,28 @@ module ReactOnRails
136
137
 
137
138
  What to do next:
138
139
 
139
- - See the documentation on https://github.com/rails/webpacker/blob/master/docs/webpack.md
140
+ - See the documentation on https://github.com/shakacode/shakapacker#webpack-configuration
140
141
  for how to customize the default webpack configuration.
141
142
 
142
143
  - Include your webpack assets to your application layout.
143
144
 
144
145
  <%= javascript_pack_tag 'hello-world-bundle' %>
145
146
 
146
- - Run `rails s` to start the Rails server and use Webpacker's default lazy compilation.
147
+ - Run `rails s` to start the Rails server.
147
148
 
148
- - Visit http://localhost:3000/hello_world and see your React On Rails app running!
149
-
150
- - Run bin/webpack-dev-server to start the Webpack dev server for compilation of Webpack
149
+ - Run bin/webpacker-dev-server to start the Webpack dev server for compilation of Webpack
151
150
  assets as soon as you save. This default setup with the dev server does not work
152
151
  for server rendering
153
152
 
154
- - Alternately, you may turn off compile in config/webpacker.yml and run the foreman
155
- command to start the rails server and run webpack in watch mode.
153
+ - Visit http://localhost:3000/hello_world and see your React On Rails app running!
154
+
155
+ - Alternately, run the foreman command to start the rails server and run webpack#{' '}
156
+ in watch mode.
156
157
 
157
158
  foreman start -f Procfile.dev-static
158
159
 
159
160
  - To turn on HMR, edit config/webpacker.yml and set HMR to true. Restart the rails server
160
- and bin/webpack-dev-server. Or use Procfile.dev.
161
+ and bin/webpacker-dev-server. Or use Procfile.dev.
161
162
 
162
163
  - To server render, change this line app/views/hello_world/index.html.erb to
163
164
  `prerender: true` to see server rendering (right click on page and select "view source").
@@ -1,5 +1,5 @@
1
1
  # Procfile for development using HMR
2
2
  # You can run these commands in separate shells
3
3
  rails: bundle exec rails s -p 3000
4
- wp-client: HMR=true bin/webpack-dev-server
5
- wp-server: HMR=true SERVER_BUNDLE_ONLY=yes bin/webpack --watch
4
+ wp-client: HMR=true bin/webpacker-dev-server
5
+ wp-server: HMR=true SERVER_BUNDLE_ONLY=yes bin/webpacker --watch
@@ -5,5 +5,5 @@ web: rails s -p 3000
5
5
  # When making frequent changes to client side assets, you will prefer building webpack assets
6
6
  # upon saving rather than when you refresh your browser page.
7
7
  # Note, if using React on Rails localization you will need to run
8
- # `bundle exec rake react_on_rails:locale` before you run bin/webpack
9
- webpack: sh -c 'rm -rf public/packs/* || true && bin/webpack -w'
8
+ # `bundle exec rake react_on_rails:locale` before you run bin/webpacker
9
+ webpack: sh -c 'rm -rf public/packs/* || true && bin/webpacker -w'
@@ -1,15 +1,32 @@
1
1
  <%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/babel.config.js") %>
2
2
 
3
- const defaultConfigFunc = require('@rails/webpacker/package/babel/preset.js');
4
-
5
3
  module.exports = function (api) {
6
- const resultConfig = defaultConfigFunc(api);
4
+ const defaultConfigFunc = require('shakapacker/package/babel/preset.js')
5
+ const resultConfig = defaultConfigFunc(api)
6
+ const isProductionEnv = api.env('production')
7
7
 
8
8
  const changesOnDefault = {
9
- plugins: [process.env.WEBPACK_SERVE && 'react-refresh/babel'].filter(Boolean),
10
- };
9
+ presets: [
10
+ [
11
+ '@babel/preset-react',
12
+ {
13
+ development: !isProductionEnv,
14
+ useBuiltIns: true
15
+ }
16
+ ]
17
+ ].filter(Boolean),
18
+ plugins: [
19
+ process.env.WEBPACK_SERVE && 'react-refresh/babel',
20
+ isProductionEnv && ['babel-plugin-transform-react-remove-prop-types',
21
+ {
22
+ removeImport: true
23
+ }
24
+ ]
25
+ ].filter(Boolean),
26
+ }
11
27
 
12
- resultConfig.plugins = [...resultConfig.plugins, ...changesOnDefault.plugins];
28
+ resultConfig.presets = [...resultConfig.presets, ...changesOnDefault.presets]
29
+ resultConfig.plugins = [...resultConfig.plugins, ...changesOnDefault.plugins ]
13
30
 
14
- return resultConfig;
15
- };
31
+ return resultConfig
32
+ }
@@ -6,7 +6,7 @@
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
- # If nil, then the standard rails/webpacker assets:precompile will run
9
+ # If nil, then the standard shakacode/shakapacker assets:precompile will run
10
10
  # config.build_production_command = nil
11
11
 
12
12
  ################################################################################
@@ -25,7 +25,7 @@ ReactOnRails.configure do |config|
25
25
  #
26
26
  # Alternately, you can remove the `ReactOnRails::TestHelper.configure_rspec_to_compile_assets`
27
27
  # and set the config/webpacker.yml option for test to true.
28
- config.build_test_command = "RAILS_ENV=test bin/webpack"
28
+ config.build_test_command = "RAILS_ENV=test bin/webpacker"
29
29
 
30
30
  ################################################################################
31
31
  ################################################################################
@@ -1,7 +1,7 @@
1
1
  <%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/config/webpack/commonWebpackConfig.js") %>
2
2
 
3
3
  // Common configuration applying to client and server configuration
4
- const { webpackConfig: baseClientWebpackConfig, merge } = require('@rails/webpacker');
4
+ const { webpackConfig: baseClientWebpackConfig, merge } = require('shakapacker');
5
5
 
6
6
  const commonOptions = {
7
7
  resolve: {
@@ -2,7 +2,7 @@
2
2
 
3
3
  process.env.NODE_ENV = process.env.NODE_ENV || 'development';
4
4
 
5
- const { devServer, inliningCss } = require('@rails/webpacker');
5
+ const { devServer, inliningCss } = require('shakapacker');
6
6
 
7
7
  const webpackConfig = require('./webpackConfig');
8
8
 
@@ -1,6 +1,6 @@
1
1
  <%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/config/webpack/serverWebpackConfig.js") %>
2
2
 
3
- const { merge, config } = require('@rails/webpacker');
3
+ const { merge, config } = require('shakapacker');
4
4
  const commonWebpackConfig = require('./commonWebpackConfig');
5
5
 
6
6
  const webpack = require('webpack');
@@ -0,0 +1,15 @@
1
+ const { env, webpackConfig } = require('shakapacker')
2
+ const { existsSync } = require('fs')
3
+ const { resolve } = require('path')
4
+
5
+ const envSpecificConfig = () => {
6
+ const path = resolve(__dirname, `${env.nodeEnv}.js`)
7
+ if (existsSync(path)) {
8
+ console.log(`Loading ENV specific webpack configuration file ${path}`)
9
+ return require(path)
10
+ } else {
11
+ return webpackConfig
12
+ }
13
+ }
14
+
15
+ module.exports = envSpecificConfig()
@@ -1,4 +1,4 @@
1
- # Note: You must restart bin/webpack-dev-server for changes to take effect
1
+ # Note: You must restart bin/webpacker-dev-server for changes to take effect
2
2
 
3
3
  default: &default
4
4
  source_path: app/javascript
@@ -17,7 +17,7 @@ default: &default
17
17
 
18
18
  development:
19
19
  <<: *default
20
- # This is false since we're running `bin/webpack -w` in Procfile.dev-setic
20
+ # This is false since we're running `bin/webpacker -w` in Procfile.dev-setic
21
21
  compile: false
22
22
 
23
23
  # Reference: https://webpack.js.org/configuration/dev-server/
@@ -124,7 +124,7 @@ module ReactOnRails
124
124
 
125
125
  return if skip_react_on_rails_precompile || build_production_command.blank?
126
126
 
127
- # Ensure that rails/webpacker does not call bin/webpack if we're providing
127
+ # Ensure that shakacode/shakapacker does not call bin/webpacker if we're providing
128
128
  # the build command.
129
129
  ENV["WEBPACKER_PRECOMPILE"] = "false"
130
130
 
@@ -132,7 +132,7 @@ module ReactOnRails
132
132
  Rake::Task["react_on_rails:assets:webpack"].invoke
133
133
  puts "Invoking task webpacker:clean from React on Rails"
134
134
 
135
- # VERSIONS is per the rails/webpacker clean method definition.
135
+ # VERSIONS is per the shakacode/shakapacker clean method definition.
136
136
  # We set it very big so that it is not used, and then clean just
137
137
  # removes files older than 1 hour.
138
138
  versions = 100_000
@@ -150,42 +150,6 @@ module ReactOnRails
150
150
  end
151
151
  end
152
152
 
153
- # Pending updates to rails/webpacker v6, we may have some message that prints after configuration runs.
154
- # def check_deprecated_settings
155
- # if build_production_command.present? &&
156
- # ReactOnRails::WebpackerUtils.webpacker_webpack_production_config_exists?
157
- # msg = <<~MSG
158
- # Setting ReactOnRails configuration for `build_production_command` is
159
- # not necessary if you have config/webpack/production.js. When that file
160
- # exists, React on Rails DOES NOT modify the standard assets:precompile.
161
- # If you want React on Rails to modify to the standard assets:precompile
162
- # to use your config/initializers/react_on_rails.rb config.build_production_command
163
- # then delete the config/webpack/production.js.
164
- # MSG
165
- # Rails.logger.warn(msg)
166
- # end
167
- #
168
- # msg = <<~MSG
169
- # ReactOnRails configuration for `build_production_command` is removed.
170
- # Move this command into `bin/webpack` converting the script to a shell script.
171
- # MSG
172
- # raise ReactOnRails::Error, msg
173
- # Commenting out until v13 when
174
- # https://github.com/rails/webpacker/issues/2640 gets resolved
175
- # if node_modules_location.present?
176
- # Rails.logger.warn("ReactOnRails configuration for `node_modules_location` is deprecated. "\
177
- # "Instead, prepend a `cd client` (or whichever location) before your test command.")
178
- # end
179
- #
180
- # return unless build_production_command.present?
181
- #
182
- # msg = <<~MSG
183
- # ReactOnRails configuration for `build_production_command` is removed.
184
- # Move this command into `bin/webpack` converting the script to a shell script.
185
- # MSG
186
- # raise ReactOnRails::Error, msg
187
- # end
188
-
189
153
  def error_if_using_webpacker_and_generated_assets_dir_not_match_public_output_path
190
154
  return unless ReactOnRails::WebpackerUtils.using_webpacker?
191
155
 
@@ -195,7 +159,7 @@ module ReactOnRails
195
159
 
196
160
  if File.expand_path(generated_assets_dir) == webpacker_public_output_path.to_s
197
161
  Rails.logger.warn("You specified generated_assets_dir in `config/initializers/react_on_rails.rb` "\
198
- "with Webpacker. Remove this line from your configuration file.")
162
+ "with Webpacker. Remove this line from your configuration file.")
199
163
  else
200
164
  msg = <<~MSG
201
165
  Error configuring /config/initializers/react_on_rails.rb: You are using webpacker
@@ -257,19 +221,19 @@ module ReactOnRails
257
221
  if ReactOnRails::WebpackerUtils.using_webpacker?
258
222
  webpacker_public_output_path = ReactOnRails::WebpackerUtils.webpacker_public_output_path
259
223
  Rails.logger.warn "Error configuring config/initializers/react_on_rails. Define neither the "\
260
- "generated_assets_dirs no the generated_assets_dir when using Webpacker. This is defined by "\
261
- "public_output_path specified in webpacker.yml = #{webpacker_public_output_path}."
224
+ "generated_assets_dirs no the generated_assets_dir when using Webpacker. This is defined by "\
225
+ "public_output_path specified in webpacker.yml = #{webpacker_public_output_path}."
262
226
  return
263
227
  end
264
228
 
265
229
  Rails.logger.warn "[DEPRECATION] ReactOnRails: Use config.generated_assets_dir rather than "\
266
- "generated_assets_dirs"
230
+ "generated_assets_dirs"
267
231
  if generated_assets_dir.blank?
268
232
  self.generated_assets_dir = generated_assets_dirs
269
233
  else
270
234
  Rails.logger.warn "[DEPRECATION] ReactOnRails. You have both generated_assets_dirs and "\
271
- "generated_assets_dir defined. Define ONLY generated_assets_dir if NOT using Webpacker"\
272
- " and define neither if using Webpacker"
235
+ "generated_assets_dir defined. Define ONLY generated_assets_dir if NOT using Webpacker"\
236
+ " and define neither if using Webpacker"
273
237
  end
274
238
  end
275
239
 
@@ -154,7 +154,7 @@ module ReactOnRails
154
154
  @registered_stores_defer_render ||= []
155
155
  @registered_stores_defer_render << redux_store_data
156
156
  "YOU SHOULD NOT SEE THIS ON YOUR VIEW -- Uses as a code block, like <% redux_store %> "\
157
- "and not <%= redux store %>"
157
+ "and not <%= redux store %>"
158
158
  else
159
159
  @registered_stores ||= []
160
160
  @registered_stores << redux_store_data
@@ -244,7 +244,7 @@ module ReactOnRails
244
244
 
245
245
  unless hash_or_string.is_a?(String) || hash_or_string.is_a?(Hash)
246
246
  raise ReactOnRails::Error, "#{__method__} only accepts String or Hash as argument "\
247
- "(#{hash_or_string.class} given)."
247
+ "(#{hash_or_string.class} given)."
248
248
  end
249
249
 
250
250
  json_value = hash_or_string.is_a?(String) ? hash_or_string : hash_or_string.to_json
@@ -85,9 +85,7 @@ module ReactOnRails
85
85
 
86
86
  def generate_file(template, path)
87
87
  result = ERB.new(template).result()
88
- File.open(path, "w") do |f|
89
- f.write(result)
90
- end
88
+ File.write(path, result)
91
89
  end
92
90
 
93
91
  def generate_translations
@@ -36,7 +36,7 @@ module ReactOnRails
36
36
  end
37
37
 
38
38
  raise ReactOnRails::Error, "ReactOnRails: your rendering_props_extension module is missing the "\
39
- "required adjust_props_for_client_side_hydration method & can not be used"
39
+ "required adjust_props_for_client_side_hydration method & can not be used"
40
40
  end
41
41
  props
42
42
  end
@@ -133,15 +133,15 @@ module ReactOnRails
133
133
  if ReactOnRails.configuration.trace
134
134
  Rails.logger.info do
135
135
  "[react_on_rails] Created JavaScript context with file "\
136
- "#{ReactOnRails::Utils.server_bundle_js_file_path}"
136
+ "#{ReactOnRails::Utils.server_bundle_js_file_path}"
137
137
  end
138
138
  end
139
139
  ExecJS.compile(base_js_code)
140
140
  rescue StandardError => e
141
141
  msg = "ERROR when compiling base_js_code! "\
142
- "See file #{file_name} to "\
143
- "correlate line numbers of error. Error is\n\n#{e.message}"\
144
- "\n\n#{e.backtrace.join("\n")}"
142
+ "See file #{file_name} to "\
143
+ "correlate line numbers of error. Error is\n\n#{e.message}"\
144
+ "\n\n#{e.backtrace.join("\n")}"
145
145
  Rails.logger.error(msg)
146
146
  trace_js_code_used("Error when compiling JavaScript code for the context.", base_js_code,
147
147
  file_name, force: true)
@@ -186,7 +186,7 @@ module ReactOnRails
186
186
  def undefined_for_exec_js_logging(function_name)
187
187
  if ReactOnRails.configuration.trace
188
188
  "console.error('[React on Rails Rendering] #{function_name} is not defined for server rendering.');\n"\
189
- " console.error(getStackTrace().join('\\n'));"
189
+ " console.error(getStackTrace().join('\\n'));"
190
190
  else
191
191
  ""
192
192
  end
@@ -66,10 +66,10 @@ module ReactOnRails
66
66
  file_list = make_file_list(make_globs(generated_assets_full_path)).to_ary
67
67
  puts "V" * 80
68
68
  puts "Please define config.webpack_generated_files (array) so the test helper knows "\
69
- "which files are required. If you are using webpacker, you typically need to only "\
70
- "include 'manifest.json'."
69
+ "which files are required. If you are using webpacker, you typically need to only "\
70
+ "include 'manifest.json'."
71
71
  puts "Detected the possible following files to check for webpack compilation in "\
72
- "#{generated_assets_full_path}"
72
+ "#{generated_assets_full_path}"
73
73
  puts file_list.join("\n")
74
74
  puts "^" * 80
75
75
  file_list
@@ -72,8 +72,8 @@ module ReactOnRails
72
72
  unless @printed_once
73
73
  puts
74
74
  puts "====> React On Rails: Checking files in "\
75
- "#{webpack_assets_status_checker.generated_assets_full_path} for "\
76
- "outdated/missing bundles based on source_path #{source_path}"
75
+ "#{webpack_assets_status_checker.generated_assets_full_path} for "\
76
+ "outdated/missing bundles based on source_path #{source_path}"
77
77
  puts
78
78
  @printed_once = true
79
79
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReactOnRails
4
- VERSION = "12.6.0"
4
+ VERSION = "13.0.0.beta.0"
5
5
  end
@@ -7,13 +7,8 @@ module ReactOnRails
7
7
  def self.using_webpacker?
8
8
  return @using_webpacker if defined?(@using_webpacker)
9
9
 
10
- @using_webpacker = ReactOnRails::Utils.gem_available?("webpacker")
11
- end
12
-
13
- def self.webpacker_webpack_production_config_exists?
14
- webpacker_webpack_config_abs_path = File.join(Rails.root,
15
- "config/webpack/production.js")
16
- File.exist?(webpacker_webpack_config_abs_path)
10
+ @using_webpacker = ReactOnRails::Utils.gem_available?("webpacker") ||
11
+ ReactOnRails::Utils.gem_available?("shakapacker")
17
12
  end
18
13
 
19
14
  def self.dev_server_running?
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-on-rails",
3
- "version": "12.6.0",
3
+ "version": "13.0.0-beta.0",
4
4
  "description": "react-on-rails JavaScript for react_on_rails Ruby gem",
5
5
  "main": "node_package/lib/ReactOnRails.js",
6
6
  "directories": {
@@ -45,7 +45,10 @@ module ReactOnRails
45
45
  # Gems we need to add to the Gemfile before bundle installing
46
46
  def required_gems
47
47
  relative_gem_root = Pathname(gem_root).relative_path_from(Pathname(dir))
48
- ["gem 'react_on_rails', path: '#{relative_gem_root}'"]
48
+ [
49
+ "gem 'react_on_rails', path: '#{relative_gem_root}'",
50
+ "gem 'shakapacker'"
51
+ ]
49
52
  end
50
53
 
51
54
  # Options we pass when running `rails new` from the command-line.
@@ -78,7 +81,7 @@ module ReactOnRails
78
81
  # Assumes we are inside a rails app's folder and necessary gems have been installed
79
82
  def generator_shell_commands
80
83
  shell_commands = []
81
- shell_commands << "rails generate react_on_rails:install #{generator_options} --ignore-warnings"
84
+ shell_commands << "rails generate react_on_rails:install #{generator_options} --ignore-warnings --force"
82
85
  shell_commands << "rails generate react_on_rails:dev_tests #{generator_options}"
83
86
  end
84
87
 
@@ -30,19 +30,12 @@ namespace :examples do # rubocop:disable Metrics/BlockLength
30
30
  desc "Generates #{example_type.name_pretty}"
31
31
  task example_type.gen_task_name_short => example_type.clobber_task_name do
32
32
  mkdir_p(example_type.dir)
33
- if Rails::VERSION::MAJOR < 6
34
- example_type.rails_options += " --webpack"
35
- elsif Rails::VERSION::MAJOR >= 7
36
- example_type.rails_options += "--javascript=webpack"
37
- end
33
+ example_type.rails_options += "--skip-javascript"
38
34
  sh_in_dir(examples_dir, "rails new #{example_type.name} #{example_type.rails_options}")
39
35
  sh_in_dir(example_type.dir, "touch .gitignore")
40
- copy_generator_webpacker_yml_to(example_type.dir)
41
- sh_in_dir(example_type.dir, "bundle add webpacker --version 6.0.0.rc.6")
42
- sh_in_dir(example_type.dir, "rake webpacker:install")
43
- sh_in_dir(example_type.dir, "bundle binstubs --path=#{example_type.dir}/bin webpacker")
44
36
  append_to_gemfile(example_type.gemfile, example_type.required_gems)
45
37
  bundle_install_in(example_type.dir)
38
+ sh_in_dir(example_type.dir, "rake webpacker:install")
46
39
  sh_in_dir(example_type.dir, example_type.generator_shell_commands)
47
40
  sh_in_dir(example_type.dir, "yarn")
48
41
  end
@@ -12,13 +12,6 @@ module ReactOnRails
12
12
  File.join(gem_root, "gen-examples", "examples")
13
13
  end
14
14
 
15
- # This method is used to prevent an error that when installing webpacker 6.0.0.rc.6
16
- # without a previous config/webpacker.yml will throw and error
17
- def copy_generator_webpacker_yml_to(destination)
18
- webpacker_file = File.join(gem_root, "lib/generators/react_on_rails/templates/base/base/config/webpacker.yml")
19
- sh %( cp #{webpacker_file} #{destination}/config/webpacker.yml )
20
- end
21
-
22
15
  def dummy_app_dir
23
16
  File.join(gem_root, "spec/dummy")
24
17
  end
@@ -30,7 +30,6 @@ Gem::Specification.new do |s|
30
30
  s.add_dependency "execjs", "~> 2.5"
31
31
  s.add_dependency "rails", ">= 5.2"
32
32
  s.add_dependency "rainbow", "~> 3.0"
33
- s.add_dependency "webpacker", ">= 4.2"
34
33
 
35
34
  s.add_development_dependency "bundler", "~> 2"
36
35
  s.add_development_dependency "gem-release"
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.6.0
4
+ version: 13.0.0.beta.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Gordon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-23 00:00:00.000000000 Z
11
+ date: 2022-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.0'
83
- - !ruby/object:Gem::Dependency
84
- name: webpacker
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '4.2'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '4.2'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: bundler
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -262,6 +248,7 @@ files:
262
248
  - lib/generators/react_on_rails/templates/base/base/config/webpack/development.js.tt
263
249
  - lib/generators/react_on_rails/templates/base/base/config/webpack/production.js.tt
264
250
  - lib/generators/react_on_rails/templates/base/base/config/webpack/serverWebpackConfig.js.tt
251
+ - lib/generators/react_on_rails/templates/base/base/config/webpack/webpack.config.js.tt
265
252
  - lib/generators/react_on_rails/templates/base/base/config/webpack/webpackConfig.js.tt
266
253
  - lib/generators/react_on_rails/templates/base/base/config/webpacker.yml
267
254
  - lib/generators/react_on_rails/templates/dev_tests/.eslintrc
@@ -346,9 +333,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
346
333
  version: 2.7.0
347
334
  required_rubygems_version: !ruby/object:Gem::Requirement
348
335
  requirements:
349
- - - ">="
336
+ - - ">"
350
337
  - !ruby/object:Gem::Version
351
- version: '0'
338
+ version: 1.3.1
352
339
  requirements: []
353
340
  rubygems_version: 3.2.32
354
341
  signing_key: