Skip to content

Commit 54b6470

Browse files
committed
refactor: update to webpacker v4
rails webpacker:binstubs yarn upgrade @rails/webpacker --latest yarn upgrade webpack-dev-server --latest rails webpacker:install
1 parent 15e90fe commit 54b6470

13 files changed

+2765
-2308
lines changed

.babelrc

-18
This file was deleted.

.browserslistrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
defaults

.gitignore

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@
1717
!/log/.keep
1818
!/tmp/.keep
1919

20-
/node_modules
21-
/yarn-error.log
22-
2320
/public/assets
2421
.byebug_history
2522

2623
# Ignore master key for decrypting credentials and more.
2724
/config/master.key
2825

2926
/.env
27+
3028
/public/packs
3129
/public/packs-test
3230
/node_modules
31+
/yarn-error.log
3332
yarn-debug.log*
3433
.yarn-integrity

.postcssrc.yml

-3
This file was deleted.

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ gem 'pg', '~> 1.1'
1313
gem 'puma', '~> 3.11'
1414
gem "rollbar", "~> 2.16"
1515
gem 'sassc-rails', '~> 2.0'
16-
gem 'webpacker', '~> 3.5'
16+
gem 'webpacker', '~> 4.0'
1717

1818
group :development, :test do
1919
gem 'byebug', '~> 11.0', platforms: [:mri, :mingw, :x64_mingw]

Gemfile.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ GEM
8585
dotenv-rails (2.7.5)
8686
dotenv (= 2.7.5)
8787
railties (>= 3.2, < 6.1)
88-
erubi (1.8.0)
88+
erubi (1.9.0)
8989
ffi (1.11.1)
9090
globalid (0.4.2)
9191
activesupport (>= 4.2.0)
@@ -109,7 +109,7 @@ GEM
109109
mimemagic (0.3.3)
110110
mini_mime (1.0.2)
111111
mini_portile2 (2.4.0)
112-
minitest (5.11.3)
112+
minitest (5.12.0)
113113
minitest-stub_any_instance (1.0.2)
114114
msgpack (1.3.1)
115115
nio4r (2.5.1)
@@ -220,7 +220,7 @@ GEM
220220
nokogiri (~> 1.6)
221221
rubyzip (~> 1.0)
222222
selenium-webdriver (>= 3.0, < 4.0)
223-
webpacker (3.6.0)
223+
webpacker (4.0.7)
224224
activesupport (>= 4.2)
225225
rack-proxy (>= 0.6.1)
226226
railties (>= 4.2)
@@ -254,7 +254,7 @@ DEPENDENCIES
254254
web-console (~> 4.0)
255255
webauthn (~> 2.0.0.a)
256256
webdrivers (~> 4.1)
257-
webpacker (~> 3.5)
257+
webpacker (~> 4.0)
258258

259259
RUBY VERSION
260260
ruby 2.6.3p62

babel.config.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
8+
if (!validEnv.includes(currentEnv)) {
9+
throw new Error(
10+
'Please specify a valid `NODE_ENV` or ' +
11+
'`BABEL_ENV` environment variables. Valid values are "development", ' +
12+
'"test", and "production". Instead, received: ' +
13+
JSON.stringify(currentEnv) +
14+
'.'
15+
)
16+
}
17+
18+
return {
19+
presets: [
20+
isTestEnv && [
21+
require('@babel/preset-env').default,
22+
{
23+
targets: {
24+
node: 'current'
25+
}
26+
}
27+
],
28+
(isProductionEnv || isDevelopmentEnv) && [
29+
require('@babel/preset-env').default,
30+
{
31+
forceAllTransforms: true,
32+
useBuiltIns: 'entry',
33+
corejs: 3,
34+
modules: false,
35+
exclude: ['transform-typeof-symbol']
36+
}
37+
]
38+
].filter(Boolean),
39+
plugins: [
40+
require('babel-plugin-macros'),
41+
require('@babel/plugin-syntax-dynamic-import').default,
42+
isTestEnv && require('babel-plugin-dynamic-import-node'),
43+
require('@babel/plugin-transform-destructuring').default,
44+
[
45+
require('@babel/plugin-proposal-class-properties').default,
46+
{
47+
loose: true
48+
}
49+
],
50+
[
51+
require('@babel/plugin-proposal-object-rest-spread').default,
52+
{
53+
useBuiltIns: true
54+
}
55+
],
56+
[
57+
require('@babel/plugin-transform-runtime').default,
58+
{
59+
helpers: false,
60+
regenerator: true,
61+
corejs: false
62+
}
63+
],
64+
[
65+
require('@babel/plugin-transform-regenerator').default,
66+
{
67+
async: false
68+
}
69+
]
70+
].filter(Boolean)
71+
}
72+
}

