react_on_rails 11.0.5 → 13.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +338 -0
- data/.eslintignore +2 -1
- data/.eslintrc +32 -3
- data/.github/FUNDING.yml +1 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +23 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +19 -0
- data/.github/workflows/lint-js-and-ruby.yml +54 -0
- data/.github/workflows/main.yml +183 -0
- data/.github/workflows/package-js-tests.yml +35 -0
- data/.github/workflows/rspec-package-specs.yml +46 -0
- data/.gitignore +3 -4
- data/.prettierignore +14 -0
- data/.prettierrc +20 -0
- data/.rubocop.yml +76 -34
- data/.travis.yml +15 -22
- data/CHANGELOG.md +443 -55
- data/CONTRIBUTING.md +62 -80
- data/Gemfile +1 -35
- data/Gemfile.development_dependencies +50 -0
- data/KUDOS.md +4 -1
- data/{docs/LICENSE.md → LICENSE.md} +1 -1
- data/NEWS.md +14 -4
- data/REACT-ON-RAILS-PRO-LICENSE +95 -0
- data/README.md +107 -802
- data/Rakefile +1 -8
- data/SUMMARY.md +51 -29
- data/book.json +5 -5
- data/docs/{basics/generator.md → additional-details/generator-details.md} +5 -13
- data/docs/{basics/installation-overview.md → additional-details/manual-installation-overview.md} +9 -14
- data/docs/{basics → additional-details}/migrating-from-react-rails.md +1 -1
- data/docs/additional-details/recommended-project-structure.md +69 -0
- data/docs/additional-details/tips-for-usage-with-sp6.md +15 -0
- data/docs/additional-details/upgrade-webpacker-v3-to-v4.md +10 -0
- data/docs/api/javascript-api.md +35 -6
- data/docs/api/redux-store-api.md +102 -0
- data/docs/api/view-helpers-api.md +133 -0
- data/docs/contributor-info/errors-with-hooks.md +45 -0
- data/docs/contributor-info/linters.md +5 -6
- data/docs/contributor-info/pull-requests.md +42 -0
- data/docs/contributor-info/releasing.md +1 -1
- data/docs/deployment/heroku-deployment.md +39 -0
- data/docs/getting-started.md +196 -0
- data/docs/guides/client-vs-server-rendering.md +27 -0
- data/docs/guides/configuration.md +289 -0
- data/docs/guides/deployment.md +5 -0
- data/docs/guides/file-system-based-automated-bundle-generation.md +197 -0
- data/docs/guides/hmr-and-hot-reloading-with-the-webpack-dev-server.md +104 -0
- data/docs/guides/how-react-on-rails-works.md +44 -0
- data/docs/guides/how-to-conditionally-server-render-based-on-device-type.md +40 -0
- data/docs/guides/how-to-use-different-files-for-client-and-server-rendering.md +98 -0
- data/docs/guides/i18n.md +87 -0
- data/docs/guides/installation-into-an-existing-rails-app.md +66 -0
- data/docs/guides/minitest-configuration.md +31 -0
- data/docs/guides/rails-webpacker-react-integration-options.md +213 -0
- data/docs/guides/react-on-rails-overview.md +29 -0
- data/docs/guides/react-server-rendering.md +32 -0
- data/docs/guides/render-functions-and-railscontext.md +205 -0
- data/docs/guides/rspec-configuration.md +73 -0
- data/docs/guides/tutorial.md +371 -0
- data/docs/{basics → guides}/upgrading-react-on-rails.md +126 -3
- data/docs/guides/webpack-configuration.md +42 -0
- data/docs/home.md +23 -0
- data/docs/javascript/asset-pipeline.md +12 -0
- data/docs/{additional-reading → javascript}/code-splitting.md +21 -11
- data/docs/javascript/converting-from-custom-webpack-config-to-rails-webpacker-config.md +10 -0
- data/docs/javascript/credits.md +10 -0
- data/docs/{additional-reading → javascript}/images.md +5 -6
- data/docs/javascript/react-helmet.md +100 -0
- data/docs/javascript/react-router.md +90 -0
- data/docs/{additional-reading → javascript}/server-rendering-tips.md +15 -12
- data/docs/javascript/troubleshooting-when-using-shakapacker.md +77 -0
- data/docs/{additional-reading → javascript}/webpack.md +2 -2
- data/docs/misc/articles.md +20 -0
- data/docs/misc/doctrine.md +5 -6
- data/docs/outdated/deferred-rendering.md +39 -0
- data/docs/{additional-reading → outdated}/rails-assets-relative-paths.md +4 -4
- data/docs/{additional-reading → outdated}/rails-assets.md +12 -20
- data/docs/{misc → outdated}/rails3.md +2 -2
- data/docs/rails/convert-rails-5-api-only-app.md +19 -0
- data/docs/rails/rails-engine-integration.md +32 -0
- data/docs/{additional-reading → rails}/rails_view_rendering_from_inline_javascript.md +2 -1
- data/docs/{additional-reading → rails}/turbolinks.md +13 -1
- data/docs/react-on-rails-pro/react-on-rails-pro.md +43 -0
- data/docs/testimonials/hvmn.md +25 -0
- data/docs/testimonials/resortpass.md +13 -0
- data/docs/testimonials/testimonials.md +28 -0
- data/jest.config.js +4 -0
- data/lib/generators/USAGE +1 -1
- data/lib/generators/react_on_rails/adapt_for_older_shakapacker_generator.rb +41 -0
- data/lib/generators/react_on_rails/base_generator.rb +55 -43
- data/lib/generators/react_on_rails/bin/dev +30 -0
- data/lib/generators/react_on_rails/bin/dev-static +30 -0
- data/lib/generators/react_on_rails/dev_tests_generator.rb +4 -3
- data/lib/generators/react_on_rails/generator_helper.rb +8 -6
- data/lib/generators/react_on_rails/generator_messages.rb +40 -0
- data/lib/generators/react_on_rails/install_generator.rb +37 -0
- data/lib/generators/react_on_rails/templates/.eslintrc +3 -1
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +4 -6
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-static +9 -0
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +21 -40
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css +4 -0
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorldServer.js +5 -0
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/packs/server-bundle.js +8 -0
- data/lib/generators/react_on_rails/templates/base/base/app/views/layouts/hello_world.html.erb +2 -1
- data/lib/generators/react_on_rails/templates/base/base/babel.config.js.tt +32 -0
- data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +20 -4
- data/lib/generators/react_on_rails/templates/base/base/config/shakapacker.yml +62 -0
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/clientWebpackConfig.js.tt +17 -0
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt +17 -0
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/development.js.tt +25 -0
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/production.js.tt +9 -0
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/serverWebpackConfig.js.tt +117 -0
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/test.js.tt +9 -0
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/webpack.config.js.tt +15 -0
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/webpackConfig.js.tt +36 -0
- data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +8 -2
- data/lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb +1 -1
- data/lib/generators/react_on_rails/templates/dev_tests/spec/{features → system}/hello_world_spec.rb +2 -2
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +6 -9
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/store/helloWorldStore.js +1 -3
- data/lib/react_on_rails/configuration.rb +198 -145
- data/lib/react_on_rails/error.rb +2 -0
- data/lib/react_on_rails/git_utils.rb +5 -3
- data/lib/react_on_rails/{react_on_rails_helper.rb → helper.rb} +201 -190
- data/lib/react_on_rails/json_output.rb +1 -1
- data/lib/react_on_rails/json_parse_error.rb +28 -0
- data/lib/react_on_rails/locales/base.rb +169 -0
- data/lib/react_on_rails/locales/to_js.rb +33 -0
- data/lib/react_on_rails/locales/to_json.rb +23 -0
- data/lib/react_on_rails/packs_generator.rb +234 -0
- data/lib/react_on_rails/prerender_error.rb +35 -27
- data/lib/react_on_rails/react_component/render_options.rb +64 -9
- data/lib/react_on_rails/server_rendering_js_code.rb +55 -0
- data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +126 -76
- data/lib/react_on_rails/server_rendering_pool.rb +0 -1
- data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +9 -8
- data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +17 -0
- data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +13 -12
- data/lib/react_on_rails/test_helper.rb +24 -3
- data/lib/react_on_rails/utils.rb +94 -25
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/react_on_rails/version_checker.rb +5 -1
- data/lib/react_on_rails/version_syntax_converter.rb +14 -12
- data/lib/react_on_rails/webpacker_utils.rb +105 -5
- data/lib/react_on_rails.rb +8 -2
- data/lib/tasks/assets.rake +28 -60
- data/lib/tasks/generate_packs.rake +11 -0
- data/lib/tasks/locale.rake +5 -4
- data/package-scripts.yml +49 -0
- data/package.json +52 -47
- data/rakelib/docker.rake +0 -5
- data/rakelib/dummy_apps.rake +5 -8
- data/rakelib/example_type.rb +12 -3
- data/rakelib/examples.rake +5 -4
- data/rakelib/lint.rake +5 -16
- data/rakelib/node_package.rake +2 -2
- data/rakelib/release.rake +37 -23
- data/rakelib/run_rspec.rake +16 -44
- data/rakelib/task_helpers.rb +16 -4
- data/react_on_rails.gemspec +6 -22
- data/tsconfig.json +14 -0
- data/webpackConfigLoader.js +5 -4
- data/yarn.lock +5935 -3106
- metadata +122 -272
- data/Gemfile.rails32 +0 -74
- data/docs/additional-reading/asset-pipeline.md +0 -20
- data/docs/additional-reading/babel.md +0 -5
- data/docs/additional-reading/caching-and-performance.md +0 -4
- data/docs/additional-reading/heroku-deployment.md +0 -92
- data/docs/additional-reading/hot-reloading-rails-development.md +0 -57
- data/docs/additional-reading/node-server-rendering.md +0 -5
- data/docs/additional-reading/rails-engine-integration.md +0 -34
- data/docs/additional-reading/react-helmet.md +0 -80
- data/docs/additional-reading/react-router.md +0 -113
- data/docs/additional-reading/recommended-project-structure.md +0 -49
- data/docs/additional-reading/rspec-configuration.md +0 -56
- data/docs/additional-reading/webpack-dev-server.md +0 -15
- data/docs/api/ruby-api-hot-reload-view-helpers.md +0 -44
- data/docs/api/ruby-api.md +0 -8
- data/docs/basics/configuration.md +0 -163
- data/docs/basics/i18n.md +0 -77
- data/docs/tutorial.md +0 -220
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-server +0 -12
- data/lib/react_on_rails/assets_precompile.rb +0 -150
- data/lib/react_on_rails/locales_to_js.rb +0 -134
- data/ruby-lint.yml +0 -25
- /data/docs/{additional-reading → additional-details}/updating-dependencies.md +0 -0
- /data/docs/{additional-reading → deployment}/elastic-beanstalk.md +0 -0
- /data/docs/{additional-reading → javascript}/angular-js-integration-migration.md +0 -0
- /data/docs/{additional-reading → javascript}/capistrano-deployment.md +0 -0
- /data/docs/{additional-reading → javascript}/foreman-issues.md +0 -0
- /data/docs/{additional-reading → javascript}/node-dependencies-and-npm.md +0 -0
- /data/docs/{additional-reading → javascript}/react-and-redux.md +0 -0
- /data/docs/{additional-reading → javascript}/troubleshooting-when-using-webpacker.md +0 -0
- /data/docs/{additional-reading → javascript}/webpack-v1-notes.md +0 -0
- /data/docs/{coding-style → misc}/style.md +0 -0
- /data/docs/{additional-reading → misc}/tips.md +0 -0
@@ -0,0 +1,77 @@
|
|
1
|
+
# Client rendering crashes when configuring `optimization.runtimeChunk` to `multiple`
|
2
|
+
|
3
|
+
## Context
|
4
|
+
|
5
|
+
1. Ruby version: 3.1
|
6
|
+
2. Rails version: 7.0.6
|
7
|
+
3. Shakapacker version: 6.6.0
|
8
|
+
4. React on Rails version: 13.3.5
|
9
|
+
|
10
|
+
## The failure
|
11
|
+
|
12
|
+
Configuring Webpack to embed the runtime in each chunk and calling `react_component` twice in a rails view/partial causes the client render to crash with the following error:
|
13
|
+
|
14
|
+
```
|
15
|
+
Could not find component registered with name XXX. Registered component names include [ YYY ]. Maybe you forgot to register the component?
|
16
|
+
```
|
17
|
+
|
18
|
+
```
|
19
|
+
VM4859 clientStartup.js:132 Uncaught Error: ReactOnRails encountered an error while rendering component: XXX. See above error message.
|
20
|
+
at Object.get (ComponentRegistry.js:40:15)
|
21
|
+
at Object.getComponent (ReactOnRails.js:211:44)
|
22
|
+
at render (VM4859 clientStartup.js:103:53)
|
23
|
+
at forEachReactOnRailsComponentRender (VM4859 clientStartup.js:138:9)
|
24
|
+
at reactOnRailsPageLoaded (VM4859 clientStartup.js:164:5)
|
25
|
+
at renderInit (VM4859 clientStartup.js:205:9)
|
26
|
+
at onPageReady (VM4859 clientStartup.js:234:9)
|
27
|
+
at HTMLDocument.onReadyStateChange (VM4859 clientStartup.js:238:13)
|
28
|
+
```
|
29
|
+
|
30
|
+
## Configs
|
31
|
+
|
32
|
+
### Webpack configuration
|
33
|
+
|
34
|
+
```js
|
35
|
+
optimization: {
|
36
|
+
runtimeChunk: 'multiple'
|
37
|
+
},
|
38
|
+
```
|
39
|
+
|
40
|
+
### Rails view
|
41
|
+
|
42
|
+
```haml
|
43
|
+
= react_component("XXX", props: @props)
|
44
|
+
= yield
|
45
|
+
= react_component("YYY", props: @props)
|
46
|
+
```
|
47
|
+
|
48
|
+
## The problem
|
49
|
+
|
50
|
+
Configuring Webpack to embed the runtime in each chunk and calling `react_component` twice in a rails view/partial causes the client render to crash.
|
51
|
+
|
52
|
+
Read more at https://github.com/shakacode/react_on_rails/issues/1558.
|
53
|
+
|
54
|
+
## Solution
|
55
|
+
|
56
|
+
To overcome this issue, we could use [shakapacker](https://github.com/shakacode/shakapacker)'s default optimization configuration (pseudo-code):
|
57
|
+
|
58
|
+
```js
|
59
|
+
const { webpackConfig: baseClientWebpackConfig } = require('shakapacker');
|
60
|
+
|
61
|
+
// ...
|
62
|
+
|
63
|
+
config.optimization = baseClientWebpackConfig.optimization;
|
64
|
+
```
|
65
|
+
As it set the `optimization.runtimeChunk` to `single`. See its source:
|
66
|
+
|
67
|
+
`package/environments/base.js:115`
|
68
|
+
```js
|
69
|
+
optimization: {
|
70
|
+
splitChunks: { chunks: 'all' },
|
71
|
+
|
72
|
+
runtimeChunk: 'single'
|
73
|
+
},
|
74
|
+
```
|
75
|
+
https://github.com/shakacode/shakapacker/blob/cdf32835d3e0949952b8b4b53063807f714f9b24/package/environments/base.js#L115-L119
|
76
|
+
|
77
|
+
Or set `optimization.runtimeChunk` to `single` directly.
|
@@ -18,5 +18,5 @@ Webpack v2 makes this very convenient! See:
|
|
18
18
|
* [Implicit Common Vendor Chunk](https://webpack.js.org/guides/code-splitting-libraries/#implicit-common-vendor-chunk)
|
19
19
|
* [Manifest File](https://webpack.js.org/guides/code-splitting-libraries/#manifest-file)
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
## Webpack v4
|
22
|
+
Webpack v4 is heartily recommended. If you need help with migrating your project to Webpack v4, please contact me, [justin@shakacode.com](mailto:justin@shakacode.com).
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Articles, Videos, and Podcasts
|
2
|
+
|
3
|
+
## Articles
|
4
|
+
|
5
|
+
* [Introducing React on Rails v9 with Webpacker Support](https://blog.shakacode.com/introducing-react-on-rails-v9-with-webpacker-support-f2584c6c8fa4) for an overview of the integration of React on Rails with Webpacker.
|
6
|
+
* [Webpacker Lite: Why Fork Webpacker?](https://blog.shakacode.com/webpacker-lite-why-fork-webpacker-f0a7707fac92)
|
7
|
+
* [React on Rails, 2000+ 🌟 Stars](https://medium.com/shakacode/react-on-rails-2000-stars-32ff5cfacfbf#.6gmfb2gpy)
|
8
|
+
* [The React on Rails Doctrine](https://medium.com/@railsonmaui/the-react-on-rails-doctrine-3c59a778c724)
|
9
|
+
* [Simple Tutorial](https://www.shakacode.com/react-on-rails/docs/guides/tutorial/).
|
10
|
+
|
11
|
+
## Videos
|
12
|
+
|
13
|
+
* [Video of running the v9 installer with Webpacker v3](https://youtu.be/M0WUM_XPaII). History, motivations, philosophy, and overview.
|
14
|
+
1. [GORUCO 2017: Front-End Sadness to Happiness: The React on Rails Story by Justin Gordon](https://www.youtube.com/watch?v=SGkTvKRPYrk)
|
15
|
+
2. [egghead.io: Creating a component with React on Rails](https://egghead.io/lessons/react-creating-a-component-with-react-on-rails)
|
16
|
+
3. [egghead.io: Creating a redux component with React on Rails](https://egghead.io/lessons/react-add-redux-state-management-to-a-react-on-rails-project)
|
17
|
+
4. [React On Rails Tutorial Series](https://www.youtube.com/playlist?list=PL5VAKH-U1M6dj84BApfUtvBjvF-0-JfEU)
|
18
|
+
1. [History and Motivation](https://youtu.be/F4oymbUHvoY)
|
19
|
+
2. [Basic Tutorial Walkthrough](https://youtu.be/_bjScw60FBk)
|
20
|
+
3. [Code Walkthrough](https://youtu.be/McQ9UM-_ocQ)
|
data/docs/misc/doctrine.md
CHANGED
@@ -4,7 +4,7 @@ By Justin Gordon, January 26, 2016
|
|
4
4
|
|
5
5
|
This document is an extension and complement to [The Rails Doctrine](http://rubyonrails.org/doctrine/). If you haven't read that document, I suggest you do so first.
|
6
6
|
|
7
|
-
As stated in the [React on Rails README](
|
7
|
+
As stated in the [React on Rails README](https://www.shakacode.com/react-on-rails/docs/), the project objective is to provide an opinionated and optimal framework for integrating **Ruby on Rails** with modern JavaScript tooling and libraries. When considering what goes into **react_on_rails**, we ask ourselves, is the functionality related to the intersection of using Rails and with modern JavaScript? A good example is view helper integration of React components on a Rails view. If the answer is yes, then the functionality belongs right here. In other cases, we're releasing separate npm packages or Ruby gems. For example, we needed an easy way to integrate [Twitter Bootstrap](http://getbootstrap.com/) with Webpack, and we released the [npm bootstrap-loader](https://github.com/shakacode/bootstrap-loader/).
|
8
8
|
|
9
9
|
Besides the project objective, let's stick with the "Rails Doctrine" and keep the following in mind.
|
10
10
|
|
@@ -19,15 +19,14 @@ The React on Rails setup provides several key components related to front-end de
|
|
19
19
|
6. Happiness for us is actively participating in open source, so we want to be where the action is, which is with the npm libraries on github.com.
|
20
20
|
7. You can get set up on React on Rails **FAST** using our application generator.
|
21
21
|
8. By placing all client-side development inside of the `/client` directory, pure JavaScript developers can productively do development separate from Rails. Instead of Rails APIs, stub APIs on an express server can provide a simple backend, allowing for rapid iteration of UI prototypes.
|
22
|
-
9. Just because we're not relying on the Rails asset pipeline for ES6 conversion does not mean that we're deploying Rails apps in any different way. We still use the asset pipeline to include our Webpack compiled JavaScript. This only requires a few small modifications, as explained in our
|
22
|
+
9. Just because we're not relying on the Rails asset pipeline for ES6 conversion does not mean that we're deploying Rails apps in any different way. We still use the asset pipeline to include our Webpack compiled JavaScript. This only requires a few small modifications, as explained in [our heroku deployment documentation](https://www.shakacode.com/react-on-rails/docs/deployment/heroku-deployment/).
|
23
23
|
|
24
24
|
## Convention over Configuration
|
25
25
|
* React on Rails has taken the hard work out of figuring out the JavaScript tooling that works best with Rails. Not only could you spend lots of time researching different tooling, but then you'd have to figure out how to splice it all together. This is where a lot of "JavaScript fatigue" comes from. The following keep the code clean and consistent:
|
26
|
-
* [Style Guide](
|
27
|
-
* [linters](
|
28
|
-
* [Recommended Project Structure](../additional-reading/recommended-project-structure.md)
|
26
|
+
* [Style Guide](https://www.shakacode.com/react-on-rails/docs/misc/style/)
|
27
|
+
* [linters](https://www.shakacode.com/react-on-rails/docs/contributor-info/linters/)
|
29
28
|
|
30
|
-
We're big believers in this quote from the Rails Doctrine:
|
29
|
+
We're big believers in this quote from the Rails Doctrine:
|
31
30
|
|
32
31
|
> The same goes even when you understand how all the pieces go together. When there’s an obvious next step for every change, we can scoot through the many parts of an application that is the same or very similar to all the other applications that went before it. A place for everything and everything in its place. Constraints liberate even the most able minds.
|
33
32
|
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Deferred Rendering
|
2
|
+
|
3
|
+
Please see [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro/] if you are interested in code splitting using
|
4
|
+
[loadable-components.com](https://loadable-components.com/docs) with React on Rails.
|
5
|
+
|
6
|
+
-----
|
7
|
+
|
8
|
+
What is code splitting? From the webpack documentation:
|
9
|
+
|
10
|
+
> For big web apps it’s not efficient to put all code into a single file, especially if some blocks of code are only required under some circumstances. Webpack has a feature to split your codebase into “chunks” which are loaded on demand. Some other bundlers call them “layers”, “rollups”, or “fragments”. This feature is called “code splitting”.
|
11
|
+
|
12
|
+
## Server Rendering and Code Splitting
|
13
|
+
|
14
|
+
Let's say you're requesting a page that needs to fetch a code chunk from the server before it's able to render. If you do all your rendering on the client side, you don't have to do anything special. However, if the page is rendered on the server, you'll find that React will spit out the following error:
|
15
|
+
|
16
|
+
> Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:
|
17
|
+
|
18
|
+
> (client) <!-- react-empty: 1 -
|
19
|
+
|
20
|
+
> (server) <div data-reactroot="
|
21
|
+
<!--This comment is here because the comment beginning on line 13 messes up Sublime's markdown parsing-->
|
22
|
+
|
23
|
+
Different markup is generated on the client than on the server. Why does this happen? When you register a component or Render-Function with `ReactOnRails.register`, React on Rails will by default render the component as soon as the page loads. However, code splitting requires that components render at a later time when the JavaScript chunks have loaded.
|
24
|
+
|
25
|
+
## Solution
|
26
|
+
|
27
|
+
To prevent this, you have to wait until the code chunk is fetched before doing the initial render on the client side. To accomplish this, react on rails allows you to register a renderer. This works just like registering a Render-Function, except that the function you pass takes three arguments: `renderer(props, railsContext, domNodeId)`, and is responsible for calling `ReactDOM.render` or `ReactDOM.hydrate` to render the component to the DOM. React on rails will automatically detect when a Render-Function takes three arguments, and will **not** call `ReactDOM.render` or `ReactDOM.hydrate`, instead allowing you to control the initial render yourself. Note, you have to be careful to call `ReactDOM.hydrate` rather than `ReactDOM.render` if you are are server rendering.
|
28
|
+
|
29
|
+
|
30
|
+
## Server vs. Client Code Caveats
|
31
|
+
|
32
|
+
If you're going to try to do code splitting with server rendered routes, you'll probably need to use seperate route definitions for client and server to prevent code splitting from happening for the server bundle. The server bundle should be one file containing all the JavaScript code. This will require you to have seperate webpack configurations for client and server.
|
33
|
+
|
34
|
+
Do not attempt to register a renderer function on the server. Instead, register either a Render-Function or a component. If you register a renderer in the server bundle, you'll get an error when react on rails tries to server render the component.
|
35
|
+
|
36
|
+
|
37
|
+
## React on Rails Pro
|
38
|
+
[React on Rails Pro](https://www.shakacode.com/react-on-rails-pro/] includes a complete setup using this technique for code splitting using
|
39
|
+
[loadable-components.com](https://loadable-components.com/docs) with React on Rails.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
*Note: this doc
|
1
|
+
*Note: this doc reflects using Sprockets for assets and has not been updated for Shakapacker or rails/webpacker*
|
2
2
|
|
3
3
|
# Using Webpack bundled assets with the Rails Asset Pipeline
|
4
4
|
|
@@ -77,7 +77,7 @@ Note: _You can output these files in the asset pipeline wherever you see fit. My
|
|
77
77
|
|
78
78
|
Lastly, we will set the publicPath to our file(s). This will be the endpoint on our rails web server that you can visit to reach the asset (if you don't know how this works, read the [intro](#using-webpack-bundled-assets-with-the-rails-asset-pipeline)). If you've been following the previous steps, you know that we set our outputPath for our assets to be absolute at `app/assets/webpack/webpack-assets/`, which your rails app should end up hosting at `/assets/webpack-assets/file-name+hash.ext` when the server is run.
|
79
79
|
|
80
|
-
Note: _If you're having a hard time figuring out what an asset's path will be on your rails server, simply run `rake assets:precompile` and `cd public/`. The path from there to your file will then be the path/url on your web server to that asset. On top of this, it is also a good idea to check out [this doc](
|
80
|
+
Note: _If you're having a hard time figuring out what an asset's path will be on your rails server, simply run `rake assets:precompile` and `cd public/`. The path from there to your file will then be the path/url on your web server to that asset. On top of this, it is also a good idea to check out [this doc](https://www.shakacode.com/react-on-rails/docs/outdated/rails-assets/) to understand how `react_on_rails` allows us to access these files after precompilation, when Rails applies another hash onto the asset._
|
81
81
|
|
82
82
|
Our publicPath setting will match the path to our outputted assets on our rails web server. Given our assets in this example will be outputted to `/app/assets/webpack/webpack-assets/` and hosted at `/assets/webpack-assets/`, our publicPath would be:
|
83
83
|
|
@@ -179,7 +179,7 @@ module.exports = {
|
|
179
179
|
// The important stuff
|
180
180
|
test: /\.(jpg|jpeg|png)(\?.*)?$/, // Load only .jpg .jpeg, and .png files
|
181
181
|
use: {
|
182
|
-
loader: 'file-loader',
|
182
|
+
loader: 'file-loader',
|
183
183
|
options: {
|
184
184
|
name: '[name][md5:hash].[ext]', // Name of bundled asset
|
185
185
|
outputPath: 'webpack-assets/', // Output location for assets. Final: `app/assets/webpack/webpack-assets/`
|
@@ -192,4 +192,4 @@ module.exports = {
|
|
192
192
|
};
|
193
193
|
```
|
194
194
|
|
195
|
-
If you'd like to understand how react_on_rails handles these bundled assets after asset precompilation and in production mode, check out: [Rails Assets](
|
195
|
+
If you'd like to understand how react_on_rails handles these bundled assets after asset precompilation and in production mode, check out: [Rails Assets](https://www.shakacode.com/react-on-rails/docs/outdated/rails-assets/).
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# Rails assets and the Extract Text Plugin
|
2
2
|
|
3
|
+
*This doc needs updating for the use of Shakapacker or rails/webpacker with React on Rails*
|
4
|
+
|
3
5
|
The [Webpack file loader](https://github.com/webpack/file-loader) copies referenced files to
|
4
6
|
the destination output directory, with an MD5 hash. The other term for this is a "digest".
|
5
7
|
|
@@ -11,41 +13,31 @@ CSS and fonts for CSS. However, this applies to any file that might be processed
|
|
11
13
|
Webpack file loader.
|
12
14
|
|
13
15
|
## The Problem
|
14
|
-
To understand the problem, it helps to read this article:
|
16
|
+
To understand the problem, it helps to read this article:
|
15
17
|
[What is fingerprinting and why should I care](http://guides.rubyonrails.org/asset_pipeline.html#what-is-fingerprinting-and-why-should-i-care-questionmark)
|
16
18
|
Basically, when Rails prepares assets for production deployments, it also adds a digest
|
17
|
-
to the file names. E.g., `img1.jpg` becomes `img1-dbu097452jf2v2.jpg`.
|
19
|
+
to the file names. E.g., `img1.jpg` becomes `img1-dbu097452jf2v2.jpg`.
|
18
20
|
|
19
|
-
When compiling its native css Rails transforms all urls and links to digested
|
20
|
-
versions, i.e. `background-image: image-url(img1.jpg)` becomes
|
21
|
-
`background-image: url(img1-dbu097452jf2v2.jpg)`. However this doesn't happen for js and
|
22
|
-
css files compiled by webpack on the client side, because they don't use
|
21
|
+
When compiling its native css Rails transforms all urls and links to digested
|
22
|
+
versions, i.e. `background-image: image-url(img1.jpg)` becomes
|
23
|
+
`background-image: url(img1-dbu097452jf2v2.jpg)`. However this doesn't happen for js and
|
24
|
+
css files compiled by webpack on the client side, because they don't use
|
23
25
|
`image-url` and `asset-url`. Without some fix, these assets would fail to load.
|
24
26
|
|
25
|
-
When Webpack's client JavaScript uses images in render methods, e.g. `<img src='...' />` or
|
27
|
+
When Webpack's client JavaScript uses images in render methods, e.g. `<img src='...' />` or
|
26
28
|
in css, e.g. `background-image: url(...)` The code (such as the CSS) generated by the Webpack
|
27
29
|
will have the Webpack digested name (MD5 hash). Since the Webpack generated CSS expects
|
28
30
|
just one level of "digesting", this "double-digesting" from Rails will cause such these assets
|
29
31
|
fail to load.
|
30
32
|
|
31
|
-
_If you are interested in learning how to use assets in your React components, read this doc: [Webpack, the Asset Pipeline, and Using Assets w/ React](
|
33
|
+
_If you are interested in learning how to use assets in your React components, read this doc: [Webpack, the Asset Pipeline, and Using Assets w/ React](https://www.shakacode.com/react-on-rails/docs/outdated/rails-assets-relative-paths/)_
|
32
34
|
|
33
35
|
## The Solution: Symlink Original File Names to New File Names
|
34
|
-
|
35
|
-
|
36
|
-
implemented using `assets:precompile` after-hook in
|
37
|
-
file [lib/tasks/assets.rake](../../lib/tasks/assets.rake)
|
38
|
-
The assets for symlinking are defined by `config.symlink_non_digested_assets_regex` in
|
39
|
-
`config/initializers/react_on_rails.rb`.
|
40
|
-
|
41
|
-
## Disabling the Symlinking
|
42
|
-
To disable symlinks set this parameter to `nil`.
|
43
|
-
|
36
|
+
_Note, this solution was removed in v14. If you're intersted in this symlink solution, please create
|
37
|
+
a github issue._
|
44
38
|
|
45
39
|
## Example from /spec/dummy
|
46
40
|
|
47
|
-
If you run
|
48
|
-
|
49
41
|
```
|
50
42
|
cd spec/dummy
|
51
43
|
RAILS_ENV=production bundle exec rake assets:precompile
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# Rails 3
|
2
2
|
|
3
|
-
* Please let us know if you find any issues with Rails 3.
|
3
|
+
* Please let us know if you find any issues with Rails 3.
|
4
4
|
* Rails 3 is confirmed to work up with versions up to 6.8.x.
|
5
5
|
* We are not testing it for new releases. If you find an issue, you will have to submit a PR to get it fixed.
|
6
6
|
|
7
7
|
## Known Issues
|
8
8
|
|
9
|
-
1. If you do not skip bootstrap for the generator, you cannot generate a working app, as bootstrap-sass does not
|
9
|
+
1. If you do not skip bootstrap for the generator, you cannot generate a working app, as bootstrap-sass does not support Rails 3, or at least the version we're using.
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Convert Rails 5 API only app to a Rails app
|
2
|
+
|
3
|
+
1. Go to the directory where you created your app
|
4
|
+
|
5
|
+
```bash
|
6
|
+
$ rails new your-current-app-name
|
7
|
+
```
|
8
|
+
|
9
|
+
Rails will start creating the app and will skip the files you have already created. If there is some conflict then it will stop and you need to resolve it manually. be careful at this step as it might replace you current code in conflicted files.
|
10
|
+
|
11
|
+
2. Resolve conflicts
|
12
|
+
|
13
|
+
```
|
14
|
+
1. Press "d" to see the difference
|
15
|
+
2. If it is only adding lines then press "y" to continue
|
16
|
+
3. If it is removeing some of your code then press "n" and add all additions manually
|
17
|
+
```
|
18
|
+
|
19
|
+
3. Run `bundle install` and follow [the instructions for installing into an existing Rails app](https://www.shakacode.com/react-on-rails/docs/guides/installation-into-an-existing-rails-app/)
|
@@ -0,0 +1,32 @@
|
|
1
|
+
## In your engine
|
2
|
+
|
3
|
+
+ At the top of `config/initializers/react_on_rails.rb`
|
4
|
+
```ruby
|
5
|
+
ActiveSupport.on_load(:action_view) do
|
6
|
+
include ReactOnRailsHelper
|
7
|
+
end
|
8
|
+
```
|
9
|
+
+ In your `<engine_name>.gemspec`:
|
10
|
+
```ruby
|
11
|
+
s.add_dependency 'react_on_rails', '~> 6'
|
12
|
+
```
|
13
|
+
+ In your `lib/<engine_name>.rb` (the entry point for your engine)
|
14
|
+
```ruby
|
15
|
+
require "react_on_rails"
|
16
|
+
```
|
17
|
+
## In the project including your engine
|
18
|
+
|
19
|
+
Place `gem 'react_on_rails', '~> 6'` before the gem pointing at your engine in your gemfile.
|
20
|
+
|
21
|
+
Requiring `react_on_rails` and including the helper will get rid of any issues where react on rails or react_component is undefined.
|
22
|
+
|
23
|
+
As far as solving the assets issue, `lib/tasks/assets.rake` in `react_on_rails` would somehow have to know that `react_on_rails` was included in an engine, and decide the path accordingly. This might be impossible, especially in the case of multiple engines using `react_on_rails` in a single application.
|
24
|
+
|
25
|
+
Another solution would be to detach this rake task from the `rails assets:precompile` task. This can be done by adding `REACT_ON_RAILS_PRECOMPILE=false` to your environment. If you do so, then react assets will have to be bundled separately from `rails assets:precompile`.
|
26
|
+
|
27
|
+
# Github Issues
|
28
|
+
|
29
|
+
* [Integration with an engine #342](https://github.com/shakacode/react_on_rails/issues/342)
|
30
|
+
* [Feature: target destination option for the install generator #459](https://github.com/shakacode/react_on_rails/issues/459)
|
31
|
+
* [Integration with Rails 5 Engines #562](https://github.com/shakacode/react_on_rails/issues/562)
|
32
|
+
* [Run inside a Rails engine? #257](https://github.com/shakacode/react_on_rails/issues/257)
|
@@ -12,9 +12,10 @@ You can easily render React components in your JavaScript with `render` method t
|
|
12
12
|
* @param name Name of your registered component
|
13
13
|
* @param props Props to pass to your component
|
14
14
|
* @param domNodeId
|
15
|
+
* @param hydrate [optional] Pass truthy to update server rendered html. Default is falsy
|
15
16
|
* @returns {virtualDomElement} Reference to your component's backing instance
|
16
17
|
*/
|
17
|
-
ReactOnRails.render(componentName, props,
|
18
|
+
ReactOnRails.render(componentName, props, domNodeId)
|
18
19
|
```
|
19
20
|
|
20
21
|
## Why do we need this?
|
@@ -1,4 +1,15 @@
|
|
1
|
-
# Turbolinks
|
1
|
+
# Turbolinks and Turbo
|
2
|
+
|
3
|
+
## Updated to support Turbo
|
4
|
+
* See [PR 1374](https://github.com/shakacode/react_on_rails/pull/1374).
|
5
|
+
* Ability to use with Turbo (@hotwired/turbo), as Turbolinks gets obsolete.
|
6
|
+
|
7
|
+
To configure turbo the following option can be set:
|
8
|
+
`ReactOnRails.setOptions({ turbo: true })`
|
9
|
+
|
10
|
+
Turbo is not auto-detected like older Turbolinks.
|
11
|
+
|
12
|
+
*Below docs maybe outdated*
|
2
13
|
|
3
14
|
* See [Turbolinks on Github](https://github.com/rails/turbolinks)
|
4
15
|
* React on Rails currently supports 2.5.x of Turbolinks and 5.0.0 of Turbolinks 5.
|
@@ -73,6 +84,7 @@ To turn on tracing of Turbolinks events, put this in your registration file, whe
|
|
73
84
|
```js
|
74
85
|
ReactOnRails.setOptions({
|
75
86
|
traceTurbolinks: true,
|
87
|
+
turbo: true,
|
76
88
|
});
|
77
89
|
```
|
78
90
|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
## React on Rails Pro
|
2
|
+
|
3
|
+
Support React on Rails development [by becoming a Github sponsor](https://github.com/sponsors/shakacode) and get these benefits:
|
4
|
+
|
5
|
+
1. 1-hour per month of support via Slack, PR reviews, and Zoom for React on Rails,
|
6
|
+
React-Rails, Shakapacker, rails/webpacker, ReScript (ReasonML), TypeScript, Rust, etc.
|
7
|
+
2. React on Rails Pro Software that extends React on Rails with Node server rendering,
|
8
|
+
fragment caching, code-splitting, and other performance enhancements for React on Rails.
|
9
|
+
|
10
|
+
See the [React on Rails Pro Support Plan](https://www.shakacode.com/react-on-rails-pro/).
|
11
|
+
|
12
|
+
ShakaCode can also help you with your custom software development needs. We specialize in
|
13
|
+
marketplace and e-commerce applications that utilize both Rails and React.
|
14
|
+
Because we own [HiChee.com](https://hichee.com), we can leverage that code for your app!
|
15
|
+
|
16
|
+
Please email Justin Gordon [justin@shakacode.com](mailto:justin@shakacode.com), the
|
17
|
+
maintainer of React on Rails, for more information.
|
18
|
+
|
19
|
+
### Pro: Fragment Caching
|
20
|
+
|
21
|
+
Fragment caching is a [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro/) feature. Fragment caching is a **HUGE** performance booster for your apps. Use the `cached_react_component` and `cached_react_component_hash`. The API is the same as `react_component` and `react_component_hash`, but for 2 differences:
|
22
|
+
|
23
|
+
1. The `cache_key` takes the same parameters as any Rails `cache` view helper.
|
24
|
+
1. The **props** are passed via a block so that evaluation of the props is not done unless the cache is broken. Suppose you put your props calculation into some method called `some_slow_method_that_returns_props`:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
<%= cached_react_component("App", cache_key: [@user, @post], prerender: true) do
|
28
|
+
some_slow_method_that_returns_props
|
29
|
+
end %>
|
30
|
+
```
|
31
|
+
|
32
|
+
Such fragment caching saves CPU work for your web server and greatly reduces the request time. It completely skips the evaluation costs of:
|
33
|
+
|
34
|
+
1. Database calls to compute the props.
|
35
|
+
2. Serialization the props values hash into a JSON string for evaluating JavaScript to server render.
|
36
|
+
3. Costs associated with evaluating JavaScript from your Ruby code.
|
37
|
+
4. Creating the HTML string containing the props and the server-rendered JavaScript code.
|
38
|
+
|
39
|
+
Note, even without server rendering (without step 3 above), fragment caching is still effective.
|
40
|
+
|
41
|
+
### Pro: Integration with Node.js for Server Rendering
|
42
|
+
|
43
|
+
Default server rendering is done by ExecJS. If you want to use a Node.js server for better performing server rendering, [email justin@shakacode.com](mailto:justin@shakacode.com). ShakaCode has built a premium Node rendering server that is part of [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro).
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# HVMN Testimonial, Written by Paul Benigeri, October 12, 2018
|
2
|
+
|
3
|
+
For some years, we used React on Rails for server-side rendering at [HVMN](https://hvmn.com). Our entire backend was already built in Rails, and we love React. As a content & e-commerce site, server-side rendering is critical, for UX performance and SEO crawler indexing.
|
4
|
+
|
5
|
+
During the 12 months leading up to our React on Rails Pro transition, our traffic grew 10x. Our team of 2 engineers was focused on shipping features, and we started to face performance issues. We had some fragment caching of our React server rending, but it didn’t work that well.
|
6
|
+
|
7
|
+
I discussed our growing pains with Justin, and as it turned out, ShakaCode just came out with React on Rails Pro and set it up on [egghead.io](https://egghead.io). The performance improvements were impressive, and Justin’s team was an ideal partner to help with the integration.
|
8
|
+
|
9
|
+
We decided to give it a shot. Over three weeks, the ShakaCode team helped us migrate to React on Rails Pro, set up Webpack v4, migrated our entire asset pipeline to Webpack v4.
|
10
|
+
|
11
|
+
Results were great. Our blog and product pages are 80-90% faster after that effort. The improved fragment caching was quick to set up and made a huge dent in our average server response times. We also observed an additional drop in response times when ShakaCode shipped the standalone Node server-side React renderer.
|
12
|
+
|
13
|
+
Working with ShakaCode was a pleasure. Justin is one of the smartest Rails architects I know, and his team was responsive and productive.
|
14
|
+
|
15
|
+
The price we paid for the consultation + the React on Rails pro license has already been made back a couple of times from hosting fees alone. The entire process was super hands off, and our core team was able to focus on shipping new feature during that sprint.
|
16
|
+
|
17
|
+
If you have any questions, please reach out.
|
18
|
+
|
19
|
+
Paul Benigeri, Head of E-Commerce
|
20
|
+
|
21
|
+
[paul@hvmn.com](mailto:paul@hvmn.com), [LinkedIn](https://www.linkedin.com/in/benigeri/)
|
22
|
+
|
23
|
+
Related Article: [HVMN’s 90% Reduction in Server Response Time from React on Rails Pro](https://blog.shakacode.com/hvmns-90-reduction-in-server-response-time-from-react-on-rails-pro-eb08226687db)
|
24
|
+
|
25
|
+
[![image](https://user-images.githubusercontent.com/1118459/46911126-577abd00-ceee-11e8-86c6-6703ff80fc2f.png)](https://www.linkedin.com/in/benigeri/)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# ResortPass Testimonial, by Leora Juster, December 10, 2018
|
2
|
+
|
3
|
+
Many can write code that "works." Even fewer can write sophisticated code that both works and reflects a deep understanding of the technologies and paradigms involved. Only a select few can do the aforementioned while assisting in managing the expectations and time constraints of less technically informed members of software product teams to make the best design decisions possible. Justin and his team were instrumental in assisting us in setting design foundations and standards for our transition to a react on rails application. Just three months of work with the team at Shaka code and we have a main page of our application server-side rendering at exponentially improved speeds. The code and CSS files are well-organized and contain repeatable patterns easy to understand, allowing my team to build on what has already been accomplished. I learned a great deal from my interactions with Justin and his team, as they are just as great teachers as they are developers, and feel like I get to continually learn from them as I build on top of their code. Their different support and pro plan options make it easy to build a continuous professional relationship despite fluctuations in my team's funding, and their team is always extremely personable, punctual, and professional.
|
4
|
+
|
5
|
+
Leora Juster, Full-Stack Lead Software Developer
|
6
|
+
|
7
|
+
[LinkedIn](https://www.linkedin.com/in/leora-juster-38933050)
|
8
|
+
|
9
|
+
![image](https://user-images.githubusercontent.com/1118459/50050877-30399b00-00ab-11e9-9e52-2977de45ccae.png)
|
10
|
+
|
11
|
+
[ResortPass](https://resortpass.com/)
|
12
|
+
|
13
|
+
[![2018-12-15_20-48-35](https://user-images.githubusercontent.com/1118459/50050866-03858380-00ab-11e9-8588-461112f8045b.png)](https://resortpass.com/)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Testimonials
|
2
|
+
# [HVMN Testimonial, Written by Paul Benigeri, October 12, 2018](https://www.shakacode.com/react-on-rails/docs/testimonials/hvmn/)
|
3
|
+
|
4
|
+
> The price we paid for the consultation + the React on Rails pro license has already been made back a couple of times from hosting fees alone. The entire process was super hands off, and our core team was able to focus on shipping new feature during that sprint.
|
5
|
+
|
6
|
+
Full writeup [here](https://www.shakacode.com/react-on-rails/docs/testimonials/hvmn/).
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
# [Leora from ResortPass](https://www.shakacode.com/react-on-rails/docs/testimonials/resortpass/), December 10, 2018
|
11
|
+
|
12
|
+
Justin and his team were instrumental in assisting us in setting design foundations and standards for our transition to a react on rails application. Just three months of work with the team at Shaka code and we have a main page of our application server-side rendering at exponentially improved speeds.
|
13
|
+
|
14
|
+
Full writeup [here](https://www.shakacode.com/react-on-rails/docs/testimonials/resortpass/).
|
15
|
+
|
16
|
+
---
|
17
|
+
|
18
|
+
From Joel Hooks, Co-Founder, Chief Nerd at [egghead.io](https://egghead.io/), January 30, 2017:
|
19
|
+
|
20
|
+
![2017-01-30_11-33-59](https://cloud.githubusercontent.com/assets/1118459/22443635/b3549fb4-e6e3-11e6-8ea2-6f589dc93ed3.png)
|
21
|
+
|
22
|
+
---
|
23
|
+
|
24
|
+
From Kyle Maune of Cooper Aerial, May 4, 2018
|
25
|
+
|
26
|
+
![image](https://user-images.githubusercontent.com/1118459/40891236-9b0b406e-671d-11e8-80ee-c026dbd1d5a2.png)
|
27
|
+
|
28
|
+
For more testimonials, see [Live Projects](https://github.com/shakacode/react_on_rails/tree/master/PROJECTS.md) and [Kudos](https://github.com/shakacode/react_on_rails/tree/master/KUDOS.md).
|
data/jest.config.js
ADDED
data/lib/generators/USAGE
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/generators"
|
4
|
+
require_relative "generator_helper"
|
5
|
+
|
6
|
+
module ReactOnRails
|
7
|
+
module Generators
|
8
|
+
class AdaptForOlderShakapackerGenerator < Rails::Generators::Base
|
9
|
+
include GeneratorHelper
|
10
|
+
Rails::Generators.hide_namespace(namespace)
|
11
|
+
|
12
|
+
def change_spelling_to_webpacker
|
13
|
+
puts "Change spelling to webpacker v7"
|
14
|
+
files = %w[
|
15
|
+
Procfile.dev
|
16
|
+
Procfile.dev-static
|
17
|
+
config/shakapacker.yml
|
18
|
+
config/initializers/react_on_rails.rb
|
19
|
+
]
|
20
|
+
files.each { |file| gsub_file(file, "shakapacker", "webpacker") }
|
21
|
+
end
|
22
|
+
|
23
|
+
def rename_config_file
|
24
|
+
puts "Rename to config/webpacker.yml"
|
25
|
+
puts "Renaming shakapacker.yml into webpacker.yml"
|
26
|
+
FileUtils.mv("config/shakapacker.yml", "config/webpacker.yml")
|
27
|
+
end
|
28
|
+
|
29
|
+
def modify_requiring_webpack_config_in_js
|
30
|
+
puts "Update commonWebpackConfig.js to follow the Shakapacker v6 interface"
|
31
|
+
file = "config/webpack/commonWebpackConfig.js"
|
32
|
+
gsub_file(file, "const baseClientWebpackConfig = generateWebpackConfig();\n\n", "")
|
33
|
+
gsub_file(
|
34
|
+
file,
|
35
|
+
"const { generateWebpackConfig, merge } = require('shakapacker');",
|
36
|
+
"const { webpackConfig: baseClientWebpackConfig, merge } = require('shakapacker');"
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|