react_on_rails 13.3.5 → 14.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +100 -62
  3. data/Gemfile.development_dependencies +10 -9
  4. data/README.md +7 -2
  5. data/lib/generators/react_on_rails/adapt_for_older_shakapacker_generator.rb +41 -0
  6. data/lib/generators/react_on_rails/base_generator.rb +13 -49
  7. data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -1
  8. data/lib/generators/react_on_rails/generator_messages.rb +40 -0
  9. data/lib/generators/react_on_rails/install_generator.rb +21 -0
  10. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +2 -2
  11. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-static +2 -2
  12. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +2 -2
  13. data/lib/generators/react_on_rails/templates/base/base/config/{webpacker.yml → shakapacker.yml} +3 -3
  14. data/lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt +3 -1
  15. data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +2 -2
  16. data/lib/generators/react_on_rails/templates/dev_tests/spec/system/hello_world_spec.rb +1 -1
  17. data/lib/react_on_rails/configuration.rb +39 -25
  18. data/lib/react_on_rails/git_utils.rb +3 -3
  19. data/lib/react_on_rails/helper.rb +25 -13
  20. data/lib/react_on_rails/json_output.rb +0 -17
  21. data/lib/react_on_rails/locales/base.rb +4 -4
  22. data/lib/react_on_rails/locales/to_js.rb +1 -1
  23. data/lib/react_on_rails/packs_generator.rb +4 -4
  24. data/lib/react_on_rails/react_component/render_options.rb +1 -1
  25. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +10 -12
  26. data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +3 -3
  27. data/lib/react_on_rails/test_helper.rb +2 -2
  28. data/lib/react_on_rails/utils.rb +2 -8
  29. data/lib/react_on_rails/version.rb +1 -1
  30. data/lib/react_on_rails/version_checker.rb +2 -2
  31. data/lib/react_on_rails/webpacker_utils.rb +6 -0
  32. data/lib/tasks/assets.rake +1 -1
  33. data/react_on_rails.gemspec +4 -4
  34. metadata +6 -131
  35. data/.bookignore +0 -15
  36. data/.circleci/config.yml +0 -338
  37. data/.coveralls.yml +0 -1
  38. data/.dockerignore +0 -2
  39. data/.eslintignore +0 -17
  40. data/.eslintrc +0 -53
  41. data/.github/FUNDING.yml +0 -1
  42. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -23
  43. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  44. data/.github/PULL_REQUEST_TEMPLATE.md +0 -19
  45. data/.github/workflows/lint-js-and-ruby.yml +0 -54
  46. data/.github/workflows/main.yml +0 -183
  47. data/.github/workflows/package-js-tests.yml +0 -35
  48. data/.github/workflows/rspec-package-specs.yml +0 -46
  49. data/.gitignore +0 -33
  50. data/.npmignore +0 -22
  51. data/.prettierignore +0 -14
  52. data/.prettierrc +0 -20
  53. data/.rspec +0 -2
  54. data/.rubocop.yml +0 -134
  55. data/.scss-lint.yml +0 -205
  56. data/.travis.yml +0 -61
  57. data/book.json +0 -18
  58. data/docs/additional-details/generator-details.md +0 -56
  59. data/docs/additional-details/manual-installation-overview.md +0 -30
  60. data/docs/additional-details/migrating-from-react-rails.md +0 -17
  61. data/docs/additional-details/recommended-project-structure.md +0 -69
  62. data/docs/additional-details/updating-dependencies.md +0 -31
  63. data/docs/additional-details/upgrade-webpacker-v3-to-v4.md +0 -10
  64. data/docs/api/javascript-api.md +0 -99
  65. data/docs/api/redux-store-api.md +0 -102
  66. data/docs/api/view-helpers-api.md +0 -133
  67. data/docs/contributor-info/errors-with-hooks.md +0 -45
  68. data/docs/contributor-info/generator-testing.md +0 -11
  69. data/docs/contributor-info/linters.md +0 -68
  70. data/docs/contributor-info/pull-requests.md +0 -42
  71. data/docs/contributor-info/releasing.md +0 -76
  72. data/docs/deployment/elastic-beanstalk.md +0 -63
  73. data/docs/deployment/heroku-deployment.md +0 -35
  74. data/docs/getting-started.md +0 -195
  75. data/docs/guides/client-vs-server-rendering.md +0 -27
  76. data/docs/guides/configuration.md +0 -289
  77. data/docs/guides/deployment.md +0 -5
  78. data/docs/guides/file-system-based-automated-bundle-generation.md +0 -205
  79. data/docs/guides/hmr-and-hot-reloading-with-the-webpack-dev-server.md +0 -104
  80. data/docs/guides/how-react-on-rails-works.md +0 -44
  81. data/docs/guides/how-to-conditionally-server-render-based-on-device-type.md +0 -40
  82. data/docs/guides/how-to-use-different-files-for-client-and-server-rendering.md +0 -98
  83. data/docs/guides/i18n.md +0 -87
  84. data/docs/guides/installation-into-an-existing-rails-app.md +0 -66
  85. data/docs/guides/minitest-configuration.md +0 -31
  86. data/docs/guides/rails-webpacker-react-integration-options.md +0 -213
  87. data/docs/guides/react-on-rails-overview.md +0 -30
  88. data/docs/guides/react-server-rendering.md +0 -32
  89. data/docs/guides/render-functions-and-railscontext.md +0 -205
  90. data/docs/guides/rspec-configuration.md +0 -73
  91. data/docs/guides/tutorial.md +0 -374
  92. data/docs/guides/upgrading-react-on-rails.md +0 -304
  93. data/docs/guides/webpack-configuration.md +0 -42
  94. data/docs/home.md +0 -23
  95. data/docs/javascript/angular-js-integration-migration.md +0 -28
  96. data/docs/javascript/asset-pipeline.md +0 -12
  97. data/docs/javascript/capistrano-deployment.md +0 -18
  98. data/docs/javascript/code-splitting.md +0 -165
  99. data/docs/javascript/converting-from-custom-webpack-config-to-rails-webpacker-config.md +0 -10
  100. data/docs/javascript/credits.md +0 -10
  101. data/docs/javascript/foreman-issues.md +0 -15
  102. data/docs/javascript/images.md +0 -57
  103. data/docs/javascript/node-dependencies-and-npm.md +0 -19
  104. data/docs/javascript/react-and-redux.md +0 -36
  105. data/docs/javascript/react-helmet.md +0 -100
  106. data/docs/javascript/react-router.md +0 -90
  107. data/docs/javascript/server-rendering-tips.md +0 -55
  108. data/docs/javascript/troubleshooting-when-using-webpacker.md +0 -90
  109. data/docs/javascript/webpack-v1-notes.md +0 -23
  110. data/docs/javascript/webpack.md +0 -22
  111. data/docs/misc/articles.md +0 -20
  112. data/docs/misc/code_of_conduct.md +0 -13
  113. data/docs/misc/doctrine.md +0 -77
  114. data/docs/misc/style.md +0 -33
  115. data/docs/misc/tips.md +0 -10
  116. data/docs/outdated/deferred-rendering.md +0 -39
  117. data/docs/outdated/rails-assets-relative-paths.md +0 -195
  118. data/docs/outdated/rails-assets.md +0 -77
  119. data/docs/outdated/rails3.md +0 -9
  120. data/docs/rails/convert-rails-5-api-only-app.md +0 -19
  121. data/docs/rails/rails-engine-integration.md +0 -32
  122. data/docs/rails/rails_view_rendering_from_inline_javascript.md +0 -36
  123. data/docs/rails/turbolinks.md +0 -124
  124. data/docs/react-on-rails-pro/react-on-rails-pro.md +0 -43
  125. data/docs/testimonials/hvmn.md +0 -25
  126. data/docs/testimonials/resortpass.md +0 -13
  127. data/docs/testimonials/testimonials.md +0 -28
  128. data/jest.config.js +0 -4
  129. data/package-scripts.yml +0 -49
  130. data/package.json +0 -96
  131. data/rakelib/docker.rake +0 -26
  132. data/rakelib/dummy_apps.rake +0 -30
  133. data/rakelib/example_type.rb +0 -96
  134. data/rakelib/examples.rake +0 -64
  135. data/rakelib/examples_config.yml +0 -14
  136. data/rakelib/lint.rake +0 -30
  137. data/rakelib/node_package.rake +0 -15
  138. data/rakelib/release.rake +0 -92
  139. data/rakelib/run_rspec.rake +0 -103
  140. data/rakelib/task_helpers.rb +0 -62
  141. data/script/bootstrap +0 -33
  142. data/script/release +0 -3
  143. data/script/setup +0 -23
  144. data/script/test +0 -38
  145. data/webpackConfigLoader.js +0 -71
  146. data/yarn.lock +0 -7010
