react_on_rails 13.3.0 → 13.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +5 -4
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +1 -1
  4. data/.github/PULL_REQUEST_TEMPLATE.md +19 -0
  5. data/.github/workflows/lint-js-and-ruby.yml +2 -1
  6. data/.github/workflows/main.yml +17 -18
  7. data/.github/workflows/rspec-package-specs.yml +1 -0
  8. data/.prettierignore +3 -1
  9. data/CHANGELOG.md +106 -56
  10. data/Gemfile.development_dependencies +2 -2
  11. data/README.md +9 -1
  12. data/docs/additional-details/recommended-project-structure.md +6 -6
  13. data/docs/additional-details/tips-for-usage-with-sp6.md +15 -0
  14. data/docs/deployment/heroku-deployment.md +15 -11
  15. data/docs/getting-started.md +28 -27
  16. data/docs/guides/configuration.md +29 -19
  17. data/docs/guides/deployment.md +3 -2
  18. data/docs/guides/file-system-based-automated-bundle-generation.md +57 -51
  19. data/docs/guides/hmr-and-hot-reloading-with-the-webpack-dev-server.md +10 -10
  20. data/docs/guides/how-react-on-rails-works.md +6 -6
  21. data/docs/guides/how-to-conditionally-server-render-based-on-device-type.md +2 -1
  22. data/docs/guides/installation-into-an-existing-rails-app.md +10 -8
  23. data/docs/guides/rails-webpacker-react-integration-options.md +34 -4
  24. data/docs/guides/react-on-rails-overview.md +6 -7
  25. data/docs/guides/rspec-configuration.md +11 -11
  26. data/docs/guides/tutorial.md +89 -83
  27. data/docs/guides/upgrading-react-on-rails.md +2 -2
  28. data/docs/guides/webpack-configuration.md +14 -14
  29. data/docs/home.md +3 -3
  30. data/docs/javascript/asset-pipeline.md +4 -4
  31. data/docs/javascript/converting-from-custom-webpack-config-to-rails-webpacker-config.md +8 -8
  32. data/docs/javascript/server-rendering-tips.md +1 -1
  33. data/docs/javascript/troubleshooting-when-using-shakapacker.md +77 -0
  34. data/docs/outdated/rails-assets-relative-paths.md +1 -1
  35. data/docs/outdated/rails-assets.md +1 -1
  36. data/docs/react-on-rails-pro/react-on-rails-pro.md +1 -1
  37. data/lib/generators/react_on_rails/adapt_for_older_shakapacker_generator.rb +41 -0
  38. data/lib/generators/react_on_rails/base_generator.rb +3 -47
  39. data/lib/generators/react_on_rails/bin/dev +2 -5
  40. data/lib/generators/react_on_rails/bin/dev-static +2 -5
  41. data/lib/generators/react_on_rails/generator_messages.rb +40 -0
  42. data/lib/generators/react_on_rails/install_generator.rb +30 -0
  43. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +2 -2
  44. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-static +2 -2
  45. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +2 -2
  46. data/lib/generators/react_on_rails/templates/base/base/config/{webpacker.yml → shakapacker.yml} +3 -3
  47. data/lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt +3 -1
  48. data/lib/react_on_rails/configuration.rb +16 -16
  49. data/lib/react_on_rails/helper.rb +26 -27
  50. data/lib/react_on_rails/packs_generator.rb +12 -5
  51. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +1 -3
  52. data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +1 -1
  53. data/lib/react_on_rails/test_helper.rb +10 -1
  54. data/lib/react_on_rails/utils.rb +0 -4
  55. data/lib/react_on_rails/version.rb +1 -1
  56. data/lib/react_on_rails/webpacker_utils.rb +8 -3
  57. data/package.json +1 -1
  58. data/rakelib/dummy_apps.rake +6 -1
  59. data/rakelib/run_rspec.rake +1 -15
  60. metadata +7 -3
data/README.md CHANGED
@@ -53,7 +53,7 @@ Given that `rails/webpacker` gem already provides basic React integration, why w
53
53
  1. Easy passing of props directly from your Rails view to your React components rather than having your Rails view load and then make a separate request to your API.
