Skip to content

Commit c91332f

Browse files
authored
Update shakapacker (#493)
* Add and install shakapacker * Update Babel and Webpack config to use Shakapacker * Update Procfile commands * Update bin/webpack occurences into bin/webpacker
1 parent a1f342b commit c91332f

16 files changed

+299
-396
lines changed

.ruby-version

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

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
source "https://rubygems.org"
44
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
55

6-
ruby "2.7.3"
6+
ruby "2.7.5"
77

88
gem "react_on_rails", "12.5.2"
9-
gem "webpacker", "6.0.0.rc.6"
9+
gem "shakapacker", "6.0.2"
1010

1111
# Bundle edge Rails instead: gem "rails", github: "rails/rails"
1212
gem "listen"

Gemfile.lock

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,11 @@ GEM
299299
rubyzip (>= 1.2.2)
300300
semantic_range (3.0.0)
301301
sexp_processor (4.16.0)
302+
shakapacker (6.0.2)
303+
activesupport (>= 5.2)
304+
rack-proxy (>= 0.6.1)
305+
railties (>= 5.2)
306+
semantic_range (>= 2.3.0)
302307
simplecov (0.16.1)
303308
docile (~> 1.1)
304309
json (>= 1.8, < 3)
@@ -392,15 +397,15 @@ DEPENDENCIES
392397
scss_lint
393398
sdoc
394399
selenium-webdriver
400+
shakapacker (= 6.0.2)
395401
spring
396402
spring-commands-rspec
397403
uglifier
398404
web-console
399405
webdrivers (= 3.9.4)
400-
webpacker (= 6.0.0.rc.6)
401406

402407
RUBY VERSION
403-
ruby 2.7.3p183
408+
ruby 2.7.5p203
404409

405410
BUNDLED WITH
406411
2.1.4

Procfile.dev

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# You can run these commands in separate shells
33
redis: redis-server
44
rails: bundle exec rails s -p 3000
5-
wp-client: HMR=true RAILS_ENV=development NODE_ENV=development bin/webpack-dev-server
6-
wp-server: bundle exec rake react_on_rails:locale && HMR=true SERVER_BUNDLE_ONLY=yes bin/webpack --watch
5+
wp-client: HMR=true RAILS_ENV=development NODE_ENV=development bin/webpacker-dev-server
6+
wp-server: bundle exec rake react_on_rails:locale && HMR=true SERVER_BUNDLE_ONLY=yes bin/webpacker --watch

Procfile.dev-static

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ redis: redis-server
66
# When making frequent changes to client side assets, you will prefer building webpack assets
77
# upon saving rather than when you refresh your browser page.
88
# Note, if using React on Rails localization you will need to run
9-
# `bundle exec rake react_on_rails:locale` before you run bin/webpack
10-
webpack: sh -c 'bundle exec rake react_on_rails:locale && rm -rf public/packs/* || true && bin/webpack -w'
9+
# `bundle exec rake react_on_rails:locale` before you run bin/webpacker
10+
webpack: sh -c 'bundle exec rake react_on_rails:locale && rm -rf public/packs/* || true && bin/webpacker -w'

babel.config.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
1-
// The source code including full typescript support is available at:
2-
// https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/babel.config.js
3-
4-
const defaultConfigFunc = require('@rails/webpacker/package/babel/preset.js');
5-
61
module.exports = function (api) {
7-
const resultConfig = defaultConfigFunc(api);
2+
const defaultConfigFunc = require('shakapacker/package/babel/preset.js')
3+
const resultConfig = defaultConfigFunc(api)
4+
const isProductionEnv = api.env('production')
85

96
const changesOnDefault = {
10-
plugins: [process.env.WEBPACK_SERVE && 'react-refresh/babel'].filter(Boolean),
11-
};
7+
presets: [
8+
[
9+
'@babel/preset-react',
10+
{
11+
development: !isProductionEnv,
12+
useBuiltIns: true
13+
}
14+
]
15+
].filter(Boolean),
16+
plugins: [
17+
process.env.WEBPACK_SERVE && 'react-refresh/babel',
18+
isProductionEnv && ['babel-plugin-transform-react-remove-prop-types',
19+
{
20+
removeImport: true
21+
}
22+
]
23+
].filter(Boolean),
24+
}
1225

13-
resultConfig.plugins = [...resultConfig.plugins, ...changesOnDefault.plugins];
26+
resultConfig.presets = [...resultConfig.presets, ...changesOnDefault.presets]
27+
resultConfig.plugins = [...resultConfig.plugins, ...changesOnDefault.plugins ]
1428

15-
return resultConfig;
16-
};
29+
return resultConfig
30+
}

bin/webpack renamed to bin/webpacker

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require "webpacker"
66
require "webpacker/webpack_runner"
77

88
ENV["RAILS_ENV"] ||= "development"
9-
ENV["NODE_ENV"] ||= "development"
9+
ENV["NODE_ENV"] ||= ENV["RAILS_ENV"]
1010
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", Pathname.new(__FILE__).realpath)
1111

1212
APP_ROOT = File.expand_path("..", __dir__)

bin/webpack-dev-server renamed to bin/webpacker-dev-server

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env ruby
22

33
ENV["RAILS_ENV"] ||= "development"
4-
ENV["NODE_ENV"] ||= "development"
4+
ENV["NODE_ENV"] ||= ENV["RAILS_ENV"]
55

66
require "pathname"
77
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",

config/webpack/DEBUGGING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# https://github.com/rails/webpacker/pull/2018
44

55
To debug:
6-
bin/webpack --debug
6+
bin/webpacker --debug-webpakcer
77

88
And put a debugger statement in the file you're editing.
99

config/webpack/commonWebpackConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/config/webpack/commonWebpackConfig.js
33

44
// Common configuration applying to client and server configuration
5-
const { webpackConfig: baseClientWebpackConfig, merge } = require('@rails/webpacker');
5+
const { webpackConfig: baseClientWebpackConfig, merge } = require('shakapacker');
66

77
const commonOptions = {
88
resolve: {

0 commit comments

Comments
 (0)