Class: React::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- React::Generators::InstallGenerator
- Defined in:
- lib/generators/react/install_generator.rb
Instance Method Summary collapse
-
#create_directory ⇒ Object
Make an empty ‘components/` directory in the right place:.
- #create_server_rendering ⇒ Object
-
#modify_webpacker_yml ⇒ Object
For Shakapacker below version 7, we need to set relative path for source_entry_path.
-
#setup_react ⇒ Object
Add requires, setup UJS.
Instance Method Details
#create_directory ⇒ Object
Make an empty ‘components/` directory in the right place:
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/generators/react/install_generator.rb', line 33 def create_directory components_dir = if webpacker? Pathname.new(javascript_dir).parent.to_s else javascript_dir end empty_directory File.join(components_dir, 'components') unless [:skip_git] create_file File.join(components_dir, 'components/.keep') end end |
#create_server_rendering ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/generators/react/install_generator.rb', line 54 def create_server_rendering if [:skip_server_rendering] return elsif webpacker? ssr_manifest_path = File.join(javascript_dir, 'server_rendering.js') template('server_rendering_pack.js', ssr_manifest_path) else ssr_manifest_path = File.join(javascript_dir, 'server_rendering.js') template('server_rendering.js', ssr_manifest_path) initializer_path = 'config/initializers/react_server_rendering.rb' template('react_server_rendering.rb', initializer_path) end end |
#modify_webpacker_yml ⇒ Object
For Shakapacker below version 7, we need to set relative path for source_entry_path
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/generators/react/install_generator.rb', line 20 def modify_webpacker_yml webpacker_yml_path = 'config/webpacker.yml' if webpacker? && Pathname.new(webpacker_yml_path).exist? gsub_file( webpacker_yml_path, "source_entry_path: /\n", "source_entry_path: packs\n" ) reloaded_webpacker_config end end |
#setup_react ⇒ Object
Add requires, setup UJS
46 47 48 49 50 51 52 |
# File 'lib/generators/react/install_generator.rb', line 46 def setup_react if webpacker? setup_react_webpacker else setup_react_sprockets end end |