Skip to content

Commit eebee78

Browse files
committed
Merge pull request shakacode#244 from shakacode/updates-to-hot-reloading
Fixed up the Procfile.static and Procfile.hot
2 parents 72673a8 + 376ebe7 commit eebee78

9 files changed

+27
-16
lines changed

Diff for: Procfile.hot

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
rails: REACT_ON_RAILS_ENV=HOT rails s
88

99
# Run the hot reload server for client development
10-
rails-assets: sh -c 'npm run build:dev:client:once && HOT_RAILS_PORT=3500 npm run hot-assets'
10+
hot-assets: sh -c 'rm app/assets/webpack/* || true && HOT_RAILS_PORT=3500 npm run hot-assets'
1111

1212
# Keep the JS fresh for server rendering. Remove if not server rendering
1313
rails-server-assets: sh -c 'npm run build:dev:server'

Diff for: Procfile.static

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Run Rails without hot reloading (static assets).
2-
rails: rails s
2+
rails: REACT_ON_RAILS_ENV= rails s
33

44
# Build client assets, watching for changes.
5-
rails-client-assets: sh -c 'npm run build:dev:client'
5+
rails-client-assets: rm app/assets/webpack/* || true && npm run build:dev:client
66

77
# Build server assets, watching for changes. Remove if not server rendering.
8-
rails-server-assets: sh -c 'npm run build:dev:server'
8+
rails-server-assets: npm run build:dev:server

Diff for: app/assets/javascripts/application_static.js renamed to app/assets/javascripts/application_static.js.erb

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
// These assets are located in app/assets/webpack directory
77
// CRITICAL that webpack/vendor-bundle must be BEFORE turbolinks
88
// since it is exposing jQuery and jQuery-ujs
9-
//= require vendor-bundle
10-
//= require app-bundle
9+
10+
<% if ENV["REACT_ON_RAILS_ENV"] != "HOT" %>
11+
<% require_asset "vendor-bundle" %>
12+
<% require_asset "app-bundle" %>
13+
<% end %>
1114

1215
// Non-webpack assets incl turbolinks
1316
//= require application_non_webpack

Diff for: app/assets/stylesheets/application_static.scss

-6
This file was deleted.

Diff for: app/assets/stylesheets/application_static.scss.erb

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// These assets are located in app/assets/webpack directory, and are generated ONLY when static
2+
// assets are prepared (not for hot reloading assets).
3+
4+
// Super important: This file is loaded even for hot loading only, so we need to be sure
5+
// that we don't reference the static generated CSS files.
6+
<% unless ENV["REACT_ON_RAILS_ENV"] == "HOT" %>
7+
@import 'vendor-bundle';
8+
@import 'app-bundle';
9+
<% end %>
10+
11+
// Non-webpack assets
12+
@import 'application_non_webpack';

Diff for: app/views/layouts/application.html.erb

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
media: 'all',
99
'data-turbolinks-track' => true) %>
1010

11-
<!-- These do not use turbolinks -->
11+
<!-- These do not use turbolinks, so no data-turbolinks-track -->
12+
<!-- This is to load the hot assets. -->
1213
<%= env_javascript_include_tag(hot: ['http://localhost:3500/vendor-bundle.js',
1314
'http://localhost:3500/app-bundle.js']) %>
1415

Diff for: client/webpack.client.base.config.js

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ module.exports = {
1616
// See use of 'vendor' in the CommonsChunkPlugin inclusion below.
1717
vendor: [
1818
'babel-polyfill',
19+
'es5-shim/es5-shim',
20+
'es5-shim/es5-sham',
1921
'jquery',
2022
],
2123

Diff for: client/webpack.client.rails.hot.config.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ config.entry.app.push(
1515
'webpack/hot/only-dev-server'
1616
);
1717

18+
// These are Rails specific
1819
config.entry.vendor.push(
19-
'es5-shim/es5-shim',
20-
'es5-shim/es5-sham',
2120
'jquery-ujs',
2221
'bootstrap-loader'
2322
);

Diff for: docs/jquery-with-react-on-rails.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
jQuery and jQuery-ujs are not required within `app/assets/javascript/application.js` and have been moved under`/client` and are managed by npm. The modules are exposed via entry point by [client/webpack.client.base.config.js](client/webpack.client.base.config.js) and, for `jquery-ujs`, in the [client/webpack.client.rails.build.config.js](client/webpack.client.rails.build.config.js) and the [client/webpack.client.rails.hot.config.js](client/webpack.client.rails.hot.config.js).
44

5-
In `application_non_webpack.js` and `application_static.js`, it's critical that any libraries that depend on jQuery come after the inclusion
5+
In `application_non_webpack.js` and `application_static.js.erb`, it's critical that any libraries that depend on jQuery come after the inclusion
66
of the Webpack bundle.
77

88
Please refer to [Considerations for jQuery with Rails and Webpack](http://forum.shakacode.com/t/considerations-for-jquery-with-rails-and-webpack/344) for further info.

0 commit comments

Comments
 (0)