|
1 | 1 | # Hyperstack |
| 2 | +WITH_PRERENDERING = true |
2 | 3 |
|
3 | 4 | # ----------------------------------- Commit so we have good history of these changes |
4 | 5 |
|
|
9 | 10 | # ----------------------------------- Add the gems |
10 | 11 |
|
11 | 12 | gem 'webpacker' |
12 | | -gem 'rails-hyperstack', '~> 1.0.alpha' |
| 13 | +gem 'rails-hyperstack', '~> 1.0.alpha1.0' |
13 | 14 | gem_group :development do |
14 | 15 | gem 'foreman' |
15 | 16 | end |
@@ -116,36 +117,86 @@ class Hyperstack::ApplicationPolicy |
116 | 117 | run 'yarn add react' |
117 | 118 | run 'yarn add react-dom' |
118 | 119 | run 'yarn add react-router' |
| 120 | +if WITH_PRERENDERING |
| 121 | +run 'yarn add react-router-dom' |
| 122 | +run 'yarn add history' |
| 123 | +run 'yarn add react_ujs' |
| 124 | +run 'yarn add jquery' |
| 125 | +end |
119 | 126 |
|
120 | | -# ----------------------------------- Create hyperstack.js |
| 127 | +if !WITH_PRERENDERING |
| 128 | + # ----------------------------------- Create hyperstack.js |
121 | 129 |
|
122 | | -file 'app/javascript/packs/hyperstack.js', <<-CODE |
123 | | -// Import all the modules |
124 | | -import React from 'react'; |
125 | | -import ReactDOM from 'react-dom'; |
| 130 | + file 'app/javascript/packs/hyperstack.js', <<-CODE |
| 131 | + // Import all the modules |
| 132 | + import React from 'react'; |
| 133 | + import ReactDOM from 'react-dom'; |
126 | 134 |
|
127 | | -// for opal/hyperstack modules to find React and others they must explicitly be saved |
128 | | -// to the global space, otherwise webpack will encapsulate them locally here |
129 | | -global.React = React; |
130 | | -global.ReactDOM = ReactDOM; |
131 | | -CODE |
| 135 | + // for opal/hyperstack modules to find React and others they must explicitly be saved |
| 136 | + // to the global space, otherwise webpack will encapsulate them locally here |
| 137 | + global.React = React; |
| 138 | + global.ReactDOM = ReactDOM; |
| 139 | + CODE |
132 | 140 |
|
133 | | -# ----------------------------------- View template |
| 141 | + # ----------------------------------- View template |
134 | 142 |
|
135 | | -inject_into_file 'app/views/layouts/application.html.erb', before: %r{<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>} do |
136 | | -<<-CODE |
137 | | -<%= javascript_pack_tag 'hyperstack' %> |
138 | | -CODE |
139 | | -end |
| 143 | + inject_into_file 'app/views/layouts/application.html.erb', before: %r{<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>} do |
| 144 | + <<-CODE |
| 145 | + <%= javascript_pack_tag 'hyperstack' %> |
| 146 | + CODE |
| 147 | + end |
140 | 148 |
|
141 | | -# ----------------------------------- application.js |
| 149 | + # ----------------------------------- application.js |
142 | 150 |
|
143 | | -inject_into_file 'app/assets/javascripts/application.js', before: %r{//= require_tree .} do |
| 151 | + inject_into_file 'app/assets/javascripts/application.js', before: %r{//= require_tree .} do |
144 | 152 | <<-CODE |
145 | 153 | //= require jquery |
146 | 154 | //= require jquery_ujs |
147 | 155 | //= require hyperstack-loader |
148 | 156 | CODE |
| 157 | + end |
| 158 | +else |
| 159 | + # ----------------------------------- Create client_and_server.js |
| 160 | + |
| 161 | + file 'app/javascript/packs/client_and_server.js', <<-CODE |
| 162 | +//app/javascript/packs/client_and_server.js |
| 163 | +// these packages will be loaded both during prerendering and on the client |
| 164 | +React = require('react'); // react-js library |
| 165 | +History = require('history'); // react-router history library |
| 166 | +ReactRouter = require('react-router'); // react-router js library |
| 167 | +ReactRouterDOM = require('react-router-dom'); // react-router DOM interface |
| 168 | +ReactRailsUJS = require('react_ujs'); // interface to react-rails |
| 169 | +// to add additional NPM packages call run yarn package-name@version |
| 170 | +// then add the require here. |
| 171 | +CODE |
| 172 | + |
| 173 | + # ----------------------------------- Create client_only.js |
| 174 | + |
| 175 | + file 'app/javascript/packs/client_only.js', <<-CODE |
| 176 | +//app/javascript/packs/client_only.js |
| 177 | +// add any requires for packages that will run client side only |
| 178 | +ReactDOM = require('react-dom'); // react-js client side code |
| 179 | +jQuery = require('jquery'); |
| 180 | +// to add additional NPM packages call run yarn package-name@version |
| 181 | +// then add the require here. |
| 182 | +CODE |
| 183 | + |
| 184 | + # ----------------------------------- add asset paths |
| 185 | + |
| 186 | + # note before this was just public/packs now its public/paths/js. WHY??? |
| 187 | + append_file 'config/initializers/assets.rb' do |
| 188 | + <<-RUBY |
| 189 | +Rails.application.config.assets.paths << Rails.root.join('public', 'packs', 'js').to_s |
| 190 | + RUBY |
| 191 | + end |
| 192 | + |
| 193 | + # ----------------------------------- application.js |
| 194 | + |
| 195 | + inject_into_file 'app/assets/javascripts/application.js', before: %r{//= require_tree .} do |
| 196 | +<<-CODE |
| 197 | +//= require hyperstack-loader |
| 198 | +CODE |
| 199 | + end |
149 | 200 | end |
150 | 201 |
|
151 | 202 | # ----------------------------------- Procfile |
|
0 commit comments