shakapacker 7.0.0.rc.0 → 7.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +4 -4
  2. data/.github/PULL_REQUEST_TEMPLATE.md +4 -8
  3. data/.github/workflows/dummy.yml +21 -0
  4. data/.github/workflows/generator.yml +37 -0
  5. data/.github/workflows/jest.yml +2 -2
  6. data/.github/workflows/js-lint.yml +2 -2
  7. data/.github/workflows/rubocop.yml +1 -1
  8. data/.github/workflows/ruby-backward-compatibility.yml +2 -6
  9. data/.github/workflows/ruby.yml +2 -6
  10. data/.gitignore +3 -0
  11. data/CHANGELOG.md +16 -18
  12. data/CONTRIBUTING.md +76 -20
  13. data/README.md +3 -1
  14. data/Rakefile +44 -8
  15. data/docs/deployment.md +1 -2
  16. data/lib/install/binstubs.rb +3 -1
  17. data/lib/install/config/webpack/webpack.config.js +3 -2
  18. data/lib/install/template.rb +27 -15
  19. data/lib/shakapacker/deprecation_helper.rb +4 -5
  20. data/lib/shakapacker/version.rb +1 -1
  21. data/lib/tasks/shakapacker/check_binstubs.rake +14 -10
  22. data/lib/tasks/shakapacker/compile.rake +1 -6
  23. data/package/index.js +16 -0
  24. data/package/utils/helpers.js +1 -1
  25. data/package.json +1 -1
  26. data/spec/dummy/.browserslistrc +1 -0
  27. data/spec/dummy/.gitignore +20 -0
  28. data/spec/dummy/.prettierrc.yaml +4 -0
  29. data/spec/dummy/Gemfile +63 -0
  30. data/spec/dummy/Procfile.dev +5 -0
  31. data/spec/dummy/Procfile.dev-static +9 -0
  32. data/spec/dummy/README.md +1 -0
  33. data/spec/dummy/Rakefile +6 -0
  34. data/spec/dummy/app/assets/config/manifest.js +2 -0
  35. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  36. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  37. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  38. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  39. data/spec/dummy/app/controllers/hello_world_controller.rb +9 -0
  40. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  41. data/spec/dummy/app/javascript/Globals.d.ts +3 -0
  42. data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css +25 -0
  43. data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorld.tsx +47 -0
  44. data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorldServer.tsx +5 -0
  45. data/spec/dummy/app/javascript/bundles/HelloWorld/components/logo.svg +7 -0
  46. data/spec/dummy/app/javascript/packs/application.js +17 -0
  47. data/spec/dummy/app/javascript/packs/hello-world-bundle.ts +8 -0
  48. data/spec/dummy/app/javascript/packs/server-bundle.ts +8 -0
  49. data/spec/dummy/app/jobs/application_job.rb +7 -0
  50. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  51. data/spec/dummy/app/models/application_record.rb +3 -0
  52. data/spec/dummy/app/models/concerns/.keep +0 -0
  53. data/spec/dummy/app/views/hello_world/index.html.erb +2 -0
  54. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  55. data/spec/dummy/app/views/layouts/hello_world.html.erb +13 -0
  56. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  57. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  58. data/spec/dummy/babel.config.js +30 -0
  59. data/spec/dummy/bin/bundle +114 -0
  60. data/spec/dummy/bin/dev +30 -0
  61. data/spec/dummy/bin/dev-static +30 -0
  62. data/spec/dummy/bin/rails +9 -0
  63. data/spec/dummy/bin/rake +9 -0
  64. data/spec/dummy/bin/setup +33 -0
  65. data/spec/dummy/bin/shakapacker +13 -0
  66. data/spec/dummy/bin/shakapacker-dev-server +13 -0
  67. data/spec/dummy/bin/spring +17 -0
  68. data/spec/dummy/bin/yarn +18 -0
  69. data/spec/dummy/config/application.rb +32 -0
  70. data/spec/dummy/config/boot.rb +4 -0
  71. data/spec/dummy/config/cable.yml +10 -0
  72. data/spec/dummy/config/credentials.yml.enc +1 -0
  73. data/spec/dummy/config/database.yml +25 -0
  74. data/spec/dummy/config/environment.rb +5 -0
  75. data/spec/dummy/config/environments/development.rb +54 -0
  76. data/spec/dummy/config/environments/production.rb +106 -0
  77. data/spec/dummy/config/environments/test.rb +49 -0
  78. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  79. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  80. data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
  81. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  82. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  83. data/spec/dummy/config/initializers/inflections.rb +16 -0
  84. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  85. data/spec/dummy/config/initializers/react_on_rails.rb +58 -0
  86. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  87. data/spec/dummy/config/locales/en.yml +33 -0
  88. data/spec/dummy/config/puma.rb +38 -0
  89. data/spec/dummy/config/routes.rb +6 -0
  90. data/spec/dummy/config/shakapacker.yml +62 -0
  91. data/spec/dummy/config/spring.rb +6 -0
  92. data/spec/dummy/config/storage.yml +34 -0
  93. data/spec/dummy/config/webpack/ServerClientOrBoth.js +34 -0
  94. data/spec/dummy/config/webpack/clientWebpackConfig.js +15 -0
  95. data/spec/dummy/config/webpack/commonWebpackConfig.js +18 -0
  96. data/spec/dummy/config/webpack/development.js +32 -0
  97. data/spec/dummy/config/webpack/production.js +9 -0
  98. data/spec/dummy/config/webpack/serverWebpackConfig.js +116 -0
  99. data/spec/dummy/config/webpack/test.js +7 -0
  100. data/spec/dummy/config/webpack/webpack.config.js +24 -0
  101. data/spec/dummy/config.ru +5 -0
  102. data/spec/dummy/db/seeds.rb +7 -0
  103. data/spec/dummy/lib/assets/.keep +0 -0
  104. data/spec/dummy/lib/tasks/.keep +0 -0
  105. data/spec/dummy/package.json +44 -0
  106. data/spec/dummy/postcss.config.js +12 -0
  107. data/spec/dummy/public/404.html +67 -0
  108. data/spec/dummy/public/422.html +67 -0
  109. data/spec/dummy/public/500.html +66 -0
  110. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  111. data/spec/dummy/public/apple-touch-icon.png +0 -0
  112. data/spec/dummy/public/favicon.ico +0 -0
  113. data/spec/dummy/public/robots.txt +1 -0
  114. data/spec/dummy/spec/rails_helper.rb +118 -0
  115. data/spec/dummy/spec/spec_helper.rb +96 -0
  116. data/spec/dummy/spec/system/hello_world_spec.rb +19 -0
  117. data/spec/dummy/tsconfig.json +21 -0
  118. data/spec/dummy/vendor/.keep +0 -0
  119. data/spec/dummy/yarn.lock +4697 -0
  120. data/spec/generator_specs/e2e_template/files/app/controllers/home_controller.rb +4 -0
  121. data/spec/generator_specs/e2e_template/files/app/javascript/components/App.js +12 -0
  122. data/spec/generator_specs/e2e_template/files/app/javascript/packs/application.js +10 -0
  123. data/spec/generator_specs/e2e_template/files/app/views/home/index.html.erb +2 -0
  124. data/spec/generator_specs/e2e_template/files/app/views/layouts/application.html.erb +17 -0
  125. data/spec/generator_specs/e2e_template/files/config/routes.rb +3 -0
  126. data/spec/generator_specs/e2e_template/files/spec/system/test_react_component_renders_spec.rb +13 -0
  127. data/spec/generator_specs/e2e_template/template.rb +21 -0
  128. data/spec/generator_specs/generator_spec.rb +169 -0
  129. data/spec/{configuration_spec.rb → shakapacker/configuration_spec.rb} +10 -10
  130. data/spec/{dev_server_runner_spec.rb → shakapacker/dev_server_runner_spec.rb} +1 -1
  131. data/spec/{engine_rake_tasks_spec.rb → shakapacker/engine_rake_tasks_spec.rb} +2 -2
  132. data/spec/{manifest_spec.rb → shakapacker/manifest_spec.rb} +1 -1
  133. data/spec/shakapacker/rake_tasks_spec.rb +93 -0
  134. data/spec/{spec_helper_initializer.rb → shakapacker/spec_helper_initializer.rb} +1 -1
  135. data/spec/shakapacker/test_app/config/webpack/webpack.config.js +0 -0
  136. data/spec/shakapacker/test_app/some.config.js +0 -0
  137. data/spec/{version_checker_spec.rb → shakapacker/version_checker_spec.rb} +9 -9
  138. data/spec/{webpack_runner_spec.rb → shakapacker/webpack_runner_spec.rb} +1 -1
  139. metadata +170 -64
  140. data/gemfiles/Gemfile-rails.5.2.x +0 -9
  141. data/spec/rake_tasks_spec.rb +0 -34
  142. /data/docs/{developing_webpacker.md → developing_shakapacker.md} +0 -0
  143. /data/spec/backward_compatibility_specs/{command_spec_bc.rb → command_spec.rb} +0 -0
  144. /data/spec/backward_compatibility_specs/{compiler_spec_bc.rb → compiler_spec.rb} +0 -0
  145. /data/spec/backward_compatibility_specs/{compiler_strategy_spec_bc.rb → compiler_strategy_spec.rb} +0 -0
  146. /data/spec/backward_compatibility_specs/{configuration_spec_bc.rb → configuration_spec.rb} +0 -0
  147. /data/spec/backward_compatibility_specs/{dev_server_runner_spec_bc.rb → dev_server_runner_spec.rb} +0 -0
  148. /data/spec/backward_compatibility_specs/{dev_server_spec_bc.rb → dev_server_spec.rb} +0 -0
  149. /data/spec/backward_compatibility_specs/{digest_strategy_spec_bc.rb → digest_strategy_spec.rb} +0 -0
  150. /data/spec/backward_compatibility_specs/{engine_rake_tasks_spec_bc.rb → engine_rake_tasks_spec.rb} +0 -0
  151. /data/spec/backward_compatibility_specs/{env_spec_bc.rb → env_spec.rb} +0 -0
  152. /data/spec/backward_compatibility_specs/{helper_spec_bc.rb → helper_spec.rb} +0 -0
  153. /data/spec/backward_compatibility_specs/{instance_spec_bc.rb → instance_spec.rb} +0 -0
  154. /data/spec/backward_compatibility_specs/{manifest_spec_bc.rb → manifest_spec.rb} +0 -0
  155. /data/spec/backward_compatibility_specs/{mtime_strategy_spec_bc.rb → mtime_strategy_spec.rb} +0 -0
  156. /data/spec/backward_compatibility_specs/{rake_tasks_spec_bc.rb → rake_tasks_spec.rb} +0 -0
  157. /data/spec/backward_compatibility_specs/{webpack_runner_spec_bc.rb → webpack_runner_spec.rb} +0 -0
  158. /data/spec/backward_compatibility_specs/{webpacker_spec_bc.rb → webpacker_spec.rb} +0 -0
  159. /data/spec/{test_app/config/webpack/webpack.config.js → dummy/app/assets/images/.keep} +0 -0
  160. /data/spec/{test_app/some.config.js → dummy/app/controllers/concerns/.keep} +0 -0
  161. /data/spec/{command_spec.rb → shakapacker/command_spec.rb} +0 -0
  162. /data/spec/{compiler_spec.rb → shakapacker/compiler_spec.rb} +0 -0
  163. /data/spec/{compiler_strategy_spec.rb → shakapacker/compiler_strategy_spec.rb} +0 -0
  164. /data/spec/{dev_server_spec.rb → shakapacker/dev_server_spec.rb} +0 -0
  165. /data/spec/{digest_strategy_spec.rb → shakapacker/digest_strategy_spec.rb} +0 -0
  166. /data/spec/{env_spec.rb → shakapacker/env_spec.rb} +0 -0
  167. /data/spec/{helper_spec.rb → shakapacker/helper_spec.rb} +0 -0
  168. /data/spec/{instance_spec.rb → shakapacker/instance_spec.rb} +0 -0
  169. /data/spec/{mtime_strategy_spec.rb → shakapacker/mtime_strategy_spec.rb} +0 -0
  170. /data/spec/{webpacker_spec.rb → shakapacker/shakapacker_spec.rb} +0 -0
  171. /data/spec/{test_app → shakapacker/test_app}/.gitignore +0 -0
  172. /data/spec/{test_app → shakapacker/test_app}/Rakefile +0 -0
  173. /data/spec/{test_app → shakapacker/test_app}/app/javascript/entrypoints/application.js +0 -0
  174. /data/spec/{test_app → shakapacker/test_app}/app/javascript/entrypoints/generated/something.js +0 -0
  175. /data/spec/{test_app → shakapacker/test_app}/app/javascript/entrypoints/multi_entry.css +0 -0
  176. /data/spec/{test_app → shakapacker/test_app}/app/javascript/entrypoints/multi_entry.js +0 -0
  177. /data/spec/{test_app → shakapacker/test_app}/bin/shakapacker +0 -0
  178. /data/spec/{test_app → shakapacker/test_app}/bin/shakapacker-dev-server +0 -0
  179. /data/spec/{test_app → shakapacker/test_app}/config/application.rb +0 -0
  180. /data/spec/{test_app → shakapacker/test_app}/config/environment.rb +0 -0
  181. /data/spec/{test_app → shakapacker/test_app}/config/initializers/inspect_autoload_paths.rb +0 -0
  182. /data/spec/{test_app → shakapacker/test_app}/config/shakapacker.yml +0 -0
  183. /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_css_extract_ignore_order_warnings.yml +0 -0
  184. /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_defaults_fallback.yml +0 -0
  185. /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_manifest_path.yml +0 -0
  186. /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_nested_entries.yml +0 -0
  187. /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_no_precompile.yml +0 -0
  188. /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_other_location.yml +0 -0
  189. /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_public_root.yml +0 -0
  190. /data/spec/{test_app → shakapacker/test_app}/config.ru +0 -0
  191. /data/spec/{test_app → shakapacker/test_app}/package.json +0 -0
  192. /data/spec/{test_app → shakapacker/test_app}/public/packs/manifest.json +0 -0
  193. /data/spec/{test_app → shakapacker/test_app}/yarn.lock +0 -0
