Skip to content

Commit 390519b

Browse files
authored
Upgrade react-webpack-rails-tutorial to Webpacker Lite (#395)
* Update babel-preset-stage-2 * No logging of redux for tests * Update WebpackerLite to 2.0.4
1 parent be73c02 commit 390519b

22 files changed

+433
-343
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ vendor/ruby
2727
.ruby-gemset
2828

2929
# Generated js bundles
30-
/app/assets/webpack/
30+
/public/webpack/
3131

3232
# Rubymine/IntelliJ
3333
.idea

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.4.1
1+
ruby-2.4.1

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ gem "rails-html-sanitizer"
4040

4141
gem "react_on_rails", "8.0.0.beta.3"
4242

43+
gem "webpacker_lite", "2.0.4"
44+
4345
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
4446
# mini_racer is probably faster than therubyracer
4547
gem "mini_racer"

Gemfile.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ GEM
288288
activemodel (>= 5.0)
289289
bindex (>= 0.4.0)
290290
railties (>= 5.0)
291+
webpacker_lite (2.0.4)
292+
activesupport (>= 4.2)
293+
multi_json (~> 1.2)
294+
railties (>= 4.2)
291295
websocket (1.2.4)
292296
websocket-driver (0.6.5)
293297
websocket-extensions (>= 0.1.0)
@@ -344,6 +348,7 @@ DEPENDENCIES
344348
spring-commands-rspec
345349
uglifier
346350
web-console
351+
webpacker_lite (= 2.0.4)
347352

348353
RUBY VERSION
349354
ruby 2.4.1p111

Procfile.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
rails: REACT_ON_RAILS_ENV=HOT rails s -b 0.0.0.0
88

99
# Run the hot reload server for client development
10-
hot-assets: sh -c 'rm app/assets/webpack/* || true && bundle exec rake react_on_rails:locale && HOT_RAILS_PORT=3500 yarn run hot-assets'
10+
hot-assets: sh -c 'rm -rf public/webpack/development || true && bundle exec rake react_on_rails:locale && HOT_RAILS_PORT=3500 yarn run hot-assets'
1111

1212
# Render static client assets
1313
rails-static-client-assets: sh -c 'yarn run build:dev:client'

Procfile.hot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
rails: REACT_ON_RAILS_ENV=HOT rails s -b 0.0.0.0
77

88
# Run the hot reload server for client development
9-
hot-assets: sh -c 'rm app/assets/webpack/* || true && bundle exec rake react_on_rails:locale && HOT_RAILS_PORT=3500 yarn run hot-assets'
9+
hot-assets: sh -c 'rm -rf public/webpack/development || true && bundle exec rake react_on_rails:locale && HOT_RAILS_PORT=3500 yarn run hot-assets'
1010

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

Procfile.static

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
rails: REACT_ON_RAILS_ENV= rails s -b 0.0.0.0
33

44
# Build client assets, watching for changes.
5-
rails-client-assets: rm app/assets/webpack/* || true && bundle exec rake react_on_rails:locale && yarn run build:dev:client
5+
rails-client-assets: rm -rf public/webpack/development || true && bundle exec rake react_on_rails:locale && yarn run build:dev:client
66

77
# Build server assets, watching for changes. Remove if not server rendering.
88
rails-server-assets: yarn run build:dev:server

app/views/layouts/application.html.erb

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@
33
<head>
44
<title>RailsReactTutorial</title>
55

6-
<%= env_stylesheet_link_tag(static: 'application_static',
7-
hot: 'application_non_webpack',
8-
media: 'all',
9-
'data-turbolinks-track' => "reload") %>
6+
<%= stylesheet_pack_tag('vendor-bundle',
7+
media: 'all',
8+
'data-turbolinks-track': true) %>
109

11-
<!-- These do not use turbolinks, so no data-turbolinks-track -->
12-
<!-- This is to load the hot assets. -->
13-
<%= env_javascript_include_tag(hot: ['http://localhost:3500/vendor-bundle.js',
14-
'http://localhost:3500/app-bundle.js']) %>
10+
<%= stylesheet_pack_tag('app-bundle',
11+
media: 'all',
12+
'data-turbolinks-track': true) %>
13+
14+
<%= javascript_pack_tag('vendor-bundle', 'data-turbolinks-track': true) %>
15+
<%= javascript_pack_tag('app-bundle', 'data-turbolinks-track': true) %>
1516

16-
<!-- These do use turbolinks -->
17-
<%= env_javascript_include_tag(static: 'application_static',
18-
hot: 'application_non_webpack',
19-
'data-turbolinks-track' => "reload") %>
2017
<%= csrf_meta_tags %>
2118
</head>
2219
<body>

client/.babelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"presets": ["es2015", "stage-0", "react"]
2+
"presets": ["es2015", "stage-2", "react"]
33
}

client/app/bundles/comments/startup/clientRegistration.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import NavigationBarApp from './NavigationBarApp';
1717
addLocaleData([...en, ...de, ...ja, ...zh]);
1818

1919
ReactOnRails.setOptions({
20-
traceTurbolinks: TRACE_TURBOLINKS, // eslint-disable-line no-undef
20+
traceTurbolinks: process.env.TRACE_TURBOLINKS, // eslint-disable-line no-undef
2121
});
2222

2323
ReactOnRails.register({

0 commit comments

Comments
 (0)