webpacker 6.0.0.beta.7 → 6.0.0.rc.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/jest.yml +5 -2
- data/.github/workflows/js-lint.yml +4 -1
- data/.github/workflows/rubocop.yml +1 -1
- data/.github/workflows/ruby.yml +12 -12
- data/.node-version +1 -1
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +21 -10
- data/Gemfile.lock +83 -83
- data/README.md +160 -157
- data/config/webpacker.yml +1 -1
- data/docs/developing_webpacker.md +29 -0
- data/docs/troubleshooting.md +53 -23
- data/docs/v6_upgrade.md +31 -42
- data/gemfiles/Gemfile-rails-edge +1 -1
- data/gemfiles/Gemfile-rails.6.1.x +12 -0
- data/lib/install/bin/yarn +18 -0
- data/lib/install/config/webpacker.yml +14 -17
- data/lib/install/package.json +17 -0
- data/lib/install/packs/entrypoints/application.js +3 -4
- data/lib/install/template.rb +28 -15
- data/lib/tasks/webpacker/check_node.rake +3 -1
- data/lib/tasks/webpacker/check_yarn.rake +4 -2
- data/lib/tasks/webpacker/clobber.rake +1 -1
- data/lib/tasks/webpacker/verify_config.rake +14 -0
- data/lib/tasks/webpacker/verify_install.rake +1 -11
- data/lib/tasks/yarn.rake +36 -0
- data/lib/webpacker/commands.rb +19 -15
- data/lib/webpacker/configuration.rb +15 -4
- data/lib/webpacker/dev_server.rb +6 -0
- data/lib/webpacker/dev_server_runner.rb +6 -3
- data/lib/webpacker/env.rb +5 -1
- data/lib/webpacker/helper.rb +14 -8
- data/lib/webpacker/instance.rb +4 -0
- data/lib/webpacker/manifest.rb +1 -2
- data/lib/webpacker/railtie.rb +1 -2
- data/lib/webpacker/runner.rb +1 -1
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker.rb +1 -1
- data/package/__tests__/development.js +4 -4
- data/package/__tests__/env.js +8 -4
- data/package/babel/preset.js +0 -1
- data/package/config.js +3 -3
- data/package/env.js +6 -3
- data/package/environments/__tests__/base.js +3 -3
- data/package/environments/base.js +12 -7
- data/package/environments/development.js +37 -33
- data/package/index.js +2 -0
- data/package/inliningCss.js +7 -0
- data/package/rules/file.js +1 -1
- data/package/rules/sass.js +1 -2
- data/package/utils/get_style_rule.js +4 -2
- data/package.json +25 -29
- data/test/command_test.rb +76 -0
- data/test/configuration_test.rb +1 -1
- data/test/dev_server_runner_test.rb +5 -2
- data/test/helper_test.rb +48 -34
- data/test/manifest_test.rb +10 -2
- data/test/mounted_app/test/dummy/config/webpacker.yml +1 -1
- data/test/test_app/config/webpacker.yml +1 -3
- data/test/test_app/config/webpacker_other_location.yml +79 -0
- data/test/test_app/public/packs/manifest.json +12 -5
- data/test/webpacker_test.rb +17 -0
- data/webpacker.gemspec +1 -1
- data/yarn.lock +2202 -2680
- metadata +18 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 308f1dcfbba68cb509f38d0990c5fc0bbab2f0d1291869057f4c11eb797cdc61
|
4
|
+
data.tar.gz: 816f1050b3df6a970119fa967e4ff9db2562dd240674d46eba91c0d6ae5aefa7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e3051f31353cd4f6ec9c0c7642ce00ab5b90f8093cfbfbb566a17468705e4a2c1ee691e0fb9b45dc55edd49b0cf62c60a8a4428b2843914dabb95ff2eb92f10
|
7
|
+
data.tar.gz: a00f04d5951f343a0e0c39bc942aec73863547630807ccd944e0d2a3a459ee52170ce77f4a3fd10c2019c5fed49f570ea174531679d61cf4e5051dea1e4036ac
|
data/.github/workflows/jest.yml
CHANGED
@@ -3,16 +3,19 @@ name: Jest specs
|
|
3
3
|
on: [push, pull_request]
|
4
4
|
|
5
5
|
jobs:
|
6
|
-
|
6
|
+
jest:
|
7
7
|
name: Jest specs
|
8
8
|
strategy:
|
9
9
|
matrix:
|
10
10
|
os: [ubuntu-latest]
|
11
|
-
node: [
|
11
|
+
node: [12.x, 14.x, 15.x]
|
12
12
|
|
13
13
|
runs-on: ${{ matrix.os }}
|
14
14
|
|
15
15
|
steps:
|
16
|
+
- name: Install yarn maybe
|
17
|
+
run: which yarn || sudo npm install -g yarn
|
18
|
+
|
16
19
|
- uses: actions/checkout@v2
|
17
20
|
- name: Get yarn cache directory path
|
18
21
|
id: yarn-cache-dir-path
|
@@ -3,7 +3,7 @@ name: JS lint
|
|
3
3
|
on: [push, pull_request]
|
4
4
|
|
5
5
|
jobs:
|
6
|
-
|
6
|
+
js-lint:
|
7
7
|
name: JS Lint
|
8
8
|
|
9
9
|
strategy:
|
@@ -14,6 +14,9 @@ jobs:
|
|
14
14
|
runs-on: ${{ matrix.os }}
|
15
15
|
|
16
16
|
steps:
|
17
|
+
- name: Install yarn maybe
|
18
|
+
run: which yarn || sudo npm install -g yarn
|
19
|
+
|
17
20
|
- uses: actions/checkout@v2
|
18
21
|
- name: Get yarn cache directory path
|
19
22
|
id: yarn-cache-dir-path
|
data/.github/workflows/ruby.yml
CHANGED
@@ -3,7 +3,7 @@ name: Ruby specs
|
|
3
3
|
on: [push, pull_request]
|
4
4
|
|
5
5
|
jobs:
|
6
|
-
|
6
|
+
test:
|
7
7
|
name: Ruby specs
|
8
8
|
runs-on: ${{ matrix.os }}
|
9
9
|
continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' || matrix.experimental }}
|
@@ -23,23 +23,20 @@ jobs:
|
|
23
23
|
]
|
24
24
|
gemfile: [
|
25
25
|
"gemfiles/Gemfile-rails.5.2.x",
|
26
|
-
"gemfiles/Gemfile-rails.6.0.x"
|
26
|
+
"gemfiles/Gemfile-rails.6.0.x",
|
27
|
+
"gemfiles/Gemfile-rails.6.1.x"
|
27
28
|
]
|
28
29
|
exclude:
|
29
|
-
- ruby:
|
30
|
+
- ruby: 2.4
|
30
31
|
gemfile: gemfiles/Gemfile-rails.6.0.x
|
31
|
-
- ruby:
|
32
|
+
- ruby: 2.4
|
33
|
+
gemfile: gemfiles/Gemfile-rails.6.1.x
|
34
|
+
- ruby: 2.5
|
35
|
+
gemfile: gemfiles/Gemfile-rails.6.1.x
|
36
|
+
- ruby: 3.0
|
32
37
|
gemfile: gemfiles/Gemfile-rails.5.2.x
|
33
38
|
experimental: [false]
|
34
39
|
include:
|
35
|
-
- ruby: 2.5
|
36
|
-
os: ubuntu-latest
|
37
|
-
gemfile: gemfiles/Gemfile-rails-edge
|
38
|
-
experimental: true
|
39
|
-
- ruby: 2.6
|
40
|
-
os: ubuntu-latest
|
41
|
-
gemfile: gemfiles/Gemfile-rails-edge
|
42
|
-
experimental: true
|
43
40
|
- ruby: 2.7
|
44
41
|
os: ubuntu-latest
|
45
42
|
gemfile: gemfiles/Gemfile-rails-edge
|
@@ -58,6 +55,9 @@ jobs:
|
|
58
55
|
restore-keys: |
|
59
56
|
bundle-use-ruby-${{ matrix.ruby }}-${{ matrix.gemfile }}-gems-
|
60
57
|
|
58
|
+
- name: Install yarn maybe
|
59
|
+
run: which yarn || sudo npm install -g yarn
|
60
|
+
|
61
61
|
- uses: ruby/setup-ruby@v1
|
62
62
|
with:
|
63
63
|
ruby-version: ${{ matrix.ruby }}
|
data/.node-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
16.7.0
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
## [[6.0.0]](https://github.com/rails/webpacker/compare/v5.1.1...master) - 2021-TBD
|
6
6
|
|
7
|
-
Please see [UPGRADE GUIDE](./docs/v6_upgrade.md) for more
|
7
|
+
Please see [UPGRADE GUIDE](./docs/v6_upgrade.md) for more information.
|
8
8
|
|
9
9
|
- `node_modules` will no longer be compiled by default. This primarily fixes [rails issue #35501](https://github.com/rails/rails/issues/35501) as well as [numerous other webpacker issues](https://github.com/rails/webpacker/issues/2131#issuecomment-581618497). The disabled loader can still be required explicitly via:
|
10
10
|
|
@@ -14,26 +14,37 @@ environment.loaders.append('nodeModules', nodeModules)
|
|
14
14
|
```
|
15
15
|
|
16
16
|
- If you have added `environment.loaders.delete('nodeModules')` to your `environment.js`, this must be removed or you will receive an error (`Item nodeModules not found`).
|
17
|
-
-
|
17
|
+
- `extract_css` option was removed. Webpacker will generate a separate `application.css` file for the default `application` pack, as supported by multiple files per entry introduced in 5.0.0. [#2608](https://github.com/rails/webpacker/pull/2608). However, CSS will be inlined when the webpack-dev-server is used with `hmr: true`. JS package exports `inliningCss`. This is useful to enable HMR for React.
|
18
18
|
- Webpacker's wrapper to the `splitChunks()` API will now default `runtimeChunk: 'single'` which will help prevent potential issues when using multiple entry points per page [#2708](https://github.com/rails/webpacker/pull/2708).
|
19
19
|
- Changes `@babel/preset-env` modules option to `'auto'` per recommendation in the Babel docs [#2709](https://github.com/rails/webpacker/pull/2709)
|
20
20
|
- Adds experimental Yarn 2 support. Note you must manually set `nodeLinker: node-modules` in your `.yarnrc.yml`.
|
21
|
-
|
22
21
|
- Fixes dev server issues [#2898](https://github.com/rails/webpacker/pull/2898)
|
22
|
+
- Update static files path to from `media/` to `static/`.
|
23
23
|
|
24
24
|
### Breaking changes
|
25
|
-
|
26
|
-
- Simple webpack config
|
27
25
|
- Removed integration installers
|
28
26
|
- Splitchunks enabled by default
|
29
|
-
- CSS extraction enabled by default
|
30
|
-
|
27
|
+
- CSS extraction enabled by default, except when devServer is configured and running
|
28
|
+
|
29
|
+
## [[5.4.0]](https://github.com/rails/webpacker/compare/v5.3.0...v5.4.0) - 2021-05-18
|
30
|
+
|
31
|
+
- Fix compatibility with Psych 4
|
32
|
+
|
33
|
+
## [[5.3.0]](https://github.com/rails/webpacker/compare/v5.2.1...v5.3.0) - 2021-04-27
|
34
|
+
|
35
|
+
- Adds experimental Yarn 2 support. Note you must manually set `nodeLinker: node-modules` in your `.yarnrc.yml`.
|
36
|
+
|
37
|
+
- Keep backups, even when they're old [#2912](https://github.com/rails/webpacker/pull/2912)
|
38
|
+
|
39
|
+
## [[5.2.2]](https://github.com/rails/webpacker/compare/v5.2.1...v5.2.2) - 2021-04-27
|
40
|
+
|
41
|
+
- Bump deps and remove node-sass [#2997](https://github.com/rails/webpacker/pull/2997).
|
31
42
|
|
32
|
-
## [[5.2.1]](https://github.com/rails/webpacker/compare/v5.2.0...
|
43
|
+
## [[5.2.1]](https://github.com/rails/webpacker/compare/v5.2.0...v5.2.1) - 2020-08-17
|
33
44
|
|
34
45
|
- Revert [#1311](https://github.com/rails/webpacker/pull/1311).
|
35
46
|
|
36
|
-
## [[5.2.0]](https://github.com/rails/webpacker/compare/v5.1.1...
|
47
|
+
## [[5.2.0]](https://github.com/rails/webpacker/compare/v5.1.1...v5.2.0) - 2020-08-16
|
37
48
|
|
38
49
|
- Bump dependencies and fixes. See [diff](https://github.com/rails/webpacker/compare/v5.1.1...5-x-stable) for changes.
|
39
50
|
|
@@ -412,7 +423,7 @@ See changes: https://github.com/rails/webpacker/compare/e8b197e36c77181ca2e4765c
|
|
412
423
|
|
413
424
|
### Added
|
414
425
|
|
415
|
-
- On CI, sort files & check modified w/ digest
|
426
|
+
- On CI, sort files & check modified w/ digest instead of mtime[#1522](https://github.com/rails/webpacker/pull/1522)
|
416
427
|
|
417
428
|
## [3.5.3] - 2018-05-03
|
418
429
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
webpacker (6.0.0.
|
4
|
+
webpacker (6.0.0.rc.5)
|
5
5
|
activesupport (>= 5.2)
|
6
6
|
rack-proxy (>= 0.6.1)
|
7
7
|
railties (>= 5.2)
|
@@ -10,60 +10,60 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
actioncable (6.1.
|
14
|
-
actionpack (= 6.1.
|
15
|
-
activesupport (= 6.1.
|
13
|
+
actioncable (6.1.4.1)
|
14
|
+
actionpack (= 6.1.4.1)
|
15
|
+
activesupport (= 6.1.4.1)
|
16
16
|
nio4r (~> 2.0)
|
17
17
|
websocket-driver (>= 0.6.1)
|
18
|
-
actionmailbox (6.1.
|
19
|
-
actionpack (= 6.1.
|
20
|
-
activejob (= 6.1.
|
21
|
-
activerecord (= 6.1.
|
22
|
-
activestorage (= 6.1.
|
23
|
-
activesupport (= 6.1.
|
18
|
+
actionmailbox (6.1.4.1)
|
19
|
+
actionpack (= 6.1.4.1)
|
20
|
+
activejob (= 6.1.4.1)
|
21
|
+
activerecord (= 6.1.4.1)
|
22
|
+
activestorage (= 6.1.4.1)
|
23
|
+
activesupport (= 6.1.4.1)
|
24
24
|
mail (>= 2.7.1)
|
25
|
-
actionmailer (6.1.
|
26
|
-
actionpack (= 6.1.
|
27
|
-
actionview (= 6.1.
|
28
|
-
activejob (= 6.1.
|
29
|
-
activesupport (= 6.1.
|
25
|
+
actionmailer (6.1.4.1)
|
26
|
+
actionpack (= 6.1.4.1)
|
27
|
+
actionview (= 6.1.4.1)
|
28
|
+
activejob (= 6.1.4.1)
|
29
|
+
activesupport (= 6.1.4.1)
|
30
30
|
mail (~> 2.5, >= 2.5.4)
|
31
31
|
rails-dom-testing (~> 2.0)
|
32
|
-
actionpack (6.1.
|
33
|
-
actionview (= 6.1.
|
34
|
-
activesupport (= 6.1.
|
32
|
+
actionpack (6.1.4.1)
|
33
|
+
actionview (= 6.1.4.1)
|
34
|
+
activesupport (= 6.1.4.1)
|
35
35
|
rack (~> 2.0, >= 2.0.9)
|
36
36
|
rack-test (>= 0.6.3)
|
37
37
|
rails-dom-testing (~> 2.0)
|
38
38
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
39
|
-
actiontext (6.1.
|
40
|
-
actionpack (= 6.1.
|
41
|
-
activerecord (= 6.1.
|
42
|
-
activestorage (= 6.1.
|
43
|
-
activesupport (= 6.1.
|
39
|
+
actiontext (6.1.4.1)
|
40
|
+
actionpack (= 6.1.4.1)
|
41
|
+
activerecord (= 6.1.4.1)
|
42
|
+
activestorage (= 6.1.4.1)
|
43
|
+
activesupport (= 6.1.4.1)
|
44
44
|
nokogiri (>= 1.8.5)
|
45
|
-
actionview (6.1.
|
46
|
-
activesupport (= 6.1.
|
45
|
+
actionview (6.1.4.1)
|
46
|
+
activesupport (= 6.1.4.1)
|
47
47
|
builder (~> 3.1)
|
48
48
|
erubi (~> 1.4)
|
49
49
|
rails-dom-testing (~> 2.0)
|
50
50
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
51
|
-
activejob (6.1.
|
52
|
-
activesupport (= 6.1.
|
51
|
+
activejob (6.1.4.1)
|
52
|
+
activesupport (= 6.1.4.1)
|
53
53
|
globalid (>= 0.3.6)
|
54
|
-
activemodel (6.1.
|
55
|
-
activesupport (= 6.1.
|
56
|
-
activerecord (6.1.
|
57
|
-
activemodel (= 6.1.
|
58
|
-
activesupport (= 6.1.
|
59
|
-
activestorage (6.1.
|
60
|
-
actionpack (= 6.1.
|
61
|
-
activejob (= 6.1.
|
62
|
-
activerecord (= 6.1.
|
63
|
-
activesupport (= 6.1.
|
54
|
+
activemodel (6.1.4.1)
|
55
|
+
activesupport (= 6.1.4.1)
|
56
|
+
activerecord (6.1.4.1)
|
57
|
+
activemodel (= 6.1.4.1)
|
58
|
+
activesupport (= 6.1.4.1)
|
59
|
+
activestorage (6.1.4.1)
|
60
|
+
actionpack (= 6.1.4.1)
|
61
|
+
activejob (= 6.1.4.1)
|
62
|
+
activerecord (= 6.1.4.1)
|
63
|
+
activesupport (= 6.1.4.1)
|
64
64
|
marcel (~> 1.0.0)
|
65
|
-
mini_mime (
|
66
|
-
activesupport (6.1.
|
65
|
+
mini_mime (>= 1.1.0)
|
66
|
+
activesupport (6.1.4.1)
|
67
67
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
68
68
|
i18n (>= 1.6, < 2)
|
69
69
|
minitest (>= 5.1)
|
@@ -72,79 +72,79 @@ GEM
|
|
72
72
|
ast (2.4.2)
|
73
73
|
builder (3.2.4)
|
74
74
|
byebug (11.1.3)
|
75
|
-
concurrent-ruby (1.1.
|
75
|
+
concurrent-ruby (1.1.9)
|
76
76
|
crass (1.0.6)
|
77
77
|
erubi (1.10.0)
|
78
|
-
globalid (0.
|
79
|
-
activesupport (>=
|
78
|
+
globalid (0.5.2)
|
79
|
+
activesupport (>= 5.0)
|
80
80
|
i18n (1.8.10)
|
81
81
|
concurrent-ruby (~> 1.0)
|
82
|
-
loofah (2.
|
82
|
+
loofah (2.12.0)
|
83
83
|
crass (~> 1.0.2)
|
84
84
|
nokogiri (>= 1.5.9)
|
85
85
|
mail (2.7.1)
|
86
86
|
mini_mime (>= 0.1.1)
|
87
87
|
marcel (1.0.1)
|
88
88
|
method_source (1.0.0)
|
89
|
-
mini_mime (1.
|
90
|
-
mini_portile2 (2.
|
89
|
+
mini_mime (1.1.1)
|
90
|
+
mini_portile2 (2.6.1)
|
91
91
|
minitest (5.14.4)
|
92
|
-
nio4r (2.5.
|
93
|
-
nokogiri (1.
|
94
|
-
mini_portile2 (~> 2.
|
92
|
+
nio4r (2.5.8)
|
93
|
+
nokogiri (1.12.3)
|
94
|
+
mini_portile2 (~> 2.6.1)
|
95
95
|
racc (~> 1.4)
|
96
|
-
parallel (1.
|
97
|
-
parser (3.0.
|
96
|
+
parallel (1.19.1)
|
97
|
+
parser (3.0.2.0)
|
98
98
|
ast (~> 2.4.1)
|
99
99
|
racc (1.5.2)
|
100
100
|
rack (2.2.3)
|
101
|
-
rack-proxy (0.
|
101
|
+
rack-proxy (0.7.0)
|
102
102
|
rack
|
103
103
|
rack-test (1.1.0)
|
104
104
|
rack (>= 1.0, < 3)
|
105
|
-
rails (6.1.
|
106
|
-
actioncable (= 6.1.
|
107
|
-
actionmailbox (= 6.1.
|
108
|
-
actionmailer (= 6.1.
|
109
|
-
actionpack (= 6.1.
|
110
|
-
actiontext (= 6.1.
|
111
|
-
actionview (= 6.1.
|
112
|
-
activejob (= 6.1.
|
113
|
-
activemodel (= 6.1.
|
114
|
-
activerecord (= 6.1.
|
115
|
-
activestorage (= 6.1.
|
116
|
-
activesupport (= 6.1.
|
105
|
+
rails (6.1.4.1)
|
106
|
+
actioncable (= 6.1.4.1)
|
107
|
+
actionmailbox (= 6.1.4.1)
|
108
|
+
actionmailer (= 6.1.4.1)
|
109
|
+
actionpack (= 6.1.4.1)
|
110
|
+
actiontext (= 6.1.4.1)
|
111
|
+
actionview (= 6.1.4.1)
|
112
|
+
activejob (= 6.1.4.1)
|
113
|
+
activemodel (= 6.1.4.1)
|
114
|
+
activerecord (= 6.1.4.1)
|
115
|
+
activestorage (= 6.1.4.1)
|
116
|
+
activesupport (= 6.1.4.1)
|
117
117
|
bundler (>= 1.15.0)
|
118
|
-
railties (= 6.1.
|
118
|
+
railties (= 6.1.4.1)
|
119
119
|
sprockets-rails (>= 2.0.0)
|
120
120
|
rails-dom-testing (2.0.3)
|
121
121
|
activesupport (>= 4.2.0)
|
122
122
|
nokogiri (>= 1.6)
|
123
|
-
rails-html-sanitizer (1.
|
123
|
+
rails-html-sanitizer (1.4.2)
|
124
124
|
loofah (~> 2.3)
|
125
|
-
railties (6.1.
|
126
|
-
actionpack (= 6.1.
|
127
|
-
activesupport (= 6.1.
|
125
|
+
railties (6.1.4.1)
|
126
|
+
actionpack (= 6.1.4.1)
|
127
|
+
activesupport (= 6.1.4.1)
|
128
128
|
method_source
|
129
|
-
rake (>= 0.
|
129
|
+
rake (>= 0.13)
|
130
130
|
thor (~> 1.0)
|
131
131
|
rainbow (3.0.0)
|
132
|
-
rake (13.0.
|
132
|
+
rake (13.0.6)
|
133
133
|
regexp_parser (2.1.1)
|
134
134
|
rexml (3.2.5)
|
135
|
-
rubocop (
|
135
|
+
rubocop (1.19.1)
|
136
136
|
parallel (~> 1.10)
|
137
|
-
parser (>=
|
137
|
+
parser (>= 3.0.0.0)
|
138
138
|
rainbow (>= 2.2.2, < 4.0)
|
139
|
-
regexp_parser (>= 1.8)
|
139
|
+
regexp_parser (>= 1.8, < 3.0)
|
140
140
|
rexml
|
141
|
-
rubocop-ast (>=
|
141
|
+
rubocop-ast (>= 1.9.1, < 2.0)
|
142
142
|
ruby-progressbar (~> 1.7)
|
143
|
-
unicode-display_width (>= 1.4.0, <
|
144
|
-
rubocop-ast (1.
|
145
|
-
parser (>=
|
146
|
-
rubocop-performance (1.
|
147
|
-
rubocop (>=
|
143
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
144
|
+
rubocop-ast (1.11.0)
|
145
|
+
parser (>= 3.0.1.1)
|
146
|
+
rubocop-performance (1.11.5)
|
147
|
+
rubocop (>= 1.7.0, < 2.0)
|
148
148
|
rubocop-ast (>= 0.4.0)
|
149
149
|
ruby-progressbar (1.11.0)
|
150
150
|
semantic_range (3.0.0)
|
@@ -158,8 +158,8 @@ GEM
|
|
158
158
|
thor (1.1.0)
|
159
159
|
tzinfo (2.0.4)
|
160
160
|
concurrent-ruby (~> 1.0)
|
161
|
-
unicode-display_width (
|
162
|
-
websocket-driver (0.7.
|
161
|
+
unicode-display_width (2.0.0)
|
162
|
+
websocket-driver (0.7.5)
|
163
163
|
websocket-extensions (>= 0.1.0)
|
164
164
|
websocket-extensions (0.1.5)
|
165
165
|
zeitwerk (2.4.2)
|
@@ -174,10 +174,10 @@ DEPENDENCIES
|
|
174
174
|
rack-proxy
|
175
175
|
rails
|
176
176
|
rake (>= 11.1)
|
177
|
-
rubocop
|
177
|
+
rubocop
|
178
178
|
rubocop-performance
|
179
179
|
semantic_range
|
180
180
|
webpacker!
|
181
181
|
|
182
182
|
BUNDLED WITH
|
183
|
-
2.2.
|
183
|
+
2.2.25
|
data/README.md
CHANGED
@@ -5,17 +5,13 @@
|
|
5
5
|
[![Rubocop](https://github.com/rails/webpacker/workflows/Rubocop/badge.svg)](https://github.com/rails/webpacker/actions)
|
6
6
|
[![JS lint](https://github.com/rails/webpacker/workflows/JS%20lint/badge.svg)](https://github.com/rails/webpacker/actions)
|
7
7
|
|
8
|
-
[![node.js](https://img.shields.io/badge/node-%3E%3D%
|
8
|
+
[![node.js](https://img.shields.io/badge/node-%3E%3D%2012.0.0-brightgreen.svg)](https://www.npmjs.com/package/@rails/webpacker)
|
9
9
|
[![Gem](https://img.shields.io/gem/v/webpacker.svg)](https://rubygems.org/gems/webpacker)
|
10
10
|
|
11
11
|
Webpacker makes it easy to use the JavaScript pre-processor and bundler
|
12
12
|
[Webpack v5](https://webpack.js.org/)
|
13
|
-
to manage application-like JavaScript in Rails. It
|
14
|
-
|
15
|
-
even JavaScript Sprinkles (that all continues to live in app/assets).
|
16
|
-
|
17
|
-
However, it is possible to use Webpacker for CSS, images and fonts assets as well,
|
18
|
-
in which case you may not even need the asset pipeline. This is mostly relevant when exclusively using component-based JavaScript frameworks.
|
13
|
+
to manage application-like JavaScript in Rails. It can coexist with the asset pipeline,
|
14
|
+
leaving Webpack responsible solely for app-like JavaScript, or it can be used exclusively, making it also responsible for images, fronts, and CSS as well.
|
19
15
|
|
20
16
|
**NOTE:** The master branch now hosts the code for v6.x.x. Please refer to [5-x-stable](https://github.com/rails/webpacker/tree/5-x-stable) branch for 5.x documentation.
|
21
17
|
|
@@ -26,16 +22,29 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
26
22
|
|
27
23
|
- [Prerequisites](#prerequisites)
|
28
24
|
- [Features](#features)
|
25
|
+
- [Optional support](#optional-support)
|
29
26
|
- [Installation](#installation)
|
30
27
|
- [Usage](#usage)
|
28
|
+
- [Server-Side Rendering (SSR)](#server-side-rendering-ssr)
|
31
29
|
- [Development](#development)
|
32
30
|
- [Webpack Configuration](#webpack-configuration)
|
31
|
+
- [Babel Configuration](#babel-configuration)
|
32
|
+
- [Integrations](#integrations)
|
33
|
+
- [React](#react)
|
34
|
+
- [CoffeeScript](#coffeescript)
|
35
|
+
- [TypeScript](#typescript)
|
36
|
+
- [CSS](#css)
|
37
|
+
- [Postcss](#postcss)
|
38
|
+
- [Sass](#sass)
|
39
|
+
- [Less](#less)
|
40
|
+
- [Stylus](#stylus)
|
41
|
+
- [Other frameworks](#other-frameworks)
|
33
42
|
- [Custom Rails environments](#custom-rails-environments)
|
34
43
|
- [Upgrading](#upgrading)
|
35
44
|
- [Paths](#paths)
|
36
|
-
- [
|
37
|
-
- [Watched](#watched)
|
45
|
+
- [Additional paths](#additional-paths)
|
38
46
|
- [Deployment](#deployment)
|
47
|
+
- [Troubleshooting](#troubleshooting)
|
39
48
|
- [Contributing](#contributing)
|
40
49
|
- [License](#license)
|
41
50
|
|
@@ -45,8 +54,8 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
45
54
|
|
46
55
|
- Ruby 2.4+
|
47
56
|
- Rails 5.2+
|
48
|
-
- Node.js
|
49
|
-
- Yarn
|
57
|
+
- Node.js 12.13.0+ || 14+
|
58
|
+
- Yarn
|
50
59
|
|
51
60
|
## Features
|
52
61
|
|
@@ -69,39 +78,28 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
69
78
|
|
70
79
|
## Installation
|
71
80
|
|
72
|
-
You can
|
73
|
-
using new `--webpack` option:
|
81
|
+
You can configure a new Rails application with Webpacker right from the start using the `--webpack` option:
|
74
82
|
|
75
83
|
```bash
|
76
|
-
# Available Rails 5.1+
|
77
84
|
rails new myapp --webpack
|
78
85
|
```
|
79
86
|
|
80
|
-
Or add it
|
87
|
+
Or you can add it later by changing your `Gemfile`:
|
81
88
|
|
82
89
|
```ruby
|
83
90
|
# Gemfile
|
84
|
-
gem 'webpacker', '~> 6.
|
91
|
+
gem 'webpacker', '~> 6.0'
|
85
92
|
|
86
93
|
# OR if you prefer to use master
|
87
94
|
gem 'webpacker', git: 'https://github.com/rails/webpacker.git'
|
88
95
|
yarn add https://github.com/rails/webpacker.git
|
89
96
|
```
|
90
97
|
|
91
|
-
|
98
|
+
Then running the following to install Webpacker:
|
92
99
|
|
93
100
|
```bash
|
94
|
-
bundle
|
95
|
-
|
96
|
-
|
97
|
-
# OR (on rails version < 5.0)
|
98
|
-
bundle exec rake webpacker:install
|
99
|
-
```
|
100
|
-
|
101
|
-
Optional: To fix ["unmet peer dependency" warnings](https://github.com/rails/webpacker/issues/1078),
|
102
|
-
|
103
|
-
```bash
|
104
|
-
yarn upgrade
|
101
|
+
./bin/bundle install
|
102
|
+
./bin/rails webpacker:install
|
105
103
|
```
|
106
104
|
|
107
105
|
When `package.json` and/or `yarn.lock` changes, such as when pulling down changes to your local environment in a team settings, be sure to keep your NPM packages up-to-date:
|
@@ -135,6 +133,35 @@ You can then link the JavaScript pack in Rails views using the `javascript_pack_
|
|
135
133
|
<%= stylesheet_pack_tag 'application' %>
|
136
134
|
```
|
137
135
|
|
136
|
+
The `javascript_pack_tag` and `stylesheet_pack_tag` helpers will include all the transpiled
|
137
|
+
packs with the chunks in your view, which creates html tags for all the chunks.
|
138
|
+
|
139
|
+
The result looks like this:
|
140
|
+
|
141
|
+
```erb
|
142
|
+
<%= javascript_pack_tag 'calendar', 'map' %>
|
143
|
+
|
144
|
+
<script src="/packs/vendor-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
145
|
+
<script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
146
|
+
<script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
147
|
+
<script src="/packs/map~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
148
|
+
<script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
149
|
+
```
|
150
|
+
|
151
|
+
**Important:** Pass all your pack names as multiple arguments, not multiple calls, when using `javascript_pack_tag` and the **`stylesheet_pack_tag`. Otherwise, you will get duplicated chunks on the page. Be especially careful if you might be calling these view helpers from your view, partials, and the layout for a page. You will need some logic to ensure you call the helpers only once with multiple arguments.
|
152
|
+
|
153
|
+
```erb
|
154
|
+
<%# DO %>
|
155
|
+
<%= javascript_pack_tag 'calendar', 'map' %>
|
156
|
+
<%= stylesheet_pack_tag 'calendar', 'map' %>
|
157
|
+
|
158
|
+
<%# DON'T %>
|
159
|
+
<%= javascript_pack_tag 'calendar' %>
|
160
|
+
<%= javascript_pack_tag 'map' %>
|
161
|
+
<%= stylesheet_pack_tag 'calendar' %>
|
162
|
+
<%= stylesheet_pack_tag 'map' %>
|
163
|
+
```
|
164
|
+
|
138
165
|
If you want to link a static asset for `<img />` tag, you can use the `asset_pack_path` helper:
|
139
166
|
```erb
|
140
167
|
<img src="<%= asset_pack_path 'images/logo.svg' %>" />
|
@@ -164,39 +191,20 @@ If you want to use images in your stylesheets:
|
|
164
191
|
}
|
165
192
|
```
|
166
193
|
|
167
|
-
|
168
|
-
|
169
|
-
your JavaScript should create the link prefetch HTML tags that you will use, so you won't
|
170
|
-
|
194
|
+
#### Server-Side Rendering (SSR)
|
195
|
+
|
196
|
+
Note, if you are using server-side rendering of JavaScript with dynamic code-spliting, as is often done with extensions to Webpacker, like [React on Rails](https://github.com/shakacode/react_on_rails), your JavaScript should create the link prefetch HTML tags that you will use, so you won't need to use to `asset_pack_path` in those circumstances.
|
197
|
+
|
198
|
+
**Note:** In order for your styles or static assets files to be available in your view, you would need to link them in your "pack" or entry file. Otherwise, Webpack won't know to package up those files.
|
171
199
|
|
172
|
-
**Note:** In order for your styles or static assets files to be available in your view,
|
173
|
-
you would need to link them in your "pack" or entry file. Otherwise, Webpack won't know
|
174
|
-
to package up those files.
|
175
200
|
|
176
201
|
### Development
|
177
202
|
|
178
|
-
Webpacker ships with two binstubs: `./bin/webpack` and `./bin/webpack-dev-server`.
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
In development, Webpacker compiles on demand rather than upfront by default. This
|
184
|
-
happens when you refer to any of the pack assets using the Webpacker helper methods.
|
185
|
-
This means that you don't have to run any separate processes. Compilation errors are logged
|
186
|
-
to the standard Rails log. However, this auto-compilation happens when a web request
|
187
|
-
is made that requires an updated webpack build, not when files change. Thus, that can
|
188
|
-
be painfully slow for front-end development in this default way. Instead, you should either
|
189
|
-
run the `bin/webpack --watch` or run `./bin/webpack-dev-server`
|
190
|
-
|
191
|
-
If you want to use live code reloading, or you have enough JavaScript that on-demand compilation is too slow, you'll need to run `./bin/webpack-dev-server` or `ruby ./bin/webpack-dev-server`.
|
192
|
-
Windows users will need to run these commands in a terminal separate from `bundle exec rails s`.
|
193
|
-
This process will watch for changes in the `app/packs/entrypoints/*.js` files and automatically
|
194
|
-
reload the browser to match. This feature is also known as
|
195
|
-
[Hot Module Replacement](https://webpack.js.org/concepts/hot-module-replacement/).
|
196
|
-
|
197
|
-
HMR is only the first step to running "Fast Refresh" with React. For more information
|
198
|
-
on how to configure rails/webpacker for Fast Refresh with React, see article
|
199
|
-
[HMR and React Hot Reloading](https://github.com/shakacode/react_on_rails/blob/master/docs/rails-webpacker-react-integration-options.md#hmr-and-react-hot-reloading).
|
203
|
+
Webpacker ships with two binstubs: `./bin/webpack` and `./bin/webpack-dev-server`. Both are thin wrappers around the standard `webpack.js` and `webpack-dev-server.js` executables to ensure that the right configuration files and environmental variables are loaded based on your environment.
|
204
|
+
|
205
|
+
In development, Webpacker compiles on demand rather than upfront by default. This happens when you refer to any of the pack assets using the Webpacker helper methods. This means that you don't have to run any separate processes. Compilation errors are logged to the standard Rails log. However, this auto-compilation happens when a web request is made that requires an updated webpack build, not when files change. Thus, that can be painfully slow for front-end development in this default way. Instead, you should either run the `bin/webpack --watch` or run `./bin/webpack-dev-server`
|
206
|
+
|
207
|
+
If you want to use live code reloading, or you have enough JavaScript that on-demand compilation is too slow, you'll need to run `./bin/webpack-dev-server` or `ruby ./bin/webpack-dev-server`. Windows users will need to run these commands in a terminal separate from `bundle exec rails s`. This process will watch for changes in the `app/packs/entrypoints/*.js` files and automatically reload the browser to match. This feature is also known as [Hot Module Replacement](https://webpack.js.org/concepts/hot-module-replacement/).
|
200
208
|
|
201
209
|
```bash
|
202
210
|
# webpack dev server
|
@@ -209,25 +217,15 @@ on how to configure rails/webpacker for Fast Refresh with React, see article
|
|
209
217
|
./bin/webpack
|
210
218
|
```
|
211
219
|
|
212
|
-
Once you start this webpack development server, Webpacker will automatically start proxying all
|
213
|
-
webpack asset requests to this server. When you stop this server, Rails will detect
|
214
|
-
that it's not running and Rails will revert back to on-demand compilation _if_ you have
|
215
|
-
the `compile` option set to true in your `config/webpacker.yml`
|
220
|
+
Once you start this webpack development server, Webpacker will automatically start proxying all webpack asset requests to this server. When you stop this server, Rails will detect that it's not running and Rails will revert back to on-demand compilation _if_ you have the `compile` option set to true in your `config/webpacker.yml`
|
216
221
|
|
217
|
-
You can use environment variables as options supported by
|
218
|
-
[webpack-dev-server](https://webpack.js.org/configuration/dev-server/) in the
|
219
|
-
form `WEBPACKER_DEV_SERVER_<OPTION>`. Please note that these environmental
|
220
|
-
variables will always take precedence over the ones already set in the
|
221
|
-
configuration file, and that the _same_ environmental variables must
|
222
|
-
be available to the `rails server` process.
|
222
|
+
You can use environment variables as options supported by [webpack-dev-server](https://webpack.js.org/configuration/dev-server/) in the form `WEBPACKER_DEV_SERVER_<OPTION>`. Please note that these environmental variables will always take precedence over the ones already set in the configuration file, and that the _same_ environmental variables must be available to the `rails server` process.
|
223
223
|
|
224
224
|
```bash
|
225
225
|
WEBPACKER_DEV_SERVER_HOST=example.com WEBPACKER_DEV_SERVER_INLINE=true WEBPACKER_DEV_SERVER_HOT=false ./bin/webpack-dev-server
|
226
226
|
```
|
227
227
|
|
228
|
-
By default, the webpack dev server listens on `localhost` in development for security purposes.
|
229
|
-
However, if you want your app to be available over local LAN IP or a VM instance like vagrant,
|
230
|
-
you can set the `host` when running `./bin/webpack-dev-server` binstub:
|
228
|
+
By default, the webpack dev server listens on `localhost` in development for security purposes. However, if you want your app to be available over local LAN IP or a VM instance like vagrant, you can set the `host` when running `./bin/webpack-dev-server` binstub:
|
231
229
|
|
232
230
|
```bash
|
233
231
|
WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server
|
@@ -236,23 +234,20 @@ WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server
|
|
236
234
|
**Note:** You need to allow webpack-dev-server host as an allowed origin for `connect-src` if you are running your application in a restrict CSP environment (like Rails 5.2+). This can be done in Rails 5.2+ in the CSP initializer `config/initializers/content_security_policy.rb` with a snippet like this:
|
237
235
|
|
238
236
|
```ruby
|
239
|
-
|
240
|
-
|
241
|
-
|
237
|
+
Rails.application.config.content_security_policy do |policy|
|
238
|
+
policy.connect_src :self, :https, 'http://localhost:3035', 'ws://localhost:3035' if Rails.env.development?
|
239
|
+
end
|
242
240
|
```
|
243
241
|
|
244
242
|
**Note:** Don't forget to prefix `ruby` when running these binstubs on Windows
|
245
243
|
|
244
|
+
|
246
245
|
### Webpack Configuration
|
247
246
|
|
248
|
-
Webpacker gives you a default set of configuration files for test, development and
|
249
|
-
production environments in `config/webpack/*.js`. You can configure each individual
|
250
|
-
environment in their respective files or configure them all in the base
|
247
|
+
Webpacker gives you a default set of configuration files for test, development and production environments in `config/webpack/*.js`. You can configure each individual environment in their respective files or configure them all in the base
|
251
248
|
`config/webpack/base.js` file.
|
252
249
|
|
253
|
-
By default, you don't need to make any changes to `config/webpack/*.js`
|
254
|
-
files since it's all standard production-ready configuration. However,
|
255
|
-
if you do need to customize or add a new loader, this is where you would go.
|
250
|
+
By default, you don't need to make any changes to `config/webpack/*.js` files since it's all standard production-ready configuration. However, if you do need to customize or add a new loader, this is where you would go.
|
256
251
|
|
257
252
|
Here is how you can modify webpack configuration:
|
258
253
|
|
@@ -283,8 +278,7 @@ const customConfig = require('./custom')
|
|
283
278
|
module.exports = merge(webpackConfig, customConfig)
|
284
279
|
```
|
285
280
|
|
286
|
-
If you need access to configs within Webpacker's configuration,
|
287
|
-
you can import them like so:
|
281
|
+
If you need access to configs within Webpacker's configuration, you can import them like so:
|
288
282
|
|
289
283
|
```js
|
290
284
|
// config/webpack/base.js
|
@@ -297,11 +291,51 @@ console.log(webpackConfig.source_path)
|
|
297
291
|
console.log(JSON.stringify(webpackConfig, undefined, 2))
|
298
292
|
```
|
299
293
|
|
294
|
+
### Babel configuration
|
295
|
+
|
296
|
+
By default, you will find the Webpacker preset in your `package.json`.
|
297
|
+
|
298
|
+
```json
|
299
|
+
"babel": {
|
300
|
+
"presets": [
|
301
|
+
"./node_modules/@rails/webpacker/package/babel/preset.js"
|
302
|
+
]
|
303
|
+
},
|
304
|
+
```
|
305
|
+
|
306
|
+
Optionally, you can change your Babel configuration by removing these lines in your `package.json` and add [a Babel configuration file](https://babeljs.io/docs/en/config-files) in your project.
|
307
|
+
|
308
|
+
|
300
309
|
### Integrations
|
301
310
|
|
302
|
-
Webpacker out of the box supports JS and static assets (fonts, images etc.)
|
303
|
-
|
304
|
-
|
311
|
+
Webpacker out of the box supports JS and static assets (fonts, images etc.) compilation. To enable support for CoffeeScript or TypeScript install relevant packages:
|
312
|
+
|
313
|
+
#### React
|
314
|
+
|
315
|
+
```bash
|
316
|
+
yarn add react react-dom @babel/preset-react
|
317
|
+
```
|
318
|
+
|
319
|
+
...if you are using typescript, update your `tsconfig.json`
|
320
|
+
|
321
|
+
```json
|
322
|
+
{
|
323
|
+
"compilerOptions": {
|
324
|
+
"declaration": false,
|
325
|
+
"emitDecoratorMetadata": true,
|
326
|
+
"experimentalDecorators": true,
|
327
|
+
"lib": ["es6", "dom"],
|
328
|
+
"module": "es6",
|
329
|
+
"moduleResolution": "node",
|
330
|
+
"sourceMap": true,
|
331
|
+
"target": "es5",
|
332
|
+
"jsx": "react",
|
333
|
+
"noEmit": true
|
334
|
+
},
|
335
|
+
"exclude": ["**/*.spec.ts", "node_modules", "vendor", "public"],
|
336
|
+
"compileOnSave": false
|
337
|
+
}
|
338
|
+
```
|
305
339
|
|
306
340
|
#### CoffeeScript
|
307
341
|
|
@@ -315,6 +349,12 @@ yarn add coffeescript coffee-loader
|
|
315
349
|
yarn add typescript @babel/preset-typescript
|
316
350
|
```
|
317
351
|
|
352
|
+
Babel won’t perform any type-checking on TypeScript code. To optionally use type-checking run:
|
353
|
+
|
354
|
+
```bash
|
355
|
+
yarn add fork-ts-checker-webpack-plugin
|
356
|
+
```
|
357
|
+
|
318
358
|
Add tsconfig.json
|
319
359
|
|
320
360
|
```json
|
@@ -339,12 +379,6 @@ Add tsconfig.json
|
|
339
379
|
}
|
340
380
|
```
|
341
381
|
|
342
|
-
Babel won’t perform any type-checking on TypeScript code. To optionally use type-checking run:
|
343
|
-
|
344
|
-
```bash
|
345
|
-
yarn add fork-ts-checker-webpack-plugin
|
346
|
-
```
|
347
|
-
|
348
382
|
Then modify the webpack config to use it as a plugin:
|
349
383
|
|
350
384
|
```js
|
@@ -362,10 +396,10 @@ module.exports = merge(webpackConfig, {
|
|
362
396
|
To enable CSS support in your application, add following packages:
|
363
397
|
|
364
398
|
```bash
|
365
|
-
yarn add css-loader mini-css-extract-plugin css-minimizer-webpack-plugin
|
399
|
+
yarn add css-loader style-loader mini-css-extract-plugin css-minimizer-webpack-plugin
|
366
400
|
```
|
367
401
|
|
368
|
-
|
402
|
+
Optionally, add the `CSS` extension to webpack config for easy resolution.
|
369
403
|
|
370
404
|
```js
|
371
405
|
// config/webpack/base.js
|
@@ -379,13 +413,18 @@ const customConfig = {
|
|
379
413
|
module.exports = merge(webpackConfig, customConfig)
|
380
414
|
```
|
381
415
|
|
382
|
-
To enable
|
416
|
+
To enable `PostCSS`, `Sass` or `Less` support, add `CSS` support first and
|
383
417
|
then add the relevant pre-processors:
|
384
418
|
|
385
419
|
#### Postcss
|
386
420
|
|
387
421
|
```bash
|
388
|
-
yarn add postcss-loader
|
422
|
+
yarn add postcss postcss-loader
|
423
|
+
```
|
424
|
+
|
425
|
+
Optionally add these two plugins if they are required in your `postcss.config.js`:
|
426
|
+
```bash
|
427
|
+
yarn add postcss-preset-env postcss-flexbugs-fixes
|
389
428
|
```
|
390
429
|
|
391
430
|
#### Sass
|
@@ -406,39 +445,6 @@ yarn add less less-loader
|
|
406
445
|
yarn add stylus stylus-loader
|
407
446
|
```
|
408
447
|
|
409
|
-
#### React
|
410
|
-
|
411
|
-
React is supported and you just need to add relevant packages,
|
412
|
-
|
413
|
-
```bash
|
414
|
-
yarn add react react-dom @babel/preset-react
|
415
|
-
```
|
416
|
-
|
417
|
-
if you are using typescript, update your `tsconfig.json`
|
418
|
-
|
419
|
-
```json
|
420
|
-
{
|
421
|
-
"compilerOptions": {
|
422
|
-
"declaration": false,
|
423
|
-
"emitDecoratorMetadata": true,
|
424
|
-
"experimentalDecorators": true,
|
425
|
-
"lib": ["es6", "dom"],
|
426
|
-
"module": "es6",
|
427
|
-
"moduleResolution": "node",
|
428
|
-
"sourceMap": true,
|
429
|
-
"target": "es5",
|
430
|
-
"jsx": "react",
|
431
|
-
"noEmit": true
|
432
|
-
},
|
433
|
-
"exclude": ["**/*.spec.ts", "node_modules", "vendor", "public"],
|
434
|
-
"compileOnSave": false
|
435
|
-
}
|
436
|
-
```
|
437
|
-
|
438
|
-
For more information on React props hydration and Server-Side Rendering (SSR), see the article
|
439
|
-
[Rails/Webpacker React Integration Options](https://github.com/shakacode/react_on_rails/blob/master/docs/rails-webpacker-react-integration-options.md)
|
440
|
-
in the [ShakaCode/react_on_rails](https://github.com/shakacode/react_on_rails) repo.
|
441
|
-
|
442
448
|
#### Other frameworks
|
443
449
|
|
444
450
|
Please follow webpack integration guide for relevant framework or library,
|
@@ -450,7 +456,7 @@ Please follow webpack integration guide for relevant framework or library,
|
|
450
456
|
For example to add Vue support:
|
451
457
|
```js
|
452
458
|
// config/webpack/rules/vue.js
|
453
|
-
const VueLoaderPlugin = require('vue-loader
|
459
|
+
const { VueLoaderPlugin } = require('vue-loader')
|
454
460
|
|
455
461
|
module.exports = {
|
456
462
|
module: {
|
@@ -461,7 +467,10 @@ module.exports = {
|
|
461
467
|
}
|
462
468
|
]
|
463
469
|
},
|
464
|
-
plugins: [new VueLoaderPlugin()]
|
470
|
+
plugins: [new VueLoaderPlugin()],
|
471
|
+
resolve: {
|
472
|
+
extensions: ['.vue']
|
473
|
+
}
|
465
474
|
}
|
466
475
|
```
|
467
476
|
|
@@ -470,9 +479,10 @@ module.exports = {
|
|
470
479
|
const { webpackConfig, merge } = require('@rails/webpacker')
|
471
480
|
const vueConfig = require('./rules/vue')
|
472
481
|
|
473
|
-
module.exports = merge(
|
482
|
+
module.exports = merge(vueConfig, webpackConfig)
|
474
483
|
```
|
475
484
|
|
485
|
+
|
476
486
|
### Custom Rails environments
|
477
487
|
|
478
488
|
Out of the box Webpacker ships with - development, test and production environments in `config/webpacker.yml` however, in most production apps extra environments are needed as part of deployment workflow. Webpacker supports this out of the box from version 3.4.0+ onwards.
|
@@ -493,8 +503,7 @@ staging:
|
|
493
503
|
public_output_path: packs-staging
|
494
504
|
```
|
495
505
|
|
496
|
-
|
497
|
-
This means you don't need to create additional environment files inside `config/webpacker/*` and instead use webpacker.yml to load different configurations using `RAILS_ENV`.
|
506
|
+
Otherwise Webpacker will use production environment as a fallback environment for loading configurations. Please note, `NODE_ENV` can either be set to `production`, `development` or `test`. This means you don't need to create additional environment files inside `config/webpacker/*` and instead use webpacker.yml to load different configurations using `RAILS_ENV`.
|
498
507
|
|
499
508
|
For example, the below command will compile assets in production mode but will use staging configurations from `config/webpacker.yml` if available or use fallback production environment configuration:
|
500
509
|
|
@@ -502,15 +511,13 @@ For example, the below command will compile assets in production mode but will u
|
|
502
511
|
RAILS_ENV=staging bundle exec rails assets:precompile
|
503
512
|
```
|
504
513
|
|
505
|
-
And, this will compile in development mode and load configuration for cucumber environment
|
506
|
-
if defined in webpacker.yml or fallback to production configuration
|
514
|
+
And, this will compile in development mode and load configuration for cucumber environment if defined in webpacker.yml or fallback to production configuration
|
507
515
|
|
508
516
|
```bash
|
509
517
|
RAILS_ENV=cucumber NODE_ENV=development bundle exec rails assets:precompile
|
510
518
|
```
|
511
519
|
|
512
|
-
Please note, binstubs compiles in development mode however rake tasks
|
513
|
-
compiles in production mode.
|
520
|
+
Please note, binstubs compiles in development mode however rake tasks compiles in production mode.
|
514
521
|
|
515
522
|
```bash
|
516
523
|
# Compiles in development mode unless NODE_ENV is specified, per the binstub source
|
@@ -533,9 +540,14 @@ bundle update webpacker
|
|
533
540
|
# overwrite your changes to the default install files and revert any unwanted changes from the install
|
534
541
|
rails webpacker:install
|
535
542
|
|
543
|
+
# yarn 1 instructions
|
536
544
|
yarn upgrade @rails/webpacker --latest
|
537
545
|
yarn upgrade webpack-dev-server --latest
|
538
546
|
|
547
|
+
# yarn 2 instructions
|
548
|
+
yarn up @rails/webpacker@latest
|
549
|
+
yarn up webpack-dev-server@latest
|
550
|
+
|
539
551
|
# Or to install the latest release (including pre-releases)
|
540
552
|
yarn add @rails/webpacker@next
|
541
553
|
```
|
@@ -544,19 +556,11 @@ Also, consult the [CHANGELOG](./CHANGELOG.md) for additional upgrade links.
|
|
544
556
|
|
545
557
|
## Paths
|
546
558
|
|
547
|
-
By default, Webpacker ships with simple conventions for where the JavaScript
|
548
|
-
app files and compiled webpack bundles will go in your Rails app.
|
549
|
-
All these options are configurable from `config/webpacker.yml` file.
|
559
|
+
By default, Webpacker ships with simple conventions for where the JavaScript app files and compiled webpack bundles will go in your Rails app. All these options are configurable from `config/webpacker.yml` file.
|
550
560
|
|
551
|
-
The configuration for what webpack is supposed to compile by default rests
|
552
|
-
on the convention that every file in `app/packs/entrypoints/*`**(default)**
|
553
|
-
or whatever path you set for `source_entry_path` in the `webpacker.yml` configuration
|
554
|
-
is turned into their own output files (or entry points, as webpack calls it). Therefore you don't want to put anything inside `packs` directory that you do not want to be
|
555
|
-
an entry file. As a rule of thumb, put all files you want to link in your views inside
|
556
|
-
"packs" directory and keep everything else under `app/packs`.
|
561
|
+
The configuration for what webpack is supposed to compile by default rests on the convention that every file in `app/packs/entrypoints/*`**(default)** or whatever path you set for `source_entry_path` in the `webpacker.yml` configuration is turned into their own output files (or entry points, as webpack calls it). Therefore you don't want to put anything inside `packs` directory that you do not want to be an entry file. As a rule of thumb, put all files you want to link in your views inside "packs" directory and keep everything else under `app/packs`.
|
557
562
|
|
558
|
-
Suppose you want to change the source directory from `app/packs`
|
559
|
-
to `frontend` and output to `assets/packs`. This is how you would do it:
|
563
|
+
Suppose you want to change the source directory from `app/packs` to `frontend` and output to `assets/packs`. This is how you would do it:
|
560
564
|
|
561
565
|
```yml
|
562
566
|
# config/webpacker.yml
|
@@ -574,16 +578,11 @@ development:
|
|
574
578
|
port: 3035
|
575
579
|
```
|
576
580
|
|
577
|
-
If you have `hmr` turned to true, then the `stylesheet_pack_tag` generates no output,
|
578
|
-
as you will want to configure your styles to be inlined in your JavaScript for hot reloading.
|
579
|
-
During production and testing, the `stylesheet_pack_tag` will create the appropriate HTML tags.
|
581
|
+
If you have `hmr` turned to true, then the `stylesheet_pack_tag` generates no output, as you will want to configure your styles to be inlined in your JavaScript for hot reloading. During production and testing, the `stylesheet_pack_tag` will create the appropriate HTML tags.
|
580
582
|
|
581
583
|
### Additional paths
|
582
584
|
|
583
|
-
If you are adding Webpacker to an existing app that has most of the assets inside
|
584
|
-
`app/assets` or inside an engine, and you want to share that
|
585
|
-
with webpack modules, you can use the `additional_paths`
|
586
|
-
option available in `config/webpacker.yml`. This lets you
|
585
|
+
If you are adding Webpacker to an existing app that has most of the assets inside `app/assets` or inside an engine, and you want to share that with webpack modules, you can use the `additional_paths` option available in `config/webpacker.yml`. This lets you
|
587
586
|
add additional paths that webpack should look up when resolving modules:
|
588
587
|
|
589
588
|
```yml
|
@@ -598,9 +597,10 @@ import 'stylesheets/main'
|
|
598
597
|
import 'images/rails.png'
|
599
598
|
```
|
600
599
|
|
601
|
-
**Note:** Please be careful when adding paths here otherwise it
|
602
|
-
|
603
|
-
|
600
|
+
**Note:** Please be careful when adding paths here otherwise it will make the compilation slow, consider adding specific paths instead of whole parent directory if you just need to reference one or two modules
|
601
|
+
|
602
|
+
**Also note:** While importing assets living outside your `source_path` defined in webpacker.yml (like, for instance, assets under `app/assets`) from within your packs using _relative_ paths like `import '../../assets/javascripts/file.js'` will work in development, Webpacker won't recompile the bundle in production unless a file that lives in one of it's watched paths has changed (check out `Webpacker::Compiler#watched_files_digest`). That's why you'd need to add `app/assets` to the additional_paths as stated above and use `import 'javascripts/file.js'` instead.
|
603
|
+
|
604
604
|
|
605
605
|
## Deployment
|
606
606
|
|
@@ -610,16 +610,19 @@ When compiling assets for production on a remote server, such as a continuous in
|
|
610
610
|
|
611
611
|
If you are using a CDN setup, webpacker will use the configured [asset host](https://guides.rubyonrails.org/configuring.html#rails-general-configuration) value to prefix URLs for images or font icons which are included inside JS code or CSS. It is possible to override this value during asset compilation by setting the `WEBPACKER_ASSET_HOST` environment variable.
|
612
612
|
|
613
|
+
|
613
614
|
## Troubleshooting
|
614
615
|
|
615
616
|
See the doc page for [Troubleshooting](./docs/troubleshooting.md).
|
616
617
|
|
618
|
+
|
617
619
|
## Contributing
|
618
620
|
|
619
621
|
[![Code Helpers](https://www.codetriage.com/rails/webpacker/badges/users.svg)](https://www.codetriage.com/rails/webpacker)
|
620
622
|
|
621
623
|
We encourage you to contribute to Webpacker! See [CONTRIBUTING](CONTRIBUTING.md) for guidelines about how to proceed.
|
622
624
|
|
625
|
+
|
623
626
|
## License
|
624
627
|
|
625
628
|
Webpacker is released under the [MIT License](https://opensource.org/licenses/MIT).
|