54
54
  Tight integration with [shakapacker](https://github.com/shakacode/shakapacker) (or it's predecessor [rails/webpacker](https://github.com/rails/webpacker)).
55
55
  1. Server-Side Rendering (SSR), often used for SEO crawler indexing and UX performance.
56
- 1. [Automated optimized entry-point creation and bundle inclusion when placing a component on a page. With this feature, you no longer need to configure `javascript_pack_tags` and `stylesheet_pack_tags` on your layouts based on what’s shown. “It just works!”](https://www.shakacode.com/react-on-rails/docs/guides/file-system-based-automated-bundle-generation.md)
56
+ 1. [Automated optimized entry-point creation and bundle inclusion when placing a component on a page. With this feature, you no longer need to configure `javascript_pack_tags` and `stylesheet_pack_tags` on your layouts based on what’s shown. “It just works!”](https://www.shakacode.com/react-on-rails/docs/guides/file-system-based-automated-bundle-generation/)
57
57
  1. [Redux](https://github.com/reactjs/redux) and [React Router](https://github.com/ReactTraining/react-router#readme) integration with server-side-rendering.
58
58
  1. [Internationalization (I18n) and (localization)](https://www.shakacode.com/react-on-rails/docs/guides/i18n)
59
59
  1. A supportive community. This [web search shows how live public sites are using React on Rails](https://publicwww.com/websites/%22react-on-rails%22++-undeveloped.com+depth%3Aall/).
@@ -113,6 +113,11 @@ The following companies support our open source projects, and ShakaCode uses the
113
113
  <img alt="ScoutAPM" src="https://user-images.githubusercontent.com/4244251/184881152-9f2d8fba-88ac-4ba6-873b-22387f8711c5.png" height="120px">
114
114
  </picture>
115
115
  </a>
116
+ <a href="https://controlplane.com">
117
+ <picture>
118
+ <img alt="Control Plane" src="https://github.com/shakacode/.github/assets/20628911/90babd87-62c4-4de3-baa4-3d78ef4bec25" height="120px">
119
+ </picture>
120
+ </a>
116
121
  <br />
117
122
  <a href="https://www.browserstack.com">
118
123
  <picture>
@@ -127,3 +132,6 @@ The following companies support our open source projects, and ShakaCode uses the
127
132
  <a href="https://www.honeybadger.io">
128
133
  <img src="https://user-images.githubusercontent.com/4244251/184881133-79ee9c3c-8165-4852-958e-31687b9536f4.png" alt="Honeybadger" height="55px">
129
134
  </a>
135
+ <a href="https://reviewable.io">
136
+ <img src="https://user-images.githubusercontent.com/20628911/230848305-c94510a4-82d7-468f-bf9f-eeb81d3f2ce0.png" alt="Reviewable" height="55px">
137
+ </a>
@@ -1,6 +1,6 @@
1
1
  # Recommended Project structure
2
2
 
3
- The React on Rails generator uses the standard `rails/webpacker` convention of this structure:
3
+ The React on Rails generator uses the standard Shakapacker convention of this structure:
4
4
 
5
5
  ```yml
6
6
  app/javascript:
@@ -13,7 +13,7 @@ app/javascript:
13
13
  ```
14
14
 
15
15
  Per the example repo [shakacode/react_on_rails_demo_ssr_hmr](https://github.com/shakacode/react_on_rails_demo_ssr_hmr),
16
- you should consider keeping your codebase mostly consistent with the defaults for [rails/webpacker](https://github.com/rails/webpacker).
16
+ you should consider keeping your codebase mostly consistent with the defaults for [Shakapacker](https://github.com/shakacode/shakapacker).
17
17
 
18
18
  ## Steps to convert from the generator defaults to use a `/client` directory for source code
19
19
 
@@ -23,7 +23,7 @@ you should consider keeping your codebase mostly consistent with the defaults fo
23
23
  mv app/javascript client
24
24
  ```
25
25
 
26
- 2. Edit your `/config/webpacker.yml` file. Change the `default/source_path`:
26
+ 2. Edit your `/config/shakapacker.yml` file. Change the `default/source_path`:
27
27
 
28
28
  ```yml
29
29
  source_path: client
@@ -31,7 +31,7 @@ mv app/javascript client
31
31
 
32
32
  ## Moving node_modules from `/` to `/client` with a custom webpack setup.
33
33
 
34
- `rails/webpacker` probably doesn't support having your main node_modules directory under `/client`, so only follow these steps if you want to use your own webpack configuration.
34
+ Shakapacker probably doesn't support having your main node_modules directory under `/client`, so only follow these steps if you want to use your own webpack configuration.
35
35
 
36
36
  1. Move the `/package.json` to `/client/package.json`
37
37
  2. Create a `/package.json` that delegates to `/client/package.json`.
@@ -40,8 +40,8 @@ mv app/javascript client
40
40
  "heroku-postbuild": "cd ./client && yarn"
41
41
  },
42
42
  ```
43
- 3. If your node_modules directory is not at the top level of the Rails project, then you will need to set the
44
- ENV value of WEBPACKER_CONFIG to the location of the `config/webpacker.yml` file per [rails/webpacker PR 2561](https://github.com/rails/webpacker/pull/2561).
43
+ 3. If your `node_modules` directory is not at the top level of the Rails project, then you will need to set the
44
+ ENV value of `SHAKAPACKER_CONFIG` to the location of the `config/shakapacker.yml` file per [rails/webpacker PR 2561](https://github.com/rails/webpacker/pull/2561). (Notice the change of spelling from Webpacker to Shakapacker)
45
45
 
46
46
  ## CSS, Sass, Fonts, and Images
47
47
  Should you move your styling assets to Webpack? Or stick with the plain Rails asset pipeline. It depends!
@@ -0,0 +1,15 @@
1
+ # Tips for usage with Shakapacker 6
2
+
3
+ As mentioned earlier in the documentation, we assume you install ReactOnRails in a project with Shakapacker 7+ installed and configured. If you still use Shakapacker 6, we encourage you to check the upgrade to the version 7 guide. Otherwise, you need to consider the following:
4
+
5
+ 1. The install generator tries to take the necessary steps to adapt the installed files to match the file structure and configurations for Shakapacker 6. So you don't need to be worried about the ReactOnRails installation process.
6
+
7
+ 2. Check the following table to map the references in the documentation to the relevant ones in Shakapacker 6:
8
+
9
+ |Usage in Shakapacker 7 |Equivalant in Shakapacker 6|
10
+ |----------------------------|---------------------------|
11
+ |`config/shakapacker.yml` |`config/webpacker.yml` |
12
+ |`bin/shakapacker` |`bin/webpacker` |
13
+ |`bin/shakapacker-dev-server`|`bin/webpacker-dev-server` |
14
+
15
+ 3. Any environment variables starting with `SHAKAPACKER_*` should be changed to `WEBPACKER_*`.
@@ -5,7 +5,7 @@ React on Rails requires both a ruby environment (for Rails) and a Node environme
5
5
 
6
6
  Assuming you have downloaded and installed the Heroku command-line utility and have initialized the app, you will need to tell Heroku to use both buildpacks via the command-line:
7
7
 
8
- ```
8
+ ```bash
9
9
  heroku buildpacks:set heroku/ruby
10
10
  heroku buildpacks:add --index 1 heroku/nodejs
11
11
  ```
@@ -14,22 +14,26 @@ For more information, see [Using Multiple Buildpacks for an App](https://devcent
14
14
 
15
15
  ## assets:precompile
16
16
 
17
- ### rails/webpacker webpack configuration
18
- If you're using the standard rails/webpacker configuration of webpack, then rails/webpacker
19
- will automatically modify or create an assets:precompile task to build your assets.
17
+ ### Shakapacker webpack configuration
18
+
19
+ Shakapacker hooks up a new `shakapacker:compile` task to `assets:precompile`, which gets run whenever you run `assets:precompile`.
20
+ If you are not using Sprockets, `shakapacker:compile` is automatically aliased to `assets:precompile`.
21
+
22
+ If you're using the standard `shakacode/shakapacker` configuration of webpack, then `shakacode/shakapacker`
23
+ will automatically modify or create an `assets:precompile` task to build your assets.
20
24
 
21
25
  Alternatively, you can specify `config.build_production_command` to have
22
- react_on_rails invoke a command for you during assets:precompile.
26
+ `react_on_rails` invoke a command for you during `assets:precompile`.
23
27
 
24
- ```
25
- config.build_production_command = "RAILS_ENV=production NODE_ENV=production bin/webpacker"
28
+ ```bash
29
+ config.build_production_command = "RAILS_ENV=production NODE_ENV=production bin/shakapacker"
26
30
  ```
27
31
 
28
- ### Consider Removing Webpacker's clean task
32
+ ### Consider Removing Shakapacker's clean task
29
33
 
30
- If you are deploying on Heroku, then you don't need Webpacker's clean task which
34
+ If you are deploying on Heroku, then you don't need Shakapacker's clean task which
31
35
  might delete files that you need.
32
36
 
33
- ```
34
- Rake::Task['webpacker:clean'].clear
37
+ ```bash
38
+ Rake::Task['shakapacker:clean'].clear
35
39
  ```
@@ -2,6 +2,8 @@
2
2
 
3
3
  Note, the best way to understand how to use ReactOnRails is to study a few simple examples. You can do a quick demo setup, either on your existing app or on a new Rails app.
4
4
 
5
+ This documentation assumes the usage of ReactOnRails with Shakapacker 7. For installation on Shakapacker 6, check [tips for usage with Shakapacker 6](https://www.shakacode.com/react-on-rails/docs/aditional-details/tips-for-usage-with-sp6) first.
6
+
5
7
  1. Do the quick [tutorial](https://www.shakacode.com/react-on-rails/docs/guides/tutorial/).
6
8
  2. Add React on Rails to an existing Rails app per [the instructions](https://www.shakacode.com/react-on-rails/docs/guides/installation-into-an-existing-rails-app/).
7
9
  3. Look at [spec/dummy](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy), a simple, no DB example.
@@ -9,38 +11,37 @@ Note, the best way to understand how to use ReactOnRails is to study a few simpl
9
11
 
10
12
  ## Basic Installation
11
13
 
12
- These steps assume that you've got a rails application with webpacker (e.g. one
13
- generated using `rails new my_app --javascript=webpack`). If your
14
- application is not yet set up to use webpacker, please see
15
- [the instructions for installing into an existing Rails app](https://www.shakacode.com/react-on-rails/docs/guides/installation-into-an-existing-rails-app/).*
14
+ You need a Rails application with Shakapacker installed and configured on it. Check [Shakapacker documentation](https://github.com/shakacode/shakapacker) for more details but typically you need the following steps:
16
15
 
17
- 1. Add the `shakapacker` and `react_on_rails` gem to Gemfile:
16
+ ```bash
17
+ rails new PROJECT_NAME --skip-javascript
18
+ cd PROJECT_NAME
19
+ bundle add shakapacker --strict
20
+ rails shakapacker:install
21
+ ```
18
22
 
19
- ```bash
20
- bundle add shakapacker --strict
21
- bundle add react_on_rails --strict
22
- ```
23
+ You may need to check [the instructions for installing into an existing Rails app](https://www.shakacode.com/react-on-rails/docs/guides/installation-into-an-existing-rails-app/) if you have an already working Rails application.
23
24
 
24
- 2. Run installation command for webpacker:
25
+ 1. Add the `react_on_rails` gem to Gemfile:
25
26
 
26
27
  ```bash
27
- rails webpacker:install
28
+ bundle add react_on_rails --strict
28
29
  ```
29
30
 
30
- 3. Commit this to git (or else you cannot run the generator unless you pass the option `--ignore-warnings`).
31
+ Commit this to git (or else you cannot run the generator in the next step unless you pass the option `--ignore-warnings`).
31
32
 
32
- 3. Run the generator:
33
+ 2. Run the install generator:
33
34
 
34
35
  ```bash
35
36
  rails generate react_on_rails:install
36
37
  ```
37
38
 
38
- 4. Start the app:
39
+ 3. Start the app:
39
40
 
40
41
  - Run `./bin/dev` for HMR
41
42
  - Run `./bin/dev-static` for statically created bundles (no HMR)
42
43
 
43
- 5. Visit http://localhost:3000/hello_world.
44
+ 4. Visit http://localhost:3000/hello_world.
44
45
 
45
46
 
46
47
  ### Turning on server rendering
@@ -60,7 +61,7 @@ Below is the line where you turn server rendering on by setting `prerender` to t
60
61
  ```
61
62
 
62
63
  Note, if you got an error in your console regarding "ReferenceError: window is not defined",
63
- then you need to edit `config/webpacker.yml` and set `hmr: false` and `inline: false`.
64
+ then you need to edit `config/shakapacker.yml` and set `hmr: false` and `inline: false`.
64
65
  See [rails/webpacker PR 2644](https://github.com/rails/webpacker/pull/2644) for a fix for this
65
66
  issue.
66
67
 
@@ -69,18 +70,18 @@ issue.
69
70
  ### Configuration
70
71
 
71
72
  * Configure `config/initializers/react_on_rails.rb`. You can adjust some necessary settings and defaults. See file [docs/basics/configuration.md](https://www.shakacode.com/react-on-rails/docs/guides/configuration/) for documentation of all configuration options.
72
- * Configure `config/webpacker.yml`. If you used the generator and the default webpacker setup, you don't need to touch this file. If you are customizing your setup, then consult the [spec/dummy/config/webpacker.yml](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/config/webpacker.yml) example or the official default [webpacker.yml](https://github.com/rails/webpacker/blob/master/lib/install/config/webpacker.yml).
73
- * Most apps should rely on the rails/webpacker setup for Webpack. v6 of rails/webpacker includes support for v5 of webpack.
73
+ * Configure `config/shakapacker.yml`. If you used the generator and the default Shakapacker setup, you don't need to touch this file. If you are customizing your setup, then consult the [spec/dummy/config/shakapacker.yml](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/config/shakapacker.yml) example or the official default [shakapacker.yml](https://github.com/shakacode/shakapacker/blob/master/lib/install/config/shakapacker.yml).
74
+ * Most apps should rely on the Shakapacker setup for Webpack. Shakapacker v6+ includes support for webpack version 5.
74
75
 
75
76
  ## Including your React Component on your Rails Views
76
77
 
77
- - React component are rendered via your Rails Views. Here's an ERB sample:
78
+ - React components are rendered via your Rails Views. Here's an ERB sample:
78
79
 
79
80
  ```erb
80
81
  <%= react_component("HelloWorld", props: @some_props) %>
81
82
  ```
82
83
 
83
- - **Server-Side Rendering**: Your react component is first rendered into HTML on the server. Use the **prerender** option:
84
+ - **Server-Side Rendering**: Your React component is first rendered into HTML on the server. Use the **prerender** option:
84
85
 
85
86
  ```erb
86
87
  <%= react_component("HelloWorld", props: @some_props, prerender: true) %>
@@ -146,13 +147,13 @@ For details on techniques to use different code for client and server rendering,
146
147
 
147
148
  ## Specifying Your React Components: Register directly or use render-functions
148
149
 
149
- You have two ways to specify your React components. You can either register the React component (either function or class component) directly, or you can create a function that returns a React component, which we using the name of a "render-function". Creating a render-function allows:
150
+ You have two ways to specify your React components. You can either register the React component (either function or class component) directly, or you can create a function that returns a React component, which we using the name of a "render-function". Creating a render-function allows you to:
150
151
 
151
- 1. You to have access to the `railsContext`. See [documentation for the railsContext](https://www.shakacode.com/react-on-rails/docs/guides/render-functions-and-railscontext/) in terms of why you might need it. You **need** a Render-Function to access the `railsContext`.
152
- 2. You can use the passed-in props to initialize a redux store or set up react-router.
153
- 3. You can return different components depending on what's in the props.
152
+ 1. Access to the `railsContext`. See the [documentation for the railsContext](https://www.shakacode.com/react-on-rails/docs/guides/render-functions-and-railscontext/) in terms of why you might need it. You **need** a Render-Function to access the `railsContext`.
153
+ 2. Use the passed-in props to initialize a redux store or set up `react-router`.
154
+ 3. Return different components depending on what's in the props.
154
155
 
155
- Note, the return value of a **Render-Function** should be either a React Function or Class Component, or an object representing server rendering results.
156
+ Note, the return value of a **Render-Function** should be either a React Function or Class Component or an object representing server rendering results.
156
157
 
157
158
  **Do not return a React Element (JSX).**
158
159
 
@@ -174,9 +175,9 @@ Thus, there is no difference between registering a React Function Component or c
174
175
 
175
176
  ## react_component_hash for Render-Functions
176
177
 
177
- Another reason to use a Render-Function is that sometimes in server rendering, specifically with React Router, you need to return the result of calling ReactDOMServer.renderToString(element). You can do this by returning an object with the following shape: { renderedHtml, redirectLocation, error }. Make sure you use this function with `react_component_hash`.
178
+ Another reason to use a Render-Function is that sometimes in server rendering, specifically with React Router, you need to return the result of calling ReactDOMServer.renderToString(element). You can do this by returning an object with the following shape: `{ renderedHtml, redirectLocation, error }`. Make sure you use this function with `react_component_hash`.
178
179
 
179
- For server rendering, if you wish to return multiple HTML strings from a Render-Function, you may return an Object from your Render-Function with a single top-level property of `renderedHtml`. Inside this Object, place a key called `componentHtml`, along with any other needed keys. An example scenario of this is when you are using side effects libraries like [React Helmet](https://github.com/nfl/react-helmet). Your Ruby code will get this Object as a Hash containing keys componentHtml and any other custom keys that you added:
180
+ For server rendering, if you wish to return multiple HTML strings from a Render-Function, you may return an Object from your Render-Function with a single top-level property of `renderedHtml`. Inside this Object, place a key called `componentHtml`, along with any other needed keys. An example scenario of this is when you are using side effects libraries like [React Helmet](https://github.com/nfl/react-helmet). Your Ruby code will get this Object as a Hash containing keys `componentHtml` and any other custom keys that you added:
180
181
 
181
182
  ```js
182
183
  { renderedHtml: { componentHtml, customKey1, customKey2} }
@@ -1,8 +1,8 @@
1
1
  Here is the full set of config options. This file is `/config/initializers/react_on_rails.rb`
2
2
 
3
- First, you should have a `/config/webpacker.yml` setup.
3
+ First, you should have a `/config/shakapacker.yml` setup.
4
4
 
5
- Here is the setup when using the recommended `/client` directory for your node_modules and source files:
5
+ Here is the setup when using the recommended `/client` directory for your `node_modules` and source files:
6
6
 
7
7
  ```yaml
8
8
  # Note: Base output directory of /public is assumed for static files
@@ -23,7 +23,7 @@ development:
23
23
 
24
24
  test:
25
25
  <<: *default
26
- # Ensure that webpacker invokes webpack to build files for tests if not using the
26
+ # Ensure that shakapacker invokes webpack to build files for tests if not using the
27
27
  # ReactOnRails rspec helper.
28
28
  compile: true
29
29
 
@@ -69,19 +69,19 @@ ReactOnRails.configure do |config|
69
69
  config.random_dom_id = true # default
70
70
 
71
71
  # defaults to "" (top level)
72
- config.node_modules_location = "client" # If using webpacker you should use "".
72
+ config.node_modules_location = "client" # If using Shakapacker you should use "".
73
73
 
74
- # If you're using the standard rails/webpacker configuration of webpack, then rails/webpacker
74
+ # If you're using the standard Shakapacker configuration of webpack, then Shakapacker
75
75
  # will automatically modify or create an assets:precompile task to build your assets. If so,
76
76
  # set this value to nil. Alternatively, you can specify `config.build_production_command`
77
77
  # to have react_on_rails invoke a command for you during assets:precompile.
78
78
  # The command is either a script or a module containing a class method `call`
79
79
  # In this example, the module BuildProductionCommand would have a class method `call`.
80
- config.build_production_command = "RAILS_ENV=production bin/webpacker"
80
+ config.build_production_command = "RAILS_ENV=production bin/shakapacker"
81
81
 
82
82
  # NOTE:
83
- # When specifying `build_production_command`, you need to disable `rails/webpacker`
84
- # configuration by setting `webpacker_precompile: false` in your `config/webpacker.yml` file.
83
+ # When specifying `build_production_command`, you need to disable `rails/shakapacker`
84
+ # configuration by setting `shakapacker_precompile: false` in your `config/shakapacker.yml` file.
85
85
 
86
86
  # See bottom for an example of the BuildProductionCommand module.
87
87
  # config.build_production_command = BuildProductionCommand
@@ -118,8 +118,8 @@ ReactOnRails.configure do |config|
118
118
  # Normally, you have different bundles for client and server, thus, the default is false.
119
119
  # Furthermore, if you are not hashing the server bundle (not in the manifest.json), then React on Rails
120
120
  # will only look for the server bundle to be created in the typical file location, typically by
121
- # a `webpack --watch` process.
122
- # If true, ensure that in config/webpacker.yml that you have both dev_server.hmr and
121
+ # a `shakapacker --watch` process.
122
+ # If true, ensure that in config/shakapacker.yml that you have both dev_server.hmr and
123
123
  # dev_server.inline set to false.
124
124
  config.same_bundle_for_client_and_server = false
125
125
 
@@ -178,11 +178,21 @@ ReactOnRails.configure do |config|
178
178
  # Change to a value like this example to enable this feature
179
179
  # config.components_subdirectory = "ror_components"
180
180
 
181
- # Default configuration to auto loading bundles for components.
182
- # default is false. The default can be overrident as an option in calls to view helpers
181
+ # Default is false.
182
+ # The default can be overidden as an option in calls to view helpers
183
183
  # `render_component` and `render_component_hash`. You may set to true to change the default to auto loading.
184
184
  config.auto_load_bundle = false
185
185
 
186
+ # Default is false
187
+ # Set this to true & instead of trying to import the generated server components into your existing
188
+ # server bundle entrypoint, the PacksGenerator will create a server bundle entrypoint using
189
+ # config.server_bundle_js_file for the filename.
190
+ config.make_generated_server_bundle_the_entrypoint = false
191
+
192
+ # Default is true, which matches Webpacker/Shakapacker's defer default for `append_javascript_pack`
193
+ # Set this to false to have `defer: false` added to your `append_javascript_pack` calls for generated entrypoints.
194
+ config.defer_generated_component_packs = true
195
+
186
196
  ################################################################################
187
197
  # I18N OPTIONS
188
198
  ################################################################################
@@ -210,9 +220,9 @@ ReactOnRails.configure do |config|
210
220
  # ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
211
221
  #
212
222
  # NOTE:
213
- # Instead of using this test helper, you may ensure fresh test files using rails/webpacker via:
214
- # 1. Have `config/webpacker/test.js` exporting an array of objects to configure both client and server bundles.
215
- # 2. Set the compile option to true in config/webpacker.yml for env test
223
+ # Instead of using this test helper, you may ensure fresh test files using Shakapacker via:
224
+ # 1. Have `config/webpack/test.js` exporting an array of objects to configure both client and server bundles.
225
+ # 2. Set the compile option to true in config/shakapacker.yml for env test
216
226
  ################################################################################
217
227
 
218
228
  # If you are using this in your spec_helper.rb (or rails_helper.rb):
@@ -222,15 +232,15 @@ ReactOnRails.configure do |config|
222
232
  # with rspec then this controls what yarn command is run
223
233
  # to automatically refresh your webpack assets on every test run.
224
234
  #
225
- config.build_test_command = "RAILS_ENV=test bin/webpacker"
235
+ config.build_test_command = "RAILS_ENV=test bin/shakapacker"
226
236
 
227
237
  # CONFIGURE YOUR SOURCE FILES
228
238
  # The test helper needs to know where your JavaScript files exist. The value is configured
229
- # by your config/webpacker.yml source_path:
239
+ # by your config/shakapacker.yml source_path:
230
240
  # source_path: client/app # if using recommended /client directory
231
241
  #
232
242
  # Define the files we need to check for webpack compilation when running tests.
233
- # The default is `%w( manifest.json )` as will be sufficient for most webpacker builds.
243
+ # The default is `%w( manifest.json )` as will be sufficient for most shakapacker builds.
234
244
  # However, if you are generating a server bundle that is NOT hashed (present in manifest.json),
235
245
  # then include the file in this list like this:
236
246
  config.webpack_generated_files = %w( server-bundle.js manifest.json )
@@ -257,7 +267,7 @@ module BuildProductionCommand
257
267
  include FileUtils
258
268
  # The call method will be called during assets:precompile
259
269
  def self.call
260
- sh "bin/webpacker"
270
+ sh "bin/shakapacker"
261
271
  end
262
272
  end
263
273
  ```
@@ -1,4 +1,5 @@
1
1
  # Deployment
2
2
 
3
- - `rails/webpacker` puts the necessary precompile steps automatically in the rake precompile step.
4
- - See the [Heroku Deployment](https://www.shakacode.com/react-on-rails/docs/deployment/heroku-deployment/) doc for specifics regarding Heroku. The information for Heroku may apply to other deployments.
3
+ Shakapacker puts the necessary precompile steps automatically in the rake precompile step.
4
+
5
+ See the [Heroku Deployment](https://www.shakacode.com/react-on-rails/docs/deployment/heroku-deployment/) doc for specifics regarding Heroku. The information for Heroku may apply to other deployments.
@@ -1,11 +1,11 @@
1
1
  # File-System-Based Automated Bundle Generation
2
2
 
3
- To use the automated bundle generation feature introduced in React on Rails v13.1.0, please upgrade to use [Shakapacker v6.5.1](https://github.com/shakacode/shakapacker/tree/v6.5.1) at least. If you are currently using webpacker, please follow the migration steps available [here](https://github.com/shakacode/shakapacker/blob/master/docs/v6_upgrade.md).
3
+ To use the automated bundle generation feature introduced in React on Rails v13.1.0, please upgrade to use [Shakapacker v6.5.1](https://github.com/shakacode/shakapacker/tree/v6.5.1) at least. If you are currently using Webpacker, please follow the migration steps available [v6 upgrade](https://github.com/shakacode/shakapacker/blob/master/docs/v6_upgrade.md). Then upgrade to Shakapacker 7 using [v7 upgrade](https://github.com/shakacode/shakapacker/blob/master/docs/v7_upgrade.md) guide.
4
4
 
5
5
  ## Configuration
6
6
 
7
7
  ### Enable nested_entries for Shakapacker
8
- To use the automated bundle generation feature, set `nested_entries: true` in the `webpacker.yml` file like this.
8
+ To use the automated bundle generation feature, set `nested_entries: true` in the `shakapacker.yml` file like this.
9
9
  The generated files will go in a nested directory.
10
10
 
11
11
  ```yml
@@ -44,14 +44,14 @@ React on Rails automatically generates pack files for components to be registere
44
44
  app/javascript/packs/generated
45
45
  ```
46
46
 
47
- *Note: the directory might be different depending on the `source_entry_path` in `config/webpacker.yml`.*
47
+ *Note: the directory might be different depending on the `source_entry_path` in `config/shakapacker.yml`.*
48
48
 
49
49
  ## Usage
50
50
 
51
51
  ### Basic usage
52
52
 
53
53
  #### Background
54
- If the `webpacker.yml` file is configured as instructed [here](https://github.com/shakacode/shakapacker#configuration-and-code), with the following configurations
54
+ If the `shakapacker.yml` file is configured as instructed [here](https://github.com/shakacode/shakapacker#configuration-and-code), with the following configurations
55
55
 
56
56
  ```yml
57
57
  default: &default
@@ -64,6 +64,7 @@ default: &default
64
64
  ```
65
65
 
66
66
  the directory structure will look like this
67
+
67
68
  ```
68
69
  app/javascript:
69
70
  └── packs: # sets up webpack entries
@@ -100,15 +101,15 @@ Your layout would contain:
100
101
  <%= stylesheet_pack_tag 'application' %>
101
102
  ```
102
103
 
104
+ Now suppose you want to use bundle splitting to minimize unnecessary javascript loaded on each page, you would put each of your components in the `packs` directory.
103
105
 
104
- Suppose, you want to use bundle splitting to minimize unnecessary javascript loaded on each page, you would put each of your components in the `packs` directory.
105
106
  ```
106
107
  app/javascript:
107
- └── packs: # sets up webpack entries
108
- │ └── FooComponentOne.jsx # Internally uses ReactOnRails.register
109
- │ └── BarComponentOne.jsx # Internally uses ReactOnRails.register
110
- │ └── BarComponentTwo.jsx # Internally uses ReactOnRails.register
111
- └── src: # any directory name is fine. Referenced files need to be under source_path
108
+ └── packs: # sets up webpack entries
109
+ │ └── FooComponentOne.jsx # Internally uses ReactOnRails.register
110
+ │ └── BarComponentOne.jsx # Internally uses ReactOnRails.register
111
+ │ └── BarComponentTwo.jsx # Internally uses ReactOnRails.register
112
+ └── src: # any directory name is fine. Referenced files need to be under source_path
112
113
  │ └── Foo
113
114
  │ │ └── ...
114
115
  │ └── Bar
@@ -123,58 +124,63 @@ The tricky part is to figure out which bundles to load on any Rails view. [Shaka
123
124
 
124
125
  #### Solution
125
126
 
126
- File-system-based automated pack generation simplifies this process with a new option for the view helpers. The steps to use it in this example are:
127
+ File-system-based automated pack generation simplifies this process with a new option for the view helpers.
127
128
 
128
- 1. Remove parameters passed directly to `javascript_pack_tag` and `stylesheet_pack_tag`.
129
- 2. Remove parameters passed directly to `append_javascript_pack_tag` and `append_stylesheet_pack_tag`.
129
+ For example, if you wanted to utilize our file-system based entrypoint generation for `FooComponentOne` & `BarComponentOne`, but not `BarComponentTwo` (for whatever reason), then...
130
130
 
131
- Your layout would now contain:
131
+ 1. Remove generated entrypoints from parameters passed directly to `javascript_pack_tag` and `stylesheet_pack_tag`.
132
+ 2. Remove generated entrypoints from parameters passed directly to `append_javascript_pack_tag` and `append_stylesheet_pack_tag`.
132
133
 
133
- ```erb
134
- <%= javascript_pack_tag %>
135
- <%= stylesheet_pack_tag %>
136
- ```
134
+ Your layout would now contain:
137
135
 
138
- 3. Create a directory structure as mentioned below:
136
+ ```erb
137
+ <%= javascript_pack_tag('BarComponentTwo') %>
138
+ <%= stylesheet_pack_tag('BarComponentTwo') %>
139
+ ```
139
140
 
140
- ```
141
- app/javascript:
142
- └── packs
143
- └── src:
144
- │ └── Foo
145
- │ │ └── ...
146
- │ │ └── ror_components # configured as `components_subdirectory`
147
- │ │ └── FooComponentOne.jsx
148
- │ └── Bar
149
- │ │ └── ...
150
- │ │ └── ror_components # configured as `components_subdirectory`
151
- │ │ │ └── BarComponentOne.jsx
152
- │ │ │ └── BarComponentTwo.jsx
153
- ```
141
+ 3. Create a directory structure where the components that you want to be auto-generated are within `ReactOnRails.configuration.components_subdirectory`, which should be a subdirectory of `Shakapacker.config.source_path`:
154
142
 
155
- 4. You no longer need to register these React components nor directly add their bundles. For example you can have a Rails view using three components:
143
+ ```
144
+ app/javascript:
145
+ └── packs:
146
+ │ └── BarComponentTwo.jsx # Internally uses ReactOnRails.register
147
+ └── src:
148
+ │ └── Foo
149
+ │ │ └── ...
150
+ │ │ └── ror_components # configured as `components_subdirectory`
151
+ │ │ └── FooComponentOne.jsx
152
+ │ └── Bar
153
+ │ │ └── ...
154
+ │ │ └── ror_components # configured as `components_subdirectory`
155
+ │ │ │ └── BarComponentOne.jsx
156
+ │ │ └── something_else
157
+ │ │ │ └── BarComponentTwo.jsx
158
+ ```
156
159
 
157
- ```erb
160
+ 4. You no longer need to register the React components within the `ReactOnRails.configuration.components_subdirectory` nor directly add their bundles. For example you can have a Rails view using three components:
161
+
162
+ ```erb
163
+ <% append_javascript_pack('BarComponentTwo') %>
158
164
  <%= react_component("FooComponentOne", {}, auto_load_bundle: true) %>
159
165
  <%= react_component("BarComponentOne", {}, auto_load_bundle: true) %>
160
- <%= react_component("BarComponentTwo", {}, auto_load_bundle: true) %>
161
- ```
166
+ <%= react_component("BarComponentTwo", {}) %>
167
+ ```
162
168
 
163
- If `FooComponentOne` uses multiple HTML strings for server rendering, the [`react_component_hash`](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api/#react_component_hash) view helper can be used on the Rails view, as illustrated below.
169
+ If a component uses multiple HTML strings for server rendering, the [`react_component_hash`](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api/#react_component_hash) view helper can be used on the Rails view, as illustrated below.
164
170
 
165
- ```erb
166
- <% foo_component_one_data = react_component_hash("FooComponentOne",
167
- prerender: true,
168
- auto_load_bundle: true
169
- props: {}
170
- ) %>
171
- <% content_for :title do %>
172
- <%= foo_component_one_data['title'] %>
173
- <% end %>
174
- <%= foo_component_one_data["componentHtml"] %>
175
- ```
171
+ ```erb
172
+ <% foo_component_one_data = react_component_hash("FooComponentOne",
173
+ prerender: true,
174
+ auto_load_bundle: true
175
+ props: {}
176
+ ) %>
177
+ <% content_for :title do %>
178
+ <%= foo_component_one_data['title'] %>
179
+ <% end %>
180
+ <%= foo_component_one_data["componentHtml"] %>
181
+ ```
176
182
 
177
- The default value of the `auto_load_bundle` parameter can be specified by setting `config.auto_load_bundle` in `config/initializers/react_on_rails.rb` and thus removed from each call to `react_component`.
183
+ The default value of the `auto_load_bundle` parameter can be specified by setting `config.auto_load_bundle` in `config/initializers/react_on_rails.rb` and thus removed from each call to `react_component`.
178
184
 
179
185
  ### Server Rendering and Client Rendering Components
180
186
 
@@ -186,6 +192,6 @@ Once generated, all server entrypoints will be imported into a file named `[Reac
186
192
 
187
193
  ### Using Automated Bundle Generation Feature with already defined packs
188
194
 
189
- To use the Automated Bundle Generation feature with already defined packs, `config/initializers/react_on_rails` should explicitly be configured with `config.auto_load_bundle = false` and you can explicitly pass `auto_load_bundle` option in [`react_component`](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api/#react_component) and [`react_component_hash`](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api/#react_component_hash) for the components using this feature.
195
+ As of version 13.3.4, bundles inside of directories that match `config.components_subdirectory` will be automatically added as entrypoints, while bundles outside of those directories will have to be manually added to the Shakapacker.config.source_entry_path or Webpack's `entry` rules.
190
196
 
191
197
 
@@ -1,6 +1,6 @@
1
1
  # HMR and Hot Reloading with the webpack-dev-server
2
2
 
3
- The webpack-dev-server provides:
3
+ The `webpack-dev-server` provides:
4
4
 
5
5
  1. Speedy compilation of client side assets
6
6
  2. Optional HMR which means that the page will reload automatically when after
@@ -11,17 +11,17 @@ 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/webpacker-dev-server`
14
+ then you can follow all the regular docs for using the `bin/shakapacker-dev-server`
15
15
  during development.
16
16
 
17
- # Server Side Rendering with the Default rails/webpacker bin/webpacker-dev-server
17
+ # Server Side Rendering with the Default shakacode/shakapacker bin/shakapacker-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
21
21
  rendering.
22
22
 
23
23
  ## If you use the same Webpack setup for your server and client bundles
24
- If you do use the webpack-dev-server for prerendering, be sure to set the
24
+ If you do use the `webpack-dev-server` for prerendering, be sure to set the
25
25
  `config/initializers/react_on_rails.rb` setting of
26
26
 
27
27
  ```
@@ -36,13 +36,13 @@ This must also be false.
36
36
 
37
37
  If you don't configure these two to false, you'll see errors like:
38
38
 
39
- * "ReferenceError: window is not defined" (if hmr is true)
40
- * "TypeError: Cannot read property 'prototype' of undefined" (if inline is true)
39
+ * `"ReferenceError: window is not defined" (if hmr is true)`
40
+ * `"TypeError: Cannot read property 'prototype' of undefined" (if inline is true)`
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/webpacker-dev-server`
45
- 1. In `config/webpacker.yml` set **hmr** and **inline** `dev_server` properties to true.
44
+ To enable HMR functionality you have to use `./bin/shakapacker-dev-server`
45
+ 1. In `config/shakapacker.yml` set **hmr** and **inline** `dev_server` properties to true.
46
46
  ```
47
47
  dev_server:
48
48
  https: false
@@ -57,7 +57,7 @@ To enable HMR functionality you have to use `./bin/webpacker-dev-server`
57
57
  2. Add react refresh packages:
58
58
  ` yarn add @pmmmwh/react-refresh-webpack-plugin react-refresh -D`
59
59
 
60
- 3. HMR is for use with the webpack-dev-server, so we only add this for the webpack-dev-server.
60
+ 3. HMR is for use with the `webpack-dev-server`, so we only add this for the `webpack-dev-server`.
61
61
  ```
62
62
  const { devServer } = require('shakapacker')
63
63
 
@@ -75,7 +75,7 @@ To enable HMR functionality you have to use `./bin/webpacker-dev-server`
75
75
  )
76
76
  }
77
77
  ```
78
- We added overlay.sockedPort option in `ReactRefreshWebpackPlugin` to match the webpack dev-server port specified in config/webpacker.yml. Thats way we make sockjs works properly and suppress error in browser console `GET http://localhost:[port]/sockjs-node/info?t=[xxxxxxxxxx] 404 (Not Found)`.
78
+ We added overlay.sockedPort option in `ReactRefreshWebpackPlugin` to match the webpack dev-server port specified in `config/shakapacker.yml`. Thats way we make sockjs works properly and suppress error in browser console `GET http://localhost:[port]/sockjs-node/info?t=[xxxxxxxxxx] 404 (Not Found)`.
79
79
 
80
80
  4. Add react-refresh plugin in `babel.config.js`
81
81
  ```