Skip to content

Commit 36d7047

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 36d7047

File tree

20 files changed

+169
-147
lines changed

20 files changed

+169
-147
lines changed

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 9 additions & 2 deletions
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
Lines changed: 26 additions & 0 deletions
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

Lines changed: 0 additions & 27 deletions
This file was deleted.

lib/react_on_rails/test_helper/webpack_assets_status_checker.rb

Lines changed: 2 additions & 2 deletions
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

Lines changed: 14 additions & 8 deletions
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

0 commit comments

Comments
 (0)