@@ -0,0 +1,33 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # The following keys must be escaped otherwise they will not be retrieved by
20
+ # the default I18n backend:
21
+ #
22
+ # true, false, on, off, yes, no
23
+ #
24
+ # Instead, surround them with single quotes.
25
+ #
26
+ # en:
27
+ # 'true': 'foo'
28
+ #
29
+ # To learn more, please read the Rails Internationalization guide
30
+ # available at https://guides.rubyonrails.org/i18n.html.
31
+
32
+ en:
33
+ hello: "Hello world"
@@ -0,0 +1,38 @@
1
+ # Puma can serve each request in a thread from an internal thread pool.
2
+ # The `threads` method setting takes two numbers: a minimum and maximum.
3
+ # Any libraries that use thread pools should be configured to match
4
+ # the maximum value specified for Puma. Default is set to 5 threads for minimum
5
+ # and maximum; this matches the default thread size of Active Record.
6
+ #
7
+ max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
8
+ min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
9
+ threads min_threads_count, max_threads_count
10
+
11
+ # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
12
+ #
13
+ port ENV.fetch("PORT") { 3000 }
14
+
15
+ # Specifies the `environment` that Puma will run in.
16
+ #
17
+ environment ENV.fetch("RAILS_ENV") { "development" }
18
+
19
+ # Specifies the `pidfile` that Puma will use.
20
+ pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
21
+
22
+ # Specifies the number of `workers` to boot in clustered mode.
23
+ # Workers are forked web server processes. If using threads and workers together
24
+ # the concurrency of the application would be max `threads` * `workers`.
25
+ # Workers do not work on JRuby or Windows (both of which do not support
26
+ # processes).
27
+ #
28
+ # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
29
+
30
+ # Use the `preload_app!` method when specifying a `workers` number.
31
+ # This directive tells Puma to first boot the application and load code
32
+ # before forking the application. This takes advantage of Copy On Write
33
+ # process behavior so workers use less memory.
34
+ #
35
+ # preload_app!
36
+
37
+ # Allow puma to be restarted by `rails restart` command.
38
+ plugin :tmp_restart
@@ -0,0 +1,6 @@
1
+ Rails.application.routes.draw do
2
+ get "hello_world", to: "hello_world#index"
3
+
4
+ get "/", to: redirect("/hello_world")
5
+ # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
6
+ end
@@ -0,0 +1,62 @@
1
+ # Note: You must restart bin/webpacker-dev-server for changes to take effect
2
+
3
+ default: &default
4
+ source_path: app/javascript
5
+ source_entry_path: packs
6
+ public_root_path: public
7
+ public_output_path: packs
8
+ cache_path: tmp/webpacker
9
+ webpack_compile_output: true
10
+
11
+ # Additional paths webpack should lookup modules
12
+ # ['app/assets', 'engine/foo/app/assets']
13
+ additional_paths: []
14
+
15
+ # Reload manifest.json on all requests so we reload latest compiled packs
16
+ cache_manifest: false
17
+
18
+ development:
19
+ <<: *default
20
+ # This is false since we're running `bin/webpacker -w` in Procfile.dev-setic
21
+ compile: false
22
+
23
+ # Reference: https://webpack.js.org/configuration/dev-server/
24
+ dev_server:
25
+ https: false
26
+ host: localhost
27
+ port: 3035
28
+ # Hot Module Replacement updates modules while the application is running without a full reload
29
+ hmr: true
30
+ client:
31
+ # Should we show a full-screen overlay in the browser when there are compiler errors or warnings?
32
+ overlay: true
33
+ # May also be a string
34
+ # webSocketURL:
35
+ # hostname: "0.0.0.0"
36
+ # pathname: "/ws"
37
+ # port: 8080
38
+ compress: true
39
+ # Note that apps that do not check the host are vulnerable to DNS rebinding attacks
40
+ allowed_hosts: [ 'localhost' ]
41
+ pretty: true
42
+ headers:
43
+ 'Access-Control-Allow-Origin': '*'
44
+ static:
45
+ watch:
46
+ ignored: '**/node_modules/**'
47
+
48
+ test:
49
+ <<: *default
50
+ compile: true
51
+
52
+ # Compile test packs to a separate directory
53
+ public_output_path: packs-test
54
+
55
+ production:
56
+ <<: *default
57
+
58
+ # Production depends on precompilation of packs prior to booting for performance.
59
+ compile: false
60
+
61
+ # Cache manifest.json for performance
62
+ cache_manifest: true
@@ -0,0 +1,6 @@
1
+ Spring.watch(
2
+ ".ruby-version",
3
+ ".rbenv-vars",
4
+ "tmp/restart.txt",
5
+ "tmp/caching-dev.txt"
6
+ )
@@ -0,0 +1,34 @@
1
+ test:
2
+ service: Disk
3
+ root: <%= Rails.root.join("tmp/storage") %>
4
+
5
+ local:
6
+ service: Disk
7
+ root: <%= Rails.root.join("storage") %>
8
+
9
+ # Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
10
+ # amazon:
11
+ # service: S3
12
+ # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
13
+ # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
14
+ # region: us-east-1
15
+ # bucket: your_own_bucket
16
+
17
+ # Remember not to checkin your GCS keyfile to a repository
18
+ # google:
19
+ # service: GCS
20
+ # project: your_project
21
+ # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
22
+ # bucket: your_own_bucket
23
+
24
+ # Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
25
+ # microsoft:
26
+ # service: AzureStorage
27
+ # storage_account_name: your_account_name
28
+ # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
29
+ # container: your_container_name
30
+
31
+ # mirror:
32
+ # service: Mirror
33
+ # primary: local
34
+ # mirrors: [ amazon, google, microsoft ]
@@ -0,0 +1,34 @@
1
+ const clientWebpackConfig = require('./clientWebpackConfig')
2
+ const serverWebpackConfig = require('./serverWebpackConfig')
3
+
4
+ const webpackConfig = (envSpecific) => {
5
+ const clientConfig = clientWebpackConfig()
6
+ const serverConfig = serverWebpackConfig()
7
+
8
+ if (envSpecific) {
9
+ envSpecific(clientConfig, serverConfig)
10
+ }
11
+
12
+ let result
13
+ // For HMR, need to separate the the client and server webpack configurations
14
+ if (process.env.WEBPACK_SERVE || process.env.CLIENT_BUNDLE_ONLY) {
15
+ // eslint-disable-next-line no-console
16
+ console.log('[React on Rails] Creating only the client bundles.')
17
+ result = clientConfig
18
+ } else if (process.env.SERVER_BUNDLE_ONLY) {
19
+ // eslint-disable-next-line no-console
20
+ console.log('[React on Rails] Creating only the server bundle.')
21
+ result = serverConfig
22
+ } else {
23
+ // default is the standard client and server build
24
+ // eslint-disable-next-line no-console
25
+ console.log('[React on Rails] Creating both client and server bundles.')
26
+ result = [clientConfig, serverConfig]
27
+ }
28
+
29
+ // To debug, uncomment next line and inspect "result"
30
+ // debugger
31
+ return result
32
+ }
33
+
34
+ module.exports = webpackConfig
@@ -0,0 +1,15 @@
1
+ const commonWebpackConfig = require('./commonWebpackConfig')
2
+
3
+ const configureClient = () => {
4
+ const clientConfig = commonWebpackConfig()
5
+
6
+ // server-bundle is special and should ONLY be built by the serverConfig
7
+ // In case this entry is not deleted, a very strange "window" not found
8
+ // error shows referring to window["webpackJsonp"]. That is because the
9
+ // client config is going to try to load chunks.
10
+ delete clientConfig.entry['server-bundle']
11
+
12
+ return clientConfig
13
+ }
14
+
15
+ module.exports = configureClient
@@ -0,0 +1,18 @@
1
+ // Common configuration applying to client and server configuration
2
+
3
+ // const { globalMutableWebpackConfig: baseClientWebpackConfig, merge } = require('shakapacker')
4
+ const { generateWebpackConfig, merge } = require('shakapacker')
5
+ const commonOptions = {
6
+ resolve: {
7
+ extensions: ['.css', '.ts', '.tsx']
8
+ }
9
+ }
10
+
11
+ const ignoreWarningsConfig = {
12
+ ignoreWarnings: [/Module not found: Error: Can't resolve 'react-dom\/client'/],
13
+ };
14
+ // Copy the object using merge b/c the baseClientWebpackConfig and commonOptions are mutable globals
15
+ // const commonWebpackConfig = () => (merge({}, baseClientWebpackConfig, commonOptions))
16
+ const commonWebpackConfig = () => (merge({}, generateWebpackConfig(), commonOptions, ignoreWarningsConfig))
17
+
18
+ module.exports = commonWebpackConfig
@@ -0,0 +1,32 @@
1
+ const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
2
+ const path = require('path')
3
+ const { devServer, inliningCss } = require('shakapacker')
4
+
5
+ const webpackConfig = require('./ServerClientOrBoth')
6
+
7
+ const developmentEnvOnly = (clientWebpackConfig, serverWebpackConfig) => {
8
+
9
+ //plugins
10
+ if (inliningCss ) {
11
+ // Note, when this is run, we're building the server and client bundles in separate processes.
12
+ // Thus, this plugin is not applied.
13
+ const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin')
14
+ clientWebpackConfig.plugins.push(
15
+ new ReactRefreshWebpackPlugin({
16
+ overlay:{
17
+ sockPort: devServer.port
18
+ }
19
+ })
20
+ )
21
+ }
22
+
23
+ clientWebpackConfig.plugins.push(
24
+ new ForkTsCheckerWebpackPlugin({
25
+ typescript: {
26
+ configFile: path.resolve(__dirname, '../../tsconfig.json')
27
+ },
28
+ async: false
29
+ })
30
+ )
31
+ }
32
+ module.exports = webpackConfig(developmentEnvOnly)
@@ -0,0 +1,9 @@
1
+ // Below code should get refactored but the current way that rails/webpacker v5
2
+ // does the globals, it's tricky
3
+ const webpackConfig = require('./ServerClientOrBoth')
4
+
5
+ const productionEnvOnly = (_clientWebpackConfig, _serverWebpackConfig) => {
6
+ // place any code here that is for production only
7
+ }
8
+
9
+ module.exports = webpackConfig(productionEnvOnly)
@@ -0,0 +1,116 @@
1
+ const { merge, config } = require('shakapacker')
2
+ const commonWebpackConfig = require('./commonWebpackConfig')
3
+
4
+ const webpack = require('webpack')
5
+
6
+ const configureServer = () => {
7
+ // We need to use "merge" because the clientConfigObject, EVEN after running
8
+ // toWebpackConfig() is a mutable GLOBAL. Thus any changes, like modifying the
9
+ // entry value will result in changing the client config!
10
+ // Using webpack-merge into an empty object avoids this issue.
11
+ const serverWebpackConfig = commonWebpackConfig()
12
+
13
+ // We just want the single server bundle entry
14
+ const serverEntry = {
15
+ 'server-bundle': serverWebpackConfig.entry['server-bundle']
16
+ }
17
+
18
+ if (!serverEntry['server-bundle']) {
19
+ throw new Error('Create a pack with the file name \'server-bundle.js\' containing all the server rendering files')
20
+ }
21
+
22
+ serverWebpackConfig.entry = serverEntry
23
+
24
+ // Remove the mini-css-extract-plugin from the style loaders because
25
+ // the client build will handle exporting CSS.
26
+ // replace file-loader with null-loader
27
+ serverWebpackConfig.module.rules.forEach((loader) => {
28
+ if (loader.use && loader.use.filter) {
29
+ loader.use = loader.use.filter(
30
+ (item) =>
31
+ !(typeof item === 'string' && item.match(/mini-css-extract-plugin/))
32
+ )
33
+ }
34
+ })
35
+
36
+ // No splitting of chunks for a server bundle
37
+ serverWebpackConfig.optimization = {
38
+ minimize: false
39
+ }
40
+ serverWebpackConfig.plugins.unshift(
41
+ new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 })
42
+ )
43
+
44
+ // Custom output for the server-bundle that matches the config in
45
+ // config/initializers/react_on_rails.rb
46
+ serverWebpackConfig.output = {
47
+ filename: 'server-bundle.js',
48
+ globalObject: 'this',
49
+ // If using the React on Rails Pro node server renderer, uncomment the next line
50
+ // libraryTarget: 'commonjs2',
51
+ path: config.outputPath,
52
+ publicPath: config.publicPath,
53
+ // https://webpack.js.org/configuration/output/#outputglobalobject
54
+ }
55
+
56
+ // Don't hash the server bundle b/c would conflict with the client manifest
57
+ // And no need for the MiniCssExtractPlugin
58
+ serverWebpackConfig.plugins = serverWebpackConfig.plugins.filter(
59
+ (plugin) =>
60
+ plugin.constructor.name !== 'WebpackAssetsManifest' &&
61
+ plugin.constructor.name !== 'MiniCssExtractPlugin' &&
62
+ plugin.constructor.name !== 'ForkTsCheckerWebpackPlugin'
63
+ )
64
+
65
+ // Configure loader rules for SSR
66
+ // Remove the mini-css-extract-plugin from the style loaders because
67
+ // the client build will handle exporting CSS.
68
+ // replace file-loader with null-loader
69
+ const rules = serverWebpackConfig.module.rules;
70
+ rules.forEach((rule) => {
71
+ if (Array.isArray(rule.use)) {
72
+ // remove the mini-css-extract-plugin and style-loader
73
+ rule.use = rule.use.filter((item) => {
74
+ let testValue;
75
+ if (typeof item === 'string') {
76
+ testValue = item;
77
+ } else if (typeof item.loader === 'string') {
78
+ testValue = item.loader;
79
+ }
80
+ return !(testValue.match(/mini-css-extract-plugin/) || testValue === 'style-loader');
81
+ });
82
+ const cssLoader = rule.use.find((item) => {
83
+ let testValue;
84
+
85
+ if (typeof item === 'string') {
86
+ testValue = item;
87
+ } else if (typeof item.loader === 'string') {
88
+ testValue = item.loader;
89
+ }
90
+
91
+ return testValue.includes('css-loader');
92
+ });
93
+ if (cssLoader && cssLoader.options) {
94
+ cssLoader.options.modules = { exportOnlyLocals: true };
95
+ }
96
+
97
+ // Skip writing image files during SSR by setting emitFile to false
98
+ } else if (rule.use && (rule.use.loader === 'url-loader' || rule.use.loader === 'file-loader')) {
99
+ rule.use.options.emitFile = false;
100
+ }
101
+ });
102
+
103
+ // eval works well for the SSR bundle because it's the fastest and shows
104
+ // lines in the server bundle which is good for debugging SSR
105
+ // The default of cheap-module-source-map is slow and provides poor info.
106
+ serverWebpackConfig.devtool = 'eval'
107
+
108
+ // If using the default 'web', then libraries like Emotion and loadable-components
109
+ // break with SSR. The fix is to use a node renderer and change the target.
110
+ // If using the React on Rails Pro node server renderer, uncomment the next line
111
+ // serverWebpackConfig.target = 'node'
112
+
113
+ return serverWebpackConfig
114
+ }
115
+
116
+ module.exports = configureServer
@@ -0,0 +1,7 @@
1
+ const webpackConfig = require('./ServerClientOrBoth')
2
+
3
+ const testOnly = (_clientWebpackConfig, _serverWebpackConfig) => {
4
+ // place any code here that is for test only
5
+ }
6
+
7
+ module.exports = webpackConfig(testOnly)
@@ -0,0 +1,24 @@
1
+ const { env, webpackConfig } = require('shakapacker')
2
+ const { existsSync } = require('fs')
3
+ const { resolve } = require('path')
4
+
5
+ const envSpecificConfig = () => {
6
+ const path = resolve(__dirname, `${env.nodeEnv}.js`)
7
+ if (existsSync(path)) {
8
+ console.log(`Loading ENV specific webpack configuration file ${path}`)
9
+ return require(path)
10
+ } else {
11
+ return webpackConfig
12
+ }
13
+ }
14
+
15
+ const webpackConfiguration = envSpecificConfig()
16
+
17
+ // To debug the webpack configuration
18
+ // 1. Uncomment debugger line below
19
+ // 2. Run `bin/webpacker --debug-webpacker`
20
+ // 3. Examine the webpackConfiguration variable
21
+ // 4. Consider adding a 'debugger` line to the beginning of this file.
22
+ // debugger
23
+
24
+ module.exports = webpackConfiguration
@@ -0,0 +1,5 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require_relative "config/environment"
4
+
5
+ run Rails.application
@@ -0,0 +1,7 @@
1
+ # This file should contain all the record creation needed to seed the database with its default values.
2
+ # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
3
+ #
4
+ # Examples:
5
+ #
6
+ # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
7
+ # Character.create(name: 'Luke', movie: movies.first)
File without changes
File without changes
@@ -0,0 +1,44 @@
1
+ {
2
+ "engines": {
3
+ "node": ">=12.13.0",
4
+ "yarn": ">=1 <4"
5
+ },
6
+ "dependencies": {
7
+ "@babel/core": "^7.18.2",
8
+ "@babel/plugin-transform-runtime": "^7.18.2",
9
+ "@babel/preset-env": "^7.18.2",
10
+ "@babel/preset-react": "^7.18.6",
11
+ "@babel/preset-typescript": "^7.17.12",
12
+ "@babel/runtime": "^7.18.3",
13
+ "@types/react": "^16.14.26",
14
+ "@types/react-dom": "^16.9.16",
15
+ "babel-loader": "^8.2.5",
16
+ "babel-plugin-macros": "^3.1.0",
17
+ "babel-plugin-transform-react-remove-prop-types": "^0.4.24",
18
+ "compression-webpack-plugin": "^9.2.0",
19
+ "css-loader": "^6.7.3",
20
+ "css-minimizer-webpack-plugin": "^4.2.2",
21
+ "mini-css-extract-plugin": "^2.7.2",
22
+ "pnp-webpack-plugin": "^1.7.0",
23
+ "prop-types": "^15.8.1",
24
+ "react": "^18.2.0",
25
+ "react-dom": "^18.2.0",
26
+ "react-on-rails": "13.3.2",
27
+ "shakapacker": "file:.yalc/shakapacker",
28
+ "style-loader": "^3.3.1",
29
+ "terser-webpack-plugin": "^5.3.3",
30
+ "typescript": "^4.7.3",
31
+ "webpack": "^5.73.0",
32
+ "webpack-assets-manifest": "^5.1.0",
33
+ "webpack-cli": "^4.9.2",
34
+ "webpack-merge": "^5.8.0",
35
+ "webpack-sources": "^3.2.3"
36
+ },
37
+ "devDependencies": {
38
+ "@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
39
+ "fork-ts-checker-webpack-plugin": "^6.5.2",
40
+ "react-refresh": "^0.14.0",
41
+ "webpack-dev-server": "^4.9.2"
42
+ },
43
+ "packageManager": "yarn@3.2.1"
44
+ }
@@ -0,0 +1,12 @@
1
+ module.exports = {
2
+ plugins: [
3
+ require('postcss-import'),
4
+ require('postcss-flexbugs-fixes'),
5
+ require('postcss-preset-env')({
6
+ autoprefixer: {
7
+ flexbox: 'no-2009'
8
+ },
9
+ stage: 3
10
+ })
11
+ ]
12
+ }
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>