Class: WebpackRailsReact::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- WebpackRailsReact::InstallGenerator
- Defined in:
- lib/generators/webpack_rails_react/install_generator.rb
Overview
:nodoc:
Instance Method Summary collapse
- #add_foreman_to_gemfile ⇒ Object
- #add_to_gitignore ⇒ Object
- #copy_package_json ⇒ Object
- #copy_procfile ⇒ Object
- #copy_webpack_conf ⇒ Object
- #create_webpack_application_js ⇒ Object
- #run_bundle_install ⇒ Object
- #run_npm_install ⇒ Object
- #whats_next ⇒ Object
Instance Method Details
#add_foreman_to_gemfile ⇒ Object
8 9 10 |
# File 'lib/generators/webpack_rails_react/install_generator.rb', line 8 def add_foreman_to_gemfile gem 'foreman' end |
#add_to_gitignore ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/generators/webpack_rails_react/install_generator.rb', line 58 def add_to_gitignore append_to_file ".gitignore" do <<-EOF.strip_heredoc # Added by webpack-rails /node_modules /public/webpack EOF end end |
#copy_package_json ⇒ Object
16 17 18 |
# File 'lib/generators/webpack_rails_react/install_generator.rb', line 16 def copy_package_json copy_file "package.json", "package.json" end |
#copy_procfile ⇒ Object
12 13 14 |
# File 'lib/generators/webpack_rails_react/install_generator.rb', line 12 def copy_procfile copy_file "Procfile", "Procfile" end |
#copy_webpack_conf ⇒ Object
20 21 22 |
# File 'lib/generators/webpack_rails_react/install_generator.rb', line 20 def copy_webpack_conf copy_file "webpack.config.js", "config/webpack.config.js" end |
#create_webpack_application_js ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/generators/webpack_rails_react/install_generator.rb', line 24 def create_webpack_application_js empty_directory "webpack" create_file "webpack/application.js" do <<-EOF.strip_heredoc import React from 'react'; import ReactDOM from 'react-dom'; import App from './App'; ReactDOM.render( <App />, document.getElementById('app') ) EOF end create_file "webpack/App.js" do <<-EOF.strip_heredoc import React from 'react'; class App extends React.Component { render() { return( <div> Hello World </div> ) } } export default App; EOF end end |
#run_bundle_install ⇒ Object
72 73 74 |
# File 'lib/generators/webpack_rails_react/install_generator.rb', line 72 def run_bundle_install run "bundle install" if yes?("Would you like us to run 'bundle install' for you?") end |
#run_npm_install ⇒ Object
68 69 70 |
# File 'lib/generators/webpack_rails_react/install_generator.rb', line 68 def run_npm_install run "npm install" if yes?("Would you like us to run 'npm install' for you?") end |
#whats_next ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/generators/webpack_rails_react/install_generator.rb', line 76 def whats_next puts <<-EOF.strip_heredoc We've set up the basics of webpack-rails for you, but you'll still need to: 1. Add the 'application' entry point in to your layout, and e.g. <%= javascript_include_tag *webpack_asset_paths('application') %> 2. Add an element with an id of 'app' to your layout 3. Enable hot module replacement by adding <script src="http://localhost:3808/webpack-dev-server.js"></script> to your layout 4. Run 'foreman start' to run the webpack-dev-server and rails server Example app/views/layouts/application.html.erb <!DOCTYPE html> <html> <head> <title>WebpackDemo</title> <%= stylesheet_link_tag 'application', media: 'all' %> <%= javascript_include_tag 'application' %> <script src="http://localhost:3808/webpack-dev-server.js"></script> <%= csrf_meta_tags %> </head> <body> <%= yield %> <%= javascript_include_tag *webpack_asset_paths('application') %> </body> </html> See the README.md for this gem at https://github.com/wdjungst/webpack-rails-react/blob/master/README.md for more info. Thanks for using webpack-rails-react! EOF end |