Class: ReactOnRails::PacksGenerator
- Inherits:
-
Object
- Object
- ReactOnRails::PacksGenerator
- Defined in:
- lib/react_on_rails/packs_generator.rb
Overview
rubocop:disable Metrics/ClassLength
This class handles two INDEPENDENT classification systems:
-
BUNDLE PLACEMENT (.client. / .server. file suffixes) Controls which webpack bundle imports a file. Pre-dates React Server Components.
-
Component.client.jsx → client bundle only
-
Component.server.jsx → server bundle (and RSC bundle when RSC enabled; requires a paired .client. file)
-
Component.jsx (no suffix) → both bundles
These suffixes only make sense for client components, as server components exist only in the RSC bundle. Methods: common_component_to_path, client_component_to_path, server_component_to_path
-
-
RSC CLASSIFICATION (‘use client’ directive) Controls how a component is registered when RSC support is enabled (Pro feature).
-
Has ‘use client’ → ReactOnRails.register() → React Client Component
-
Lacks ‘use client’ → registerServerComponent() → React Server Component
Method: client_entrypoint?
-
These are orthogonal. A .client.jsx file can be a React Server Component (if it lacks ‘use client’), and a .server.jsx file can be a React Client Component (if it has ‘use client’).
Constant Summary collapse
- CONTAINS_CLIENT_OR_SERVER_REGEX =
/\.(server|client)($|\.)/- COMPONENT_EXTENSIONS =
/\.(jsx?|tsx?)$/- MINIMUM_SHAKAPACKER_VERSION_FOR_AUTO_BUNDLING =
Auto-registration requires nested_entries support which was added in 7.0.0 Note: The gemspec requires Shakapacker >= 6.0 for basic functionality
"7.0.0"
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.instance ⇒ Object
36 37 38 |
# File 'lib/react_on_rails/packs_generator.rb', line 36 def self.instance @instance ||= PacksGenerator.new end |
Instance Method Details
#generate_packs_if_stale ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/react_on_rails/packs_generator.rb', line 46 def generate_packs_if_stale return unless ReactOnRails.configuration.auto_load_bundle verbose = ENV["REACT_ON_RAILS_VERBOSE"] == "true" add_generated_pack_to_server_bundle # Clean any non-generated files from directories clean_non_generated_files_with_feedback(verbose: verbose) are_generated_files_present_and_up_to_date = Dir.exist?(generated_packs_directory_path) && File.exist?(generated_server_bundle_file_path) && !stale_or_missing_packs? if are_generated_files_present_and_up_to_date puts Rainbow("✅ Generated packs are up to date, no regeneration needed").green if verbose return end clean_generated_directories_with_feedback(verbose: verbose) generate_packs(verbose: verbose) end |
#react_on_rails_npm_package ⇒ Object
40 41 42 43 44 |
# File 'lib/react_on_rails/packs_generator.rb', line 40 def react_on_rails_npm_package return "react-on-rails-pro" if ReactOnRails::Utils.react_on_rails_pro? "react-on-rails" end |