Module: ReactOnRails::Dev::ServerMode
- Defined in:
- lib/react_on_rails/dev/server_mode.rb
Constant Summary collapse
- DEFAULT_SHAKAPACKER_CONFIG_PATH =
"config/shakapacker.yml"- MODE_TEXT =
{ hmr: { command_label: "(none) / hmr", command_description: "Start development server with HMR (default)", procfile_description: "HMR development with webpack-dev-server", procfile_dev_label: "HMR Procfile.dev", launcher_description: "HMR development (bin/dev default)", mode_heading: "🔥 HMR Development mode (default)", next_step_label: "HMR", workflow_suffix: "for HMR", shared_output_warning: "Do not combine shared output path with bin/dev (HMR)", refresh_guidance: "Ensure you're running HMR mode: bin/dev (not bin/dev static)", refresh_note: "Note: React Refresh only works in HMR mode, not static mode" }, live_reload: { command_label: "(none)", command_description: "Start development server with live reload (default)", procfile_description: "Live reload development with webpack-dev-server", procfile_dev_label: "Live reload Procfile.dev", launcher_description: "Live reload development (bin/dev default)", mode_heading: "🔁 Live reload development mode (default)", next_step_label: "live reload", workflow_suffix: "for live reload", shared_output_warning: "Do not combine shared output path with bin/dev (live reload)", refresh_guidance: "HMR is disabled in your Shakapacker config; enable dev_server.hmr for React Refresh", refresh_note: "With live reload enabled, changes refresh the page instead of preserving component state" }, development_server: { command_label: "(none)", command_description: "Start development server (default)", procfile_description: "Development server with webpack-dev-server", procfile_dev_label: "Development server Procfile.dev", launcher_description: "Development server (bin/dev default)", mode_heading: "🚀 Development server mode (default)", next_step_label: "the development server", workflow_suffix: "for the development server", shared_output_warning: "Do not combine shared output path with bin/dev (development server)", refresh_guidance: "Check your Shakapacker config has dev_server.hmr: true for React Refresh", refresh_note: "React Refresh requires HMR; other dev-server modes may reload the page" } }.freeze
- MODE_DETAILS =
{ hmr: [ "Hot Module Replacement (HMR) enabled", "React on Rails pack generation (via precompile hook or bin/dev)", "Webpack dev server for fast recompilation", "Source maps for debugging", "May have Flash of Unstyled Content (FOUC)", "Fast recompilation" ], live_reload: [ "Full-page live reload enabled", "React on Rails pack generation (via precompile hook or bin/dev)", "Webpack dev server for automatic recompilation", "Source maps for debugging", "Browser refreshes after changes" ], development_server: [ "Webpack dev server enabled", "React on Rails pack generation (via precompile hook or bin/dev)", "Source maps for debugging", "Development server watches for changes" ] }.freeze
Class Method Summary collapse
- .details(mode) ⇒ Object
-
.detect(config_path = shakapacker_config_path, fallback: :hmr) ⇒ Object
The fallback preserves legacy HMR wording when no Shakapacker config can be read.
-
.hmr_enabled?(config_path = shakapacker_config_path) ⇒ Boolean
This is intentionally narrower than detect: missing, empty, or unparseable config falls back to :hmr for legacy bin/dev help text, but only an explicit HMR config should trigger HMR-specific doctor warnings.
- .text(mode, key) ⇒ Object
Class Method Details
.details(mode) ⇒ Object
97 98 99 |
# File 'lib/react_on_rails/dev/server_mode.rb', line 97 def details(mode) MODE_DETAILS.fetch(normalize_mode(mode)) end |
.detect(config_path = shakapacker_config_path, fallback: :hmr) ⇒ Object
The fallback preserves legacy HMR wording when no Shakapacker config can be read.
79 80 81 |
# File 'lib/react_on_rails/dev/server_mode.rb', line 79 def detect(config_path = shakapacker_config_path, fallback: :hmr) detect_from_config(config_path) || normalize_mode(fallback) end |
.hmr_enabled?(config_path = shakapacker_config_path) ⇒ Boolean
This is intentionally narrower than detect: missing, empty, or unparseable config falls back to :hmr for legacy bin/dev help text, but only an explicit HMR config should trigger HMR-specific doctor warnings.
85 86 87 |
# File 'lib/react_on_rails/dev/server_mode.rb', line 85 def hmr_enabled?(config_path = shakapacker_config_path) detect_from_config(config_path) == :hmr end |
.text(mode, key) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/react_on_rails/dev/server_mode.rb', line 89 def text(mode, key) mode_text = MODE_TEXT.fetch(normalize_mode(mode)) mode_text.fetch(key) do valid_keys = mode_text.keys.join(", ") raise ArgumentError, "Unknown ServerMode text key #{key.inspect}. Valid keys: #{valid_keys}" end end |