Skip to content

Commit e4adbd8

Browse files
committed
Update to Webpacker from Webpacker Lite
* Uses branch on github for now for Webpacker * gem "webpacker", git: "https://github.com/shakacode/webpacker.git", branch: "issue-464-merge-webpacker-lite-into-webpacker"
1 parent d0033c3 commit e4adbd8

20 files changed

+169
-147
lines changed

CHANGELOG.md

+24
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,30 @@ Changes since last non-beta release.
88

99
*Please add entries here for your pull requests.*
1010

11+
### [9.0.0.beta.1]
12+
- Switch over to using Webpacker
13+
14+
- If using the WebpackConfigLoader, you will need to rename the following object properties:
15+
- hotReloadingUrl devServerUrl
16+
- hotReloadingHostname devServerHost
17+
- hotReloadingPort devServerPort
18+
19+
- Find your webpacker_lite.yml and rename it to webpacker.yml
20+
- Add a section like this under your development env:
21+
```
22+
dev_server:
23+
host: localhost
24+
port: 8080
25+
https: false
26+
# Can be enabled by export WEBPACKER_HMR=TRUE in env
27+
hot: false
28+
```
29+
- remove `hot_reloading_host` and `hot_reloading_enabled_by_default`
30+
- rename `webpack_public_output_dir` to `public_output_path`
31+
32+
33+
34+
1135
### [8.0.6]
1236
#### fixed
1337
- Fixes server rendering when using a CDN. Server rendering would try to fetch a file with the "asset_host". This change updates the webpacker_lite dependency to 2.1.0 which has a new helper `pack_path`. [#901](https://github.com/shakacode/react_on_rails/pull/901) by [justin808](https://github.com/justin808). Be sure to update webpacker_lite to 2.1.0.

Gemfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ gem "chromedriver-helper"
3838
gem "launchy"
3939
gem "poltergeist"
4040
gem "selenium-webdriver"
41-
gem "webpacker_lite", "~> 2.1"
41+
gem "webpacker", git: "https://github.com/shakacode/webpacker.git",
42+
branch: "issue-464-merge-webpacker-lite-into-webpacker"
4243

4344
gem "rainbow"

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ For more testimonials, see [Live Projects](PROJECTS.md) and [Kudos](./KUDOS.md).
7474

7575
# NEWS
7676
* **[VERSION 8.1.0](https://rubygems.org/gems/react_on_rails/)** shipped with [webpacker_lite](https://github.com/shakacode/webpacker_lite) (soon [**webpacker**](https://github.com/rails/webpacker/issues/464#issuecomment-310986140) support! [react-webpack-rails-tutorial PR #395](https://github.com/shakacode/react-webpack-rails-tutorial/pull/395) shows the changes needed to migrate from the Asset Pipeline to Webpacker Lite. For more information, see my article: [Webpacker Lite: Why Fork Webpacker?](https://blog.shakacode.com/webpacker-lite-why-fork-webpacker-f0a7707fac92). Per recent discussions, we [will merge Webpacker Lite changes back into Webpacker](https://github.com/rails/webpacker/issues/464#issuecomment-310986140). There's no reason to wait for this. The upgrade will eventually be trivial.
77-
* The Docs here on `master` refer to 8.1.0 including support for [webpacker_lite](https://github.com/shakacode/webpacker_lite)!
77+
* The Docs here on `master` refer to 9.0.0 including support for [webpacker](https://github.com/shakacode/webpacker)!
7878
*Use the [7.0.4 docs](https://github.com/shakacode/react_on_rails/tree/7.0.4) to refer to the older asset pipeline way.*
7979
* *See [NEWS.md](NEWS.md) for more notes over time.*
8080

@@ -124,7 +124,7 @@ See the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpac
124124

125125
## Why Webpack?
126126

127-
Webpack is used to generate JavaScript and CSS "bundles" directly to your `/public` directory. [webpacker_lite](https://github.com/shakacode/webpacker_lite) provides view helpers to access the Webpack generated (and fingerprinted) JS and CSS. These files totally skip the Rails asset pipeline. You are responsible for properly processing your Webpack output via the Webpack config files.
127+
Webpack is used to generate JavaScript and CSS "bundles" directly to your `/public` directory. [webpacker](https://github.com/rails/webpacker) provides view helpers to access the Webpack generated (and fingerprinted) JS and CSS. These files totally skip the Rails asset pipeline. You are responsible for properly processing your Webpack output via the Webpack config files.
128128

129129
This usage of webpack fits neatly and simply into existing Rails apps. You can include React components on a Rails view with a simple helper.
130130

docs/api/ruby-api-hot-reload-view-helpers.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## NOTE: These helpers are NOT needed if using webpacker_lite
1+
## NOTE: These helpers are NOT needed if using webpacker
22

33
## Hot Reloading View Helpers
44
The `env_javascript_include_tag` and `env_stylesheet_link_tag` support the usage of a webpack dev server for providing the JS and CSS assets during development mode. See the [shakacode/react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial/) for a working example.

docs/basics/installation-overview.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The default path: `public/webpack` can be loaded with webpackConfigLoader as sho
2323
1. You create scripts in `client/package.json` per the example apps. These are used for building your Webpack assets. Also do this for your top level `package.json`.
2424

2525
## Rails Steps (outside of /client)
26-
1. Add `gem "webpacker_lite"` to the Gemfile, run bundle. The gem provides the `stylesheet_pack_tag` and `javascript_pack_tag` helpers which is used to load the bundled assets to your layouts.[Dummy Example](../../spec/dummy/app/views/layouts/application.html.erb)
26+
1. Add `gem "webpacker"` to the Gemfile, run bundle. The gem provides the `stylesheet_pack_tag` and `javascript_pack_tag` helpers which is used to load the bundled assets to your layouts.[Dummy Example](../../spec/dummy/app/views/layouts/application.html.erb)
2727
1. Configure the `config/initializers/react_on_rails.rb`. You can adjust some necessary settings and defaults. See file [spec/dummy/config/initializers/react_on_rails.rb](../../spec/dummy/config/initializers/react_on_rails.rb) for a detailed example of configuration, including comments on the different values to configure.
2828
1. Configure your Procfiles per the example apps. These are at the root of your Rails installation.
2929
1. Configure your top level JavaScript files for inclusion in your layout. You'll want a version that you use for static assets, and you want a file for any files in your setup that are not part of your webpack build. The reason for this is for use with hot-reloading. If you are not using hot reloading, then you only need to configure your `application.js` file to include your Webpack generated files. For more information on hot reloading, see [Hot Reloading of Assets For Rails Development](../additional-reading/hot-reloading-rails-development.md)

lib/generators/react_on_rails/base_generator.rb

+9-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def create_react_directories
4747
def copy_base_files
4848
base_path = "base/base/"
4949
base_files = %w[app/controllers/hello_world_controller.rb
50-
config/webpacker_lite.yml
50+
config/webpacker.yml
5151
client/.babelrc
5252
client/webpack.config.js
5353
client/REACT_ON_RAILS_CLIENT_README.md]
@@ -71,7 +71,14 @@ def template_package_json
7171
end
7272

7373
def add_base_gems_to_gemfile
74-
append_to_file("Gemfile", "\ngem 'mini_racer', platforms: :ruby\ngem 'webpacker_lite'\n")
74+
gems = <<-GEMS.strip_heredoc
75+
76+
gem 'mini_racer', platforms: :ruby
77+
gem 'webpacker', git: "https://github.com/shakacode/webpacker.git",
78+
branch: "issue-464-merge-webpacker-lite-into-webpacker"
79+
GEMS
80+
append_to_file("Gemfile",
81+
gems)
7582
end
7683

7784
def append_to_spec_rails_helper
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Note: Base output directory of /public is assumed for static files
2+
default: &default
3+
# Critical to set compile as false for React on Rails projects
4+
compile: false
5+
6+
development:
7+
<<: *default
8+
# generated files for development, in /public/webpack/development
9+
public_output_path: webpack/development
10+
11+
dev_server:
12+
host: localhost
13+
port: 8080
14+
https: false
15+
# Can be enabled by export WEBPACKER_HMR=TRUE in env
16+
hot: false
17+
18+
test:
19+
<<: *default
20+
# generated files for tests, in /public/webpack/test
21+
public_output_path: webpack/test
22+
23+
production:
24+
<<: *default
25+
# generated files for tests, in /public/webpack/production
26+
public_output_path: webpack/production

lib/generators/react_on_rails/templates/base/base/config/webpacker_lite.yml

-27
This file was deleted.

lib/react_on_rails/test_helper/webpack_assets_status_checker.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def initialize(
2424
end
2525

2626
def stale_generated_webpack_files
27-
manifest_needed = ReactOnRails::Utils.using_webpacker_lite? &&
28-
!WebpackerLite::Manifest.exist?
27+
manifest_needed = ReactOnRails::Utils.using_webpacker? &&
28+
!Webpacker::Manifest.exist?
2929

3030
return ["manifest.json"] if manifest_needed
3131

lib/react_on_rails/utils.rb

+14-8
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,31 @@ def self.invoke_and_exit_if_failed(cmd, failure_message)
6262
end
6363

6464
def self.server_bundle_js_file_path
65+
# Don't ever use the hashed file name?
66+
# Cases:
67+
# 1. Using same bundle for both server and client, so server bundle will be hashed
68+
# 2. Using a different bundle (different Webpack config), so file is not hashed
6569
bundle_js_file_path(ReactOnRails.configuration.server_bundle_js_file)
6670
end
6771

68-
# TODO: conturbo Write Test for this, with BOTH webpacker_lite installed and not, and
69-
# with case for webpacker_lite, but server file is not in the file
72+
# TODO: conturbo Write Test for this, with BOTH webpacker installed and not, and
73+
# with case for webpacker, but server file is not in the file
7074
def self.bundle_js_file_path(bundle_name)
7175
# For testing outside of Rails app
7276

73-
if using_webpacker_lite? && WebpackerLite::Manifest.lookup(bundle_name)
74-
# If using webpacker_lite gem
75-
# Per https://github.com/rails/webpacker/issues/571, this path might
76-
public_subdir_hashed_file_name = ActionController::Base.helpers.pack_path(bundle_name)
77-
return File.join("public", public_subdir_hashed_file_name)
77+
if using_webpacker?
78+
# Note, server bundle should not be in the manifest
79+
# If using webpacker gem
80+
# Per https://github.com/rails/webpacker/issues/571
81+
path = Webpacker::Manifest.lookup_no_throw(bundle_name)
82+
return path if path.present?
83+
# Else either the file is not in the manifest, so we'll default to the non-hashed name.
7884
end
7985

8086
File.join(ReactOnRails.configuration.generated_assets_dir, bundle_name)
8187
end
8288

83-
def self.using_webpacker_lite?
89+
def self.using_webpacker?
8490
ActionController::Base.helpers.respond_to?(:asset_pack_path)
8591
end
8692

spec/dummy/Gemfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ gem "sdoc", group: :doc
4141

4242
gem "react_on_rails", path: "../.."
4343

44-
gem "webpacker_lite", "2.1.0"
44+
gem "webpacker", git: "https://github.com/shakacode/webpacker.git",
45+
branch: "issue-464-merge-webpacker-lite-into-webpacker"
4546

4647
gem "mini_racer"
4748

spec/dummy/Gemfile.lock

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
GIT
2+
remote: https://github.com/shakacode/webpacker.git
3+
revision: 38657a1c0e012cf8e1932cf6f88d702cb36e635c
4+
branch: issue-464-merge-webpacker-lite-into-webpacker
5+
specs:
6+
webpacker (2.0)
7+
activesupport (>= 4.2)
8+
multi_json (~> 1.2)
9+
railties (>= 4.2)
10+
111
PATH
212
remote: ../..
313
specs:
@@ -102,7 +112,7 @@ GEM
102112
railties (>= 3.0.0)
103113
globalid (0.4.0)
104114
activesupport (>= 4.2.0)
105-
i18n (0.8.4)
115+
i18n (0.8.6)
106116
interception (0.5)
107117
io-like (0.3.0)
108118
jbuilder (2.6.4)
@@ -131,7 +141,7 @@ GEM
131141
mini_portile2 (2.2.0)
132142
mini_racer (0.1.9)
133143
libv8 (~> 5.3)
134-
minitest (5.10.2)
144+
minitest (5.10.3)
135145
multi_json (1.12.1)
136146
nio4r (2.1.0)
137147
nokogiri (1.8.0)
@@ -276,10 +286,6 @@ GEM
276286
uglifier (3.2.0)
277287
execjs (>= 0.3.0, < 3)
278288
unicode-display_width (1.2.1)
279-
webpacker_lite (2.1.0)
280-
activesupport (>= 4.2)
281-
multi_json (~> 1.2)
282-
railties (>= 4.2)
283289
websocket (1.2.4)
284290
websocket-driver (0.6.5)
285291
websocket-extensions (>= 0.1.0)
@@ -326,7 +332,7 @@ DEPENDENCIES
326332
sqlite3
327333
turbolinks (~> 5.0)
328334
uglifier
329-
webpacker_lite (= 2.1.0)
335+
webpacker!
330336

331337
BUNDLED WITH
332338
1.15.3

spec/dummy/client/server-rails-hot.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ const webpackConfig = require('./webpack.client.rails.hot.config');
2020

2121
const webpackConfigLoader = require('react-on-rails/webpackConfigLoader');
2222
const configPath = resolve('..', 'config');
23-
const { hotReloadingUrl, hotReloadingPort, hotReloadingHostname } = webpackConfigLoader(configPath);
23+
const { devServerUrl, devServerPort, devServerHostname } = webpackConfigLoader(configPath);
2424

2525
const compiler = webpack(webpackConfig);
2626

2727
const devServer = new WebpackDevServer(compiler, {
2828
proxy: {
29-
'*': hotReloadingUrl,
29+
'*': devServerUrl,
3030
},
3131
headers: {
3232
'Access-Control-Allow-Origin': '*',
@@ -48,9 +48,9 @@ const devServer = new WebpackDevServer(compiler, {
4848
},
4949
});
5050

51-
devServer.listen(hotReloadingPort, hotReloadingHostname, err => {
51+
devServer.listen(devServerPort, devServerHostname, err => {
5252
if (err) console.error(err);
5353
console.log(
54-
`=> 🔥 Webpack development server is running on ${hotReloadingUrl}`
54+
`=> 🔥 Webpack development server is running on ${devServerUrl}`
5555
);
5656
});

spec/dummy/client/webpack.client.rails.hot.config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const merge = require('webpack-merge');
1212
const config = require('./webpack.client.base.config');
1313
const webpackConfigLoader = require('react-on-rails/webpackConfigLoader');
1414
const configPath = resolve('..', 'config');
15-
const { hotReloadingUrl, webpackOutputPath } = webpackConfigLoader(configPath);
15+
const { devServerUrl, webpackOutputPath } = webpackConfigLoader(configPath);
1616

1717
// entry is prepended because 'react-hot-loader/patch' must be the very first entry
1818
// for hot reloading to work.
@@ -27,15 +27,15 @@ module.exports = merge.strategy(
2727
entry: {
2828
'app-bundle': [
2929
'react-hot-loader/patch',
30-
`webpack-dev-server/client?${hotReloadingUrl}`,
30+
`webpack-dev-server/client?${devServerUrl}`,
3131
'webpack/hot/only-dev-server'
3232
],
3333
},
3434

3535
output: {
3636
filename: '[name].js',
3737
path: webpackOutputPath,
38-
publicPath: `${hotReloadingUrl}/`,
38+
publicPath: `${devServerUrl}/`,
3939
},
4040

4141
module: {

spec/dummy/config/initializers/react_on_rails.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def self.custom_context(view_context)
2020
config.generated_assets_dir = File.join(%w[public webpack], Rails.env)
2121

2222
# Define the files we need to check for webpack compilation when running tests.
23-
config.webpack_generated_files = %w[app-bundle.js vendor-bundle.js server-bundle.js]
23+
config.webpack_generated_files = %w[manifest.json]
2424

2525
# This is the file used for server rendering of React when using `(prerender: true)`
2626
# If you are never using server rendering, you may set this to "".

spec/dummy/config/webpacker.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Note: Base output directory of /public is assumed for static files
2+
default: &default
3+
# Critical to set compile as false for React on Rails projects
4+
compile: false
5+
6+
development:
7+
<<: *default
8+
# generated files for development, in /public/webpack/development
9+
public_output_path: webpack/development
10+
11+
dev_server:
12+
host: localhost
13+
port: 8080
14+
https: false
15+
# Can be enabled by export WEBPACKER_HMR=TRUE in env
16+
hot: false
17+
18+
test:
19+
<<: *default
20+
# generated files for tests, in /public/webpack/test
21+
public_output_path: webpack/test
22+
23+
production:
24+
<<: *default
25+
# generated files for tests, in /public/webpack/production
26+
public_output_path: webpack/production

spec/dummy/config/webpacker_lite.yml

-27
This file was deleted.

spec/react_on_rails/support/shared_examples/base_generator_examples.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
client/.babelrc
3737
client/package.json
3838
config/initializers/react_on_rails.rb
39-
config/webpacker_lite.yml
39+
config/webpacker.yml
4040
package.json
4141
Procfile.dev].each { |file| assert_file(file) }
4242
end

0 commit comments

Comments
 (0)