Skip to content

Commit 8e656f9

Browse files
authored
Replace custom webpack configs with simplified one (#477)
1 parent f3489ec commit 8e656f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+12038
-11036
lines changed

client/.bootstraprc renamed to .bootstraprc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extractStyles: false
3232
# For example, _variables.scss contains:
3333
# $input-color: $gray !default;
3434
# This means you can define $input-color before we load _variables.scss
35-
preBootstrapCustomizations: ./app/assets/styles/bootstrap-pre-customizations.scss
35+
preBootstrapCustomizations: ./client/app/assets/styles/bootstrap-pre-customizations.scss
3636

3737
# This gets loaded after bootstrap/variables is loaded and before bootstrap is loaded.
3838
# A good example of this is when you want to override a bootstrap variable to be based

.browserslistrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
defaults

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
3+
client/app/libs/i18n/translations.js
4+
client/app/libs/i18n/default.js

client/.eslintrc.yml renamed to .eslintrc.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ rules:
2626

2727
jsx-a11y/anchor-is-valid: off
2828

29-
# arrow-parens:
30-
# - 0
31-
# - "as-needed"
32-
3329
settings:
3430
import/resolver:
3531
webpack:
36-
config: 'webpack.client.base.config.js'
32+
config: 'config/webpack/development.js'
File renamed without changes.

.rubocop.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ AllCops:
1515
- 'db/**/*'
1616
- 'db/schema.rb'
1717
- 'db/seeds.rb'
18-
- 'client/node_modules/**/*'
1918
- 'bin/**/*'
2019
- 'Procfile.*'
2120
- !ruby/regexp /old_and_unused\.rb$/

.scss-lint.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# See http://sass-guidelin.es/#zeros
22

33
scss_files:
4-
- 'app/assets/stylesheets/**/*.scss'
54
- 'client/app/**/*.scss'
65

76
exclude: 'client/node_modules/**'

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ install:
4444
- yarn
4545
- google-chrome --version
4646
- rake db:setup
47+
- bundle exec rake react_on_rails:locale
4748

4849
before_script:
4950
- "export DISPLAY=:99"

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
source "https://rubygems.org"
44
ruby "2.7.1"
55

6-
gem "react_on_rails", github: "shakacode/react_on_rails", branch: "justin808/remove-precompile-rake"
6+
gem "react_on_rails", "12.0.1"
77
gem "webpacker"
88

99
# Bundle edge Rails instead: gem "rails", github: "rails/rails"

Gemfile.lock

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
GIT
2-
remote: https://github.com/shakacode/react_on_rails.git
3-
revision: 38403e66bba1c3fde7edd4fb46c7f7daaaa111a6
4-
branch: justin808/remove-precompile-rake
5-
specs:
6-
react_on_rails (12.0.0.pre.beta.2)
7-
addressable
8-
connection_pool
9-
execjs (~> 2.5)
10-
rails (>= 3.2)
11-
rainbow (~> 3.0)
12-
webpacker (>= 4.0)
13-
141
GEM
152
remote: https://rubygems.org/
163
specs:
@@ -216,6 +203,13 @@ GEM
216203
rb-inotify (0.10.1)
217204
ffi (~> 1.0)
218205
rdoc (6.2.1)
206+
react_on_rails (12.0.1)
207+
addressable
208+
connection_pool
209+
execjs (~> 2.5)
210+
rails (>= 3.2)
211+
rainbow (~> 3.0)
212+
webpacker (>= 4.0)
219213
redis (3.3.3)
220214
regexp_parser (1.7.1)
221215
require_all (3.0.0)
@@ -359,7 +353,7 @@ DEPENDENCIES
359353
rails-html-sanitizer
360354
rails_best_practices
361355
rainbow
362-
react_on_rails!
356+
react_on_rails (= 12.0.1)
363357
redis (= 3.3.3)
364358
rspec-rails (= 3.7.2)
365359
rubocop

Procfile.static

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

44
# Build client assets, watching for changes.
5-
rails-client-assets: rm -rf public/webpack/development || true && bundle exec rake react_on_rails:locale && yarn run build:dev:client
6-
7-
# Build server assets, watching for changes. Remove if not server rendering.
8-
rails-server-assets: yarn run build:dev:server
5+
rails-client-assets: yarn run build:dev

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,9 @@ Save a change to a JSX file and see it update immediately in the browser! Note,
204204
line in the `rails_helper.rb` file. If you are using this project as an example and are not using RSpec, you may want to implement similar logic in your own project.
205205

206206
## Webpack
207-
### Configuration Files
208207

209-
- `webpack.client.base.config.js`: Common **client** configuration file to minimize code duplication for `webpack.client.rails.build.config`, `webpack.client.rails.hot.config`, `webpack.client.express.config`
210-
- `webpack.client.express.config.js`: Webpack configuration for Express server [client/server-express.js](client/server-express.js)
211-
- `webpack.client.rails.build.config.js`: Client side js bundle for deployment and tests.
212-
- `webpack.client.rails.hot.config.js`: Webpack Dev Server bundler for serving rails assets on port 3500, used by [client/server-rails-hot.js](client/server-rails-hot.js), for hot reloading JS and CSS within Rails.
213-
- `webpack.server.rails.build.config.js`: Server side js bundle, used by server rendering.
208+
_Converted to use @rails/webpacker webpack configuration_.
209+
214210

215211
### Additional Resources
216212
- [Webpack Docs](https://webpack.js.org/)

app/assets/javascripts/application_non_webpack.js

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

app/assets/javascripts/application_static.js

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

app/assets/stylesheets/application_non_webpack.scss

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

app/assets/stylesheets/application_static.scss

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

app/views/layouts/application.html.erb

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

6-
<%= stylesheet_pack_tag('vendor-bundle',
7-
media: 'all',
8-
'data-turbolinks-track': true) %>
6+
<%= stylesheet_packs_with_chunks_tag('clientRegistration',
7+
media: 'all',
8+
'data-turbolinks-track': true) %>
99

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) %>
10+
<%= javascript_packs_with_chunks_tag('clientRegistration',
11+
'data-turbolinks-track': true,
12+
defer: true) %>
1613

1714
<%= csrf_meta_tags %>
1815
</head>

babel.config.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
module.exports = function(api) {
2+
var validEnv = ['development', 'test', 'production']
3+
var currentEnv = api.env()
4+
var isDevelopmentEnv = api.env('development')
5+
var isProductionEnv = api.env('production')
6+
var isTestEnv = api.env('test')
7+
const isHMR = process.env.WEBPACK_DEV_SERVER
8+
9+
if (!validEnv.includes(currentEnv)) {
10+
throw new Error(
11+
'Please specify a valid `NODE_ENV` or ' +
12+
'`BABEL_ENV` environment variables. Valid values are "development", ' +
13+
'"test", and "production". Instead, received: ' +
14+
JSON.stringify(currentEnv) +
15+
'.'
16+
)
17+
}
18+
19+
return {
20+
presets: [
21+
isTestEnv && [
22+
'@babel/preset-env',
23+
{
24+
targets: {
25+
node: 'current'
26+
}
27+
}
28+
],
29+
(isProductionEnv || isDevelopmentEnv) && '@babel/preset-env',
30+
"@babel/preset-react",
31+
].filter(Boolean),
32+
plugins: [
33+
'babel-plugin-macros',
34+
isDevelopmentEnv && isHMR && 'react-refresh/babel',
35+
[
36+
'@babel/plugin-proposal-class-properties',
37+
{
38+
loose: true
39+
}
40+
],
41+
[
42+
'@babel/plugin-transform-runtime',
43+
{
44+
helpers: false,
45+
regenerator: true,
46+
corejs: false
47+
}
48+
]
49+
].filter(Boolean)
50+
}
51+
}

bin/webpack

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ require "webpacker/webpack_runner"
1313

1414
APP_ROOT = File.expand_path("..", __dir__)
1515

16-
puts "bin/webpack is running #{APP_ROOT}/bin/webpack.sh"
17-
exec "#{APP_ROOT}/bin/webpack.sh"
16+
Dir.chdir(APP_ROOT) do
17+
Webpacker::WebpackRunner.run(ARGV)
18+
end

bin/webpack-dev-server

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env ruby
2+
3+
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
4+
ENV["NODE_ENV"] ||= "development"
5+
ENV["WEBPACK_DEV_SERVER"] ||= "TRUE"
6+
7+
require "pathname"
8+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
9+
Pathname.new(__FILE__).realpath)
10+
11+
require "bundler/setup"
12+
13+
require "webpacker"
14+
require "webpacker/dev_server_runner"
15+
16+
APP_ROOT = File.expand_path("..", __dir__)
17+
Dir.chdir(APP_ROOT) do
18+
Webpacker::DevServerRunner.run(ARGV)
19+
end

bin/webpack.sh

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

client/.babelrc

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

client/.eslintignore

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

client/app/bundles/comments/components/CommentBox/CommentBox.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import SelectLanguage from 'libs/i18n/selectLanguage';
99
import { defaultMessages, defaultLocale } from 'libs/i18n/default';
1010

1111
import CommentForm from './CommentForm/CommentForm';
12-
import CommentList, { CommentPropTypes } from './CommentList/CommentList';
12+
import CommentList, { commentPropTypes } from './CommentList/CommentList';
1313
import css from './CommentBox.scss';
1414

1515
class CommentBox extends BaseComponent {
@@ -22,7 +22,7 @@ class CommentBox extends BaseComponent {
2222
isFetching: PropTypes.boolean,
2323
isSaving: PropTypes.boolean,
2424
submitCommentError: PropTypes.string,
25-
$$comments: PropTypes.arrayOf(CommentPropTypes),
25+
$$comments: PropTypes.arrayOf(commentPropTypes),
2626
}).isRequired,
2727
intl: intlShape.isRequired,
2828
};

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

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

client/app/packs/bootstrap.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import 'bootstrap-loader';

0 commit comments

Comments
 (0)