bin/webpack

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ require "bundler/setup"
1212

1313
require "webpacker"
1414
require "webpacker/webpack_runner"
15-
Webpacker::WebpackRunner.run(ARGV)
15+
16+
APP_ROOT = File.expand_path("..", __dir__)
17+
Dir.chdir(APP_ROOT) do
18+
Webpacker::WebpackRunner.run(ARGV)
19+
end

bin/webpack-dev-server

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ require "bundler/setup"
1212

1313
require "webpacker"
1414
require "webpacker/dev_server_runner"
15-
Webpacker::DevServerRunner.run(ARGV)
15+
16+
APP_ROOT = File.expand_path("..", __dir__)
17+
Dir.chdir(APP_ROOT) do
18+
Webpacker::DevServerRunner.run(ARGV)
19+
end

config/webpacker.yml

+28-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
default: &default
44
source_path: app/javascript
55
source_entry_path: packs
6+
public_root_path: public
67
public_output_path: packs
78
cache_path: tmp/cache/webpacker
9+
check_yarn_integrity: false
10+
webpack_compile_output: false
811

912
# Additional paths webpack should lookup modules
1013
# ['app/assets', 'engine/foo/app/assets']
@@ -13,7 +16,25 @@ default: &default
1316
# Reload manifest.json on all requests so we reload latest compiled packs
1417
cache_manifest: false
1518

19+
# Extract and emit a css file
20+
extract_css: false
21+
22+
static_assets_extensions:
23+
- .jpg
24+
- .jpeg
25+
- .png
26+
- .gif
27+
- .tiff
28+
- .ico
29+
- .svg
30+
- .eot
31+
- .otf
32+
- .ttf
33+
- .woff
34+
- .woff2
35+
1636
extensions:
37+
- .mjs
1738
- .js
1839
- .sass
1940
- .scss
@@ -31,6 +52,9 @@ development:
3152
<<: *default
3253
compile: true
3354

55+
# Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
56+
check_yarn_integrity: true
57+
3458
# Reference: https://webpack.js.org/configuration/dev-server/
3559
dev_server:
3660
https: false
@@ -48,7 +72,7 @@ development:
4872
headers:
4973
'Access-Control-Allow-Origin': '*'
5074
watch_options:
51-
ignored: /node_modules/
75+
ignored: '**/node_modules/**'
5276

5377

5478
test:
@@ -64,5 +88,8 @@ production:
6488
# Production depends on precompilation of packs prior to booting for performance.
6589
compile: false
6690

91+
# Extract and emit a css file
92+
extract_css: true
93+
6794
# Cache manifest.json for performance
6895
cache_manifest: true

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
"@material/textfield": "^0.37.0",
1414
"@material/top-app-bar": "^0.37.0",
1515
"@material/typography": "^0.35.0",
16-
"@rails/webpacker": "3.5",
1716
"@rails/ujs": "~6.0.0",
17+
"@rails/webpacker": "^4.0.7",
1818
"sinon": "^7.3.2",
1919
"stimulus": "^1.1.0",
2020
"turbolinks": "^5.2.0"
2121
},
2222
"devDependencies": {
23-
"webpack-dev-server": "^3.1.14"
23+
"webpack-dev-server": "^3.8.1"
2424
}
2525
}

postcss.config.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
plugins: [
3+
require('postcss-import'),
4+
require('postcss-flexbugs-fixes'),
5+
require('postcss-preset-env')({
6+
autoprefixer: {
7+
flexbox: 'no-2009'
8+
},
9+
stage: 3
10+
})
11+
]
12+
}

0 commit comments

Comments
 (0)