@@ -1,55 +0,0 @@
1
- # Server Rendering Tips
2
-
3
- For the best performance with Server Rendering, consider using [React on Rails Pro]
4
-
5
-
6
- ## General Tips
7
- - Your code can't reference `document`. Server side JS execution does not have access to `document`,
8
- so jQuery and some other libs won't work in this environment. You can debug this by putting in
9
- `console.log` statements in your code.
10
- - You can conditionally avoid running code that references document by either checking if `window`
11
- is defined or using the "railsContext"
12
- your top level react component. Since the passed in props Hash from the view helper applies to
13
- client and server side code, the best way to do this is to use a Render-Function.
14
- - If you're serious about server rendering, it's worth the effort to have different entry points for client and server rendering. It's worth the extra complexity. The point is that you have separate files for top level client or server side, and you pass some extra option indicating that rendering is happening server side.
15
- - You can enable Node.js server rendering via [React on Rails Pro](https://github.com/shakacode/react_on_rails/wiki).
16
-
17
- ## Troubleshooting Server Rendering
18
-
19
- 1. First be sure your code works with server rendering disabled (`prerender: false`)
20
- 2. Be sure that `config.trace` is true. You will get the server invocation code that renders your component. If you're not using Webpacker, you will also get the whole file used to setup the JavaScript context.
21
-
22
- ## CSS
23
- Server bundles must always have CSS Extracted
24
-
25
- ## setTimeout, setInterval, and clearTimeout
26
-
27
- These methods are polyfilled for server rendering to be no-ops. We log calls to these when in `trace` mode. In the past, some libraries, namely babel-polyfill, did call setTimout.
28
-
29
- Here's an example of this which shows the line numbers that end up calling setTimeout:
30
- ```
31
- ➜ ~/shakacode/react_on_rails/gen-examples/examples/basic-server-rendering (add-rails-helper-to-generator u=) ✗ export SERVER_TRACE_REACT_ON_RAILS=TRUE
32
- ➜ ~/shakacode/react_on_rails/gen-examples/examples/basic-server-rendering (add-rails-helper-to-generator u=) ✗ rspec
33
- Hello World
34
- Building Webpack client-rendering assets...
35
- Completed building Webpack client-rendering assets.
36
- ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
37
- react_renderer.rb: 92
38
- wrote file tmp/server-generated.js
39
- ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
40
- ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
41
- react_renderer.rb: 92
42
- wrote file tmp/base_js_code.js
43
- ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
44
- [SERVER] setTimeout is not defined for execJS. See https://github.com/sstephenson/execjs#faq. Note babel-polyfill will call this.
45
- [SERVER] at setTimeout (<eval>:31:17)
46
- at defer (<eval>:4422:8)
47
- at setImmediate (<eval>:4387:6)
48
- at notify (<eval>:4481:16)
49
- at module.exports (<eval>:4490:6)
50
- at notify (<eval>:4081:4)
51
- at Promise.$resolve (<eval>:4189:8)
52
- at <eval>:793:18
53
- at Function.resolve (<eval>:4265:6)
54
- the hello world example works
55
- ```
@@ -1,90 +0,0 @@
1
- ## Context
2
-
3
- Rails: 5.0.2
4
- react_on_rails: upgraded from 6.6.0 to 9.0.3
5
-
6
- ## The failure
7
-
8
- Rspec failing with
9
- ```
10
- Failure/Error: raise Webpacker::Manifest::MissingEntryError, missing_file_from_manifest_error(name)
11
-
12
- Webpacker::Manifest::MissingEntryError:
13
- Webpacker can't find webpack-bundle.js in /home/user/ws/pp/code/pp-core-checkout_spa_update_npm/public/webpack-test/manifest.json. Possible causes:
14
- 1. You want to set webpacker.yml value of compile to true for your environment
15
- unless you are using the `webpack -w` or the webpack-dev-server.
16
- 2. Webpack has not yet re-run to reflect updates.
17
- 3. You have misconfigured Webpacker's config/webpacker.yml file.
18
- 4. Your Webpack configuration is not creating a manifest.
19
- Your manifest contains:
20
- {
21
- "main.css": "/webpack-test/main-bundle.css",
22
- "main.js": "/webpack-test/main-dde0e05a2817931424c3.js"
23
- }
24
- # /home/user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/webpacker-3.0.1/lib/webpacker/manifest.rb:44:in `handle_missing_entry'
25
- # /home/user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/webpacker-3.0.1/lib/webpacker/manifest.rb:40:in `find'
26
- # /home/user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/webpacker-3.0.1/lib/webpacker/manifest.rb:27:in `lookup'
27
- # /home/user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/react_on_rails-9.0.3/lib/react_on_rails/utils.rb:145:in `bundle_js_file_path_from_webpacker'
28
- # /home/user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/react_on_rails-9.0.3/lib/react_on_rails/utils.rb:90:in `bundle_js_file_path'
29
- # /home/user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/react_on_rails-9.0.3/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb:56:in `block in all_compiled_assets'
30
- # /home/user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/react_on_rails-9.0.3/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb:55:in `map'
31
- # /home/user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/react_on_rails-9.0.3/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb:55:in `all_compiled_assets'
32
- # /home/user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/react_on_rails-9.0.3/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb:35:in `stale_generated_webpack_files'
33
- # /home/user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/react_on_rails-9.0.3/lib/react_on_rails/test_helper/ensure_assets_compiled.rb:34:in `call'
34
- # /home/user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/react_on_rails-9.0.3/lib/react_on_rails/test_helper.rb:85:in `ensure_assets_compiled'
35
- # /home/user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/react_on_rails-9.0.3/lib/react_on_rails/test_helper.rb:39:in `block (2 levels) in configure_rspec_to_compile_assets'
36
- # /home/user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:443:in `instance_exec'
37
- ...
38
- ```
39
-
40
- At the same time dev/prod environments works fine (with extra webpack calling step outside rails).
41
-
42
- ## Configs
43
-
44
- ### webpack.config.js
45
-
46
- ```js
47
- ...
48
- const ManifestPlugin = require('webpack-manifest-plugin');
49
- ...
50
- const { output } = webpackConfigLoader(configPath);
51
- ...
52
- output: {
53
- filename: '[name]-[hash].js',
54
-
55
- // Leading and trailing slashes ARE necessary.
56
- publicPath: output.publicPath,
57
- path: output.path,
58
- },
59
- ...
60
- plugins: [
61
- ...
62
- new ManifestPlugin({
63
- publicPath: output.publicPath,
64
- writeToFileEmit: true
65
- }),
66
- ...
67
- ]
68
- ...
69
- ```
70
-
71
- ### config/webpacker.yml
72
-
73
- is default from sample appliction v9.x
74
-
75
- ### config/initializers/react_on_rails.rb
76
-
77
- ```ruby
78
- ...
79
- # Define the files we need to check for webpack compilation when running tests.
80
- config.webpack_generated_files = %w( webpack-bundle.js main-bundle.css )
81
- ...
82
- ```
83
-
84
- ## The problem
85
-
86
- When `ReactOnRails.configuration.webpack_generated_files` is specified, it prevents usage of `manifest.json`
87
-
88
- ## Solution
89
-
90
- Removing of `config.webpack_generated_files` from `config/initializers/react_on_rails.rb` resolving issue.
@@ -1,23 +0,0 @@
1
- # Webpack V1 Tips
2
-
3
- The following only apply to Webpack V1. Take 1 hour and update to v2! It's worth it!
4
-
5
- ## Use the `--bail` Option When Running Webpack for CI or Deployments if using Webpack V1
6
- For your scripts that statically build your Webpack bundles, use the `--bail` option. This will ensure that CI and your product deployment **halt** if Webpack cannot complete! For more details, see the documentation for [Webpack's `--bail` option](https://webpack.js.org/configuration/other-options/#bail). Note, you might not want to use the `--bail` option if you just want to depend on Webpack returning a non-zero error code and you want to see all the errors, rather than only the first error.
7
-
8
-
9
- ## Entry Points
10
- You should ensure you configure the entry points correctly for webpack if you want to break out libraries into a "vendor" bundle where your libraries are packaged separately from your app's code. If you send web clients your vendor bundle separately from your app bundles, then web clients might have the vendor bundle cached while they receive updates for your app.
11
-
12
- You need both include `react-dom` and `react` as values for `entry`, like this:
13
-
14
- ```
15
- entry: {
16
-
17
- // See use of 'vendor' in the CommonsChunkPlugin inclusion below.
18
- vendor: [
19
- 'babel-core/polyfill',
20
- 'react',
21
- 'react-dom',
22
- ],
23
- ```
@@ -1,22 +0,0 @@
1
- # Webpack Tips
2
-
3
- ## Where do I learn about advanced Webpack setups, such as with "CSS Modules", "Code Splitting", etc
4
- You can try out example app, [shakacode/react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial). We're building comprehensive production examples in our new, premium product, [**React on Rails Pro**](https://forum.shakacode.com/t/introducing-react-on-rails-pro-subscriptions/785). If you're interested, please see the details in [this forum post](https://forum.shakacode.com/t/introducing-react-on-rails-pro-subscriptions/785).
5
-
6
- ## Webpack v1 or v2?
7
- We recommend using Webpack version 2.3.1 or greater.
8
-
9
- ## yarn or npm?
10
- Yarn is the current recommendation!
11
-
12
- ## Entry Points
13
-
14
- You should ensure you configure the entry points correctly for webpack if you want to break out libraries into a "vendor" bundle where your libraries are packaged separately from your app's code. If you send web clients your vendor bundle separately from your app bundles, then web clients might have the vendor bundle cached while they receive updates for your app.
15
-
16
- Webpack v2 makes this very convenient! See:
17
-
18
- * [Implicit Common Vendor Chunk](https://webpack.js.org/guides/code-splitting-libraries/#implicit-common-vendor-chunk)
19
- * [Manifest File](https://webpack.js.org/guides/code-splitting-libraries/#manifest-file)
20
-
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).
@@ -1,20 +0,0 @@
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)
@@ -1,13 +0,0 @@
1
- # Contributor Code of Conduct
2
-
3
- As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
-
5
- We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
-
7
- Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
-
9
- Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
-
11
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
-
13
- This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
@@ -1,77 +0,0 @@
1
- # The React on Rails Doctrine
2
-
3
- By Justin Gordon, January 26, 2016
4
-
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
-
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
-
9
- Besides the project objective, let's stick with the "Rails Doctrine" and keep the following in mind.
10
-
11
- ## Optimize for Programmer Happiness
12
- The React on Rails setup provides several key components related to front-end developer happiness:
13
-
14
- 1. [Hot reloading of both JavaScript and CSS](https://gaearon.github.io/react-hot-loader/), via the [webpack dev server](https://webpack.github.io/docs/webpack-dev-server.html). This works for both using an [express server](http://expressjs.com/) to load stubs for the ajax requests, as well as using a live Rails server. **Oh yes**, your Rails server can do hot reloading!
15
- 2. [CSS modules](https://github.com/css-modules/webpack-demo) which remove the madness of a global namespace for CSS. We organize our CSS (Sass, actually) right next to our JavaScript React component files. This means no more creating long class names to ensure that CSS picks up the right styles.
16
- 3. [ES6 JavaScript](http://es6-features.org/#Constants) is a great language for client side coding, much more so than Ruby due to the asynchronous nature of UI programming.
17
- 4. JavaScript libraries and tooling work better in the native node way, rather than via some aspect of Sprockets and the Rails Asset Pipeline. We find way less frustration this way, especially from being able to get the latest advances with the rest of the JavaScript community. Why complicated beautiful JavaScript tooling Rails asset pipeline complexity?
18
- 5. We want our JavaScript from npm. Getting JavaScript from rubygems.org is comparatively frustrating.
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
- 7. You can get set up on React on Rails **FAST** using our application generator.
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 heroku deployment documentation](https://www.shakacode.com/react-on-rails/docs/deployment/heroku-deployment/).
23
-
24
- ## Convention over Configuration
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](https://www.shakacode.com/react-on-rails/docs/misc/style/)
27
- * [linters](https://www.shakacode.com/react-on-rails/docs/contributor-info/linters/)
28
-
29
- We're big believers in this quote from the Rails Doctrine:
30
-
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.
32
-
33
-
34
- ## The Menu Is Omakase
35
- Here's the chef's selection from the React on Rails community:
36
-
37
- ### Libraries
38
- * [Bootstrap](http://getbootstrap.com/), loaded from [bootstrap-loader](https://github.com/shakacode/bootstrap-loader/). Common UI styles.
39
- * [Lodash](https://lodash.com/): Swiss army knife of utilities.
40
- * [React](https://facebook.github.io/react/): UI components.
41
- * [React-Router](https://github.com/reactjs/react-router): Provider of deep links for client-side application.
42
- * [Redux](https://github.com/reactjs/redux): Flux implementation (aka "state container").
43
-
44
- ### JavaScript Tooling
45
- * [Babel](https://babeljs.io/): Transpiler for ES6 into ES5 and much more.
46
- * [EsLint](http://eslint.org/)
47
- * [Webpack](http://webpack.github.io/): Generator of deployment assets and provider of hot module reloading.
48
-
49
- By having a common set of tools, we can discuss what we should or shouldn't be using. Thus, this takes out the "JavaScript Fatigue" from having too many unclear choices in the JavaScript world.
50
-
51
- By the way, we're *not* omakase for standard Rails. That would be CoffeeScript. However, the Rails Doctrine makes it clear that non-standard menu choices are certainly welcome!
52
-
53
- ## No One Paradigm
54
- React on Rails fits into the "No One Paradigm" of the Rails ecosystem from the perspective that it rocks for client side development with Rails, even though it's a totally different language than the server code written in Ruby.
55
-
56
- ## Exalt Beautiful Code
57
- ES5 was ugly. ES6 is beautiful. React is beautiful. Client side code written with React plus Redux, fully linted with the ShakaCode linters, and organized per our recommended project structure is beautiful. Don't take our word for it. Take a look at the component sample code in the [react-webpack-rails-tutorial sample code](https://github.com/shakacode/react-webpack-rails-tutorial/tree/master/client/app/bundles/comments).
58
-
59
- ## Value Integrated Systems
60
- Assuming that you're building the type of app that's a good fit for Rails (document/database based with lots of business rules), the tight integration of modern JavaScript with React on top of Ruby on Rails is better than building a pure client side app and separate microservices. Here's why:
61
-
62
- * Via React on Rails, we can seamlessly integrate React UI components with Rails.
63
- * Tight integration allows for trivial set up of server rendering of React on top of Rails, complete with support for fragment caching of the server rendered HTML, and integration with [Turbolinks](https://github.com/turbolinks/turbolinks).
64
- * Tight integration allows mixing and matching Rails pages with React driven pages, even on the same page. Not every part of a UI requires the high fidelity achievable using React. Many existing apps may have hundreds of standards Rails forms. Support for mixing and matching React with Rails forms provides the best of both worlds.
65
-
66
- ## Progress over Stability
67
- React on Rails will maintain an active pace of development, to keep up with:
68
-
69
- * Community suggestions.
70
- * New client side tooling, libraries, and techniques.
71
- * Updates to Rails.
72
-
73
- ## Raise a Big Tent
74
- React on Rails is definitely a part of the big tent of Rails. Plus, React on Rails provides its own big tent. A huge benefit of the React on Rails system is simple integration with Webpack and NPM, allowing integration with almost any library available on [npm](https://www.npmjs.org/)! The integration with Webpack also allows for other Webpack supported build tools.
75
-
76
- ## Thanks!
77
- Thanks for reading and being a part of the React on Rails community. Feedback on this document and *anything* in React on Rails is welcome. Please [open an issue](https://github.com/shakacode/react_on_rails/issues/new) or a pull request. If you'd like to join our private Slack channel, please [email](mailto:contact@shakacode.com) us a request.
data/docs/misc/style.md DELETED
@@ -1,33 +0,0 @@
1
- # Code Style
2
- This document describes the coding style of [ShakaCode](http://www.shakacode.com). Yes, it's opinionated, as all style guidelines should be. We shall put as little as possible into this guide and instead rely on:
3
-
4
- * Use of linters with our standard linter configuration.
5
- * References to existing style guidelines that support the linter configuration.
6
- * Anything additional goes next.
7
-
8
- ## Client Side JavaScript and React
9
- * See the [Shakacode JavaScript Style Guide](https://github.com/shakacode/style-guide-javascript)
10
-
11
- ## Style Guides to Follow
12
- Follow these style guidelines per the linter configuration. Basically, lint your code and if you have questions about the suggested fixes, look here:
13
-
14
- ### Ruby Coding Standards
15
- * [ShakaCode Ruby Coding Standards](https://github.com/shakacode/style-guide-ruby)
16
- * [Ruby Documentation](http://guides.rubyonrails.org/api_documentation_guidelines.html)
17
-
18
- ### JavaScript Coding Standards
19
- * [ShakaCode Javascript](https://github.com/shakacode/style-guide-javascript)
20
- * Use the [eslint-config-shakacode](https://github.com/shakacode/style-guide-javascript/tree/master/packages/eslint-config-shakacode) npm package with eslint.
21
- * [JSDoc](http://usejsdoc.org/)
22
-
23
- ### Git coding Standards
24
- * [Git Coding Standards](http://chlg.co/1GV2m9p)
25
-
26
- ### Sass Coding Standards
27
- * [Sass Guidelines](http://sass-guidelin.es/) by [Hugo Giraudel](http://hugogiraudel.com/)
28
- * [Github Front End Guidelines](http://primercss.io/guidelines/)
29
-
30
- # Git Usage
31
- * Follow a github-flow model where you branch off of master for features.
32
- * Before merging a branch to master, rebase it on top of master, by using command like `git fetch; git checkout my-branch; git rebase -i origin/master`. Clean up your commit message at this point. Be super careful to communicate with anybody else working on this branch and do not do this when others have uncommitted changes. Ideally, your merge of your feature back to master should be one nice commit.
33
- * Run hosted CI and code coverage.
data/docs/misc/tips.md DELETED
@@ -1,10 +0,0 @@
1
- # Tips
2
- + **DO NOT RUN `rails s`** and instead run
3
-
4
- `foreman start -f Procfile.dev`
5
-
6
- to automatically start the webpack file watchers that will regenerate your JavaScript. Note, RSpec does not automatically rebuild the bundle files, so you could get incorrect results from your tests if you change the client code and do not rebuild the bundles. The same problem occurs when pulling down changes from GitHub and running tests without first rebuilding the bundles.
7
- + The default for rendering right now is `prerender: false`. **NOTE:** Server side rendering does not work for some components that use an async setup for server rendering. You can configure the default for prerender in your config.
8
- + You can expose either a React component or a function that returns a React component. If you wish to create a React component via a function, rather than simply props, then you need to set the property "generator" on that helper invocation to true (or change the defaults). When that is done, the function is invoked with a single parameter of "props", and that function should return a React element.
9
- + Be sure you can first render your react component **client only** before you try to debug server rendering!
10
- + Open up the HTML source and take a look at the generated HTML and the JavaScript to see what's going on under the covers. Note that when server rendering is turned on, then you'll see the server rendered react components. When server rendering is turned off, then you'll only see the `div` element where the in-line JavaScript will render the component. You might also notice how the props you pass (a Ruby Hash) becomes in-line JavaScript on the HTML page.
@@ -1,39 +0,0 @@
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,195 +0,0 @@
1
- *Note: this doc reflects using Sprockets for assets and has not been updated for rails/webpacker*
2
-
3
- # Using Webpack bundled assets with the Rails Asset Pipeline
4
-
5
- **If you're looking to use assets in your react components, look no further. This doc is for you.**
6
-
7
- As most of you know, when you spin up a Rails application all of your asset files that live within your `app/assets/` directory will be added into your application's Asset Pipeline. If you would like to view any of these assets (most commonly you'd want to view images), run your rails server in development mode and in a browser visit a url similar to: `localhost:3000/assets/sample_image.png`. In this case, if I had an image `sample_image.png` in my `app/assets/images/` directory, visiting the url `localhost:3000/assets/sample_image.png` in a browser would display the image to me. Meaning that `/assets/sample_image.png` is my path to that individual asset.
8
-
9
- ## The Problem
10
-
11
- Sometimes we would like to use images directly in our react components or even component specific CSS. This can cause problems because it is difficult to maintain the relative path to assets in our pipeline. Normally, we would use erb to get around this, using something like `<img src="<%= asset_path('my-image.png') %>" />`. Unfortunately, that will not play well with webpack.
12
-
13
- Now we could always just place these assets in our `app/assets/` directory like normal and then reference them in our react with things like `<img src="/assets/asset-name.ext" />`, and that would work! But that also will move this image out of our client side app, which isn't always ideal. Also hardcoding the path to an asset isn't a good approach considering file paths can always change, and that would then require a source code change. That's just no bueno.
14
-
15
- So how do we get around this? And find the relative paths to our assets without hardcoding the paths?
16
-
17
- ## The Solution: The lowdown on Webpack's url-loader & file-loader, outputPaths and publicPaths
18
-
19
- Loaders are an incredibly useful part of Webpack. Simply put, they allow you to load and bundle different types of sources/files (you can load anything from images, CSS, to CoffeeScript).
20
-
21
- ##### Url Loader vs. File Loader
22
-
23
- Two very common, and quite useful, Webpack loaders are the [url-loader](https://github.com/webpack-contrib/url-loader) and the [file-loader](https://github.com/webpack-contrib/file-loader). They allow you to load and access files in an easy manner. Both of these loaders are incredibly similar to one another, and in fact work together to accomplish their goals, with a very slight difference. The url-loader will load any file(s) and when accessed, will return a Data Url that can be used to access the file(s) (commonly used to inline images). File-loader on the other hand, will bundle and output the file(s) to a desired directory so they can live in the assets on your webserver along with your outputted webpack bundle. These bundled assets can then be accessed by their public paths, making it very easy to include and use them in your JavaScript code.
24
-
25
- The url-loader is great to use for smaller images! It is most commonly used with a set byte limit on the size of the files that can be loaded. When this is the case, anything below the byte limit will be loaded and returned as a Data Url. Anything that exceeds the byte limit, will delegate to file-loader for loading, passing any set query parameters as well to file-loader (if that sounds like gibberish right now, don't worry. You'll learn all about it soon!).
26
-
27
- The benefit of using url-loader first, and falling back on file-loader, is that the use of Data Urls saves HTTP Requests that need to be made to fetch files. That is very important in regards to how fast a webpage will load. Generally speaking, the less HTTP requests that need to be made, the faster a page will load. For more information about usage, and the pros & cons of Data Urls read [here](https://css-tricks.com/data-uris/).
28
-
29
- Note: _For the rest of this doc, we will be using file-loader. This is because its usage can be a little bit trickier and it is used as url-loader's back up. Keep in mind that the usage for the two are EXTREMELY similar. For more info about the url-loader's usage, check out its configuration for the `react_on_rails` sample app [here](https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/client/webpack.client.base.config.js) (specifically lines 82-84)._
30
-
31
- ##### Configuring Webpack with file-loader
32
-
33
- Once you have added file-loader (or whatever loader you would like to use) to your project, you can start configuring your `webpack.config.js` file to bundle these assets. Inside your `module["loaders"]` list you will add a new object to represent your loader. This loader will include a few attributes:
34
-
35
- 1. `test`: a regular expression that specifies the types of files that can be loaded.
36
- 2. `loader`: the name of the loader you will be using (in this doc we will be using [file-loader](https://github.com/webpack-contrib/file-loader))
37
- 3. `query`: query parameters are additional configuration options that get passed to the loader. This can either be appended to your `loader` attribute like follows:
38
-
39
-
40
- ```javascript
41
- loader: "file-loader?name=[name].[ext]"
42
- ```
43
-
44
- or as a JSON object:
45
-
46
- ```javascript
47
- query: {
48
- name: "[name].[ext]"
49
- }
50
- ```
51
-
52
- both of these two example above do the exact same thing, just using different syntaxes. For the rest of this doc we will be using the JSON object style. For more information about webpack loaders, read [this](https://webpack.github.io/docs/using-loaders.html).
53
-
54
- _For the sake of this doc, we're also going to add a `resolve["alias"]` inside our webpack.config to make it easier to include our assets in our jsx files. In `resolve["alias"]`, simply add:_
55
-
56
- ```javascript
57
- 'assets': path.resolve('./app/assets')
58
- ```
59
-
60
- ##### Configuring your file-loader Query Parameters
61
-
62
- The first property we'll want to set is our file's resulting name after bundling. For now we're just going to use:
63
-
64
- ```javascript
65
- name: "[name][md5:hash].[ext]"
66
- ```
67
-
68
- This will just set the name to the file's original name + a md5 digested hash + the extension of the original file (.png, .jpg, etc).
69
-
70
- Next we'll set the outputPath for our files. This is the directory we want the files to be placed in after webpack runs. When Webpack runs with file-loader, all files (in this case assets) that have been used in the bundled JavaScript will be bundled and outputted to the output destination. **Keep in mind that react_on_rails outputs by default to the `app/assets/webpack/` directory so when we specify the outputPath here it will be relative the `app/assets/webpack` directory.** You can set the outputPath to whatever you want, in this example we will add it to a directory `/app/assets/webpack/webpack-assets/`, and here's how we would do that:
71
-
72
- ```javascript
73
- outputPath: "webpack-assets/"
74
- ```
75
-
76
- Note: _You can output these files in the asset pipeline wherever you see fit. My preference is outputting somewhere inside the `app/assets/webpack/` directory just because anything in this directory is already ignored by git due to the react_on_rails generated gitignore, meaning they will not be added by git twice! (once in your `client/app/assets/` and once in your outputted path after webpack bundling)_
77
-
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
-
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
-
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
-
84
- ```javascript
85
- publicPath: "/assets/webpack-assets/"
86
- ```
87
-
88
- Voila! Your webpack setup is complete.
89
-
90
- ##### Adding/Using `client/` Assets
91
-
92
- Now for the fun part, we actually get to use our client assets now. The first thing you'll want to do is create an assets directory inside your client directory. The best place for this directory is probably at `client/app/assets`. Put any assets you want in there, images, stylesheets, whatever. Now that the assets are in place, we can simply `import` or `require` them in our jsx files for use in our components. For example:
93
-
94
- ```javascript
95
- import myImage from 'assets/images/my-image.png'; // This uses the assets alias we created earlier to map to the client/app/assets/ directory followed by `images/my-image.png`
96
-
97
- export default class MyImageBox extends React.Component {
98
- constructor(props, context) {
99
- super(props, context);
100
- }
101
-
102
- render() {
103
- return <img src={myImage} />
104
- }
105
- }
106
- ```
107
-
108
- `myImage` in the example above will resolve to the path of that asset on the web server. Therefore using it as an img's source would then properly display the image/assets when this react component is rendered.
109
-
110
- Note: **Any assets in our `client/` directory that are not imported/required for use in our jsx files will NOT be bundled and outputted by webpack.**
111
-
112
- ## Summary: Welcome people who are tired of reading
113
-
114
- If you've read this far, you probably have a grip on everything. If you didn't, and want a condensed version, here you go:
115
-
116
- - Add webpack's file-loader to your project
117
- - Add a new loader module in your webpack.config.js file
118
- - Set this loader's test attribute to a regex of the file extensions you would like to load
119
- - Set the loader attribute to "file-loader"
120
- - Set name to something like `"[name][md5:hash].[ext]"`
121
- - Set outputPath attribute to directory of choice, relative to `app/assets/webpack` directory
122
- - Set publicPath attribute, this should be the same as where the rails asset pipeline will serve your asset(s) on the server. See [this](#configuring-your-file-loader-query-parameters) for more info.
123
- - Add assets directory in `client/app/`, and place whatever you would like in there
124
- - Import or Require these files in your jsx and use them all you want!
125
-
126
- ### Here's a full example of a webpack.config.js configured with file-loader to load images:
127
-
128
- ```javascript
129
- const webpack = require('webpack');
130
- const path = require('path');
131
-
132
- const devBuild = process.env.NODE_ENV !== 'production';
133
- const nodeEnv = devBuild ? 'development' : 'production';
134
-
135
- module.exports = {
136
- entry: [
137
- './app/bundles/HelloWorld/startup/registration',
138
- ],
139
-
140
- output: {
141
- filename: 'hello-world-bundle.js',
142
- path: '../app/assets/webpack'
143
- },
144
-
145
- resolve: {
146
- extensions: ['', '.js', '.jsx'],
147
- alias: {
148
- assets: path.resolve('./app/assets'), // Makes it easier to reference our assets in jsx files
149
- react: path.resolve('./node_modules/react'),
150
- 'react-dom': path.resolve('./node_modules/react-dom'),
151
- },
152
- },
153
-
154
- plugins: [
155
- new webpack.DefinePlugin({
156
- 'process.env': {
157
- NODE_ENV: JSON.stringify(nodeEnv),
158
- }
159
- })
160
- ],
161
- module: {
162
- rules: [
163
- {
164
- test: /\.jsx?$/,
165
- loader: 'babel-loader',
166
- exclude: /node_modules/,
167
- },
168
- {
169
- test: require.resolve('react'),
170
- use: {
171
- loader: 'imports-loader',
172
- options: {
173
- shim: 'es5-shim/es5-shim',
174
- sham: 'es5-shim/es5-sham',
175
- },
176
- }
177
- },
178
- {
179
- // The important stuff
180
- test: /\.(jpg|jpeg|png)(\?.*)?$/, // Load only .jpg .jpeg, and .png files
181
- use: {
182
- loader: 'file-loader',
183
- options: {
184
- name: '[name][md5:hash].[ext]', // Name of bundled asset
185
- outputPath: 'webpack-assets/', // Output location for assets. Final: `app/assets/webpack/webpack-assets/`
186
- publicPath: '/assets/webpack-assets/' // Endpoint asset can be found at on Rails server
187
- }
188
- }
189
- }
190
- ]
191
- }
192
- };
193
- ```
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](https://www.shakacode.com/react-on-rails/docs/outdated/rails-assets/).