webpacker 6.0.0.rc.5 → 6.0.0.rc.6
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 +6 -17
- data/.github/workflows/js-lint.yml +6 -17
- data/.github/workflows/ruby.yml +13 -38
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +15 -3
- data/CONTRIBUTING.md +19 -0
- data/Gemfile.lock +7 -7
- data/README.md +28 -19
- data/docs/troubleshooting.md +5 -1
- data/docs/v6_upgrade.md +68 -30
- data/lib/install/{packs/entrypoints/application.js → application.js} +3 -7
- data/lib/install/bin/webpack +4 -7
- data/lib/install/config/webpacker.yml +4 -2
- data/lib/install/package.json +0 -2
- data/lib/install/template.rb +10 -1
- data/lib/tasks/yarn.rake +22 -20
- data/lib/webpacker/railtie.rb +7 -0
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +27 -7
- data/package/__tests__/development.js +2 -9
- data/package/environments/base.js +1 -1
- data/package/environments/development.js +2 -6
- data/package/rules/file.js +1 -1
- data/package.json +12 -12
- data/test/test_app/config/initializers/inspect_autoload_paths.rb +1 -0
- data/test/webpacker_test.rb +4 -0
- data/webpacker.gemspec +1 -1
- data/yarn.lock +1081 -1508
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb700e8975b2ec865da84e152fea23586c8e7a2a428465230255ab97ebe482ce
|
4
|
+
data.tar.gz: c2a023d554364442cd356771cad8b42226a3d6ce3a4708b6a5603151aad886ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb863173d2577d304c03a4e6d66eddc385a62950bf30af00ed29c4abb9039b0290402771f58c9ede11cf9f26d5945136997d78148590871b7247e13b4d3db7cf
|
7
|
+
data.tar.gz: a624efeabf2bdbd7b83b59aa2854e4ebda00c5c476849c03fc585d967810b30fd5d118fbf13f412c40cb6e7fa1fe020f619cc9ede0cd72989c25504f3f8e0e53
|
data/.github/workflows/jest.yml
CHANGED
@@ -8,31 +8,20 @@ jobs:
|
|
8
8
|
strategy:
|
9
9
|
matrix:
|
10
10
|
os: [ubuntu-latest]
|
11
|
-
node: [12.x, 14.x,
|
11
|
+
node: [12.x, 14.x, 16.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
|
-
|
19
16
|
- uses: actions/checkout@v2
|
20
|
-
- name: Get yarn cache directory path
|
21
|
-
id: yarn-cache-dir-path
|
22
|
-
run: echo "::set-output name=dir::$(yarn cache dir)"
|
23
|
-
|
24
|
-
- uses: actions/cache@v2
|
25
|
-
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
|
26
|
-
with:
|
27
|
-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
28
|
-
key: ${{ runner.os }}-${{ matrix.node }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
29
|
-
restore-keys: |
|
30
|
-
${{ runner.os }}-${{ matrix.node }}-yarn-
|
31
|
-
|
32
17
|
- name: Use Node.js ${{ matrix.node }}
|
33
|
-
uses: actions/setup-node@
|
18
|
+
uses: actions/setup-node@v2
|
34
19
|
with:
|
35
20
|
node-version: ${{ matrix.node }}
|
21
|
+
cache: yarn
|
22
|
+
|
23
|
+
- name: Install yarn maybe
|
24
|
+
run: which yarn || npm install -g yarn
|
36
25
|
|
37
26
|
- name: Install dependencies
|
38
27
|
run: yarn --frozen-lockfile
|
@@ -9,31 +9,20 @@ jobs:
|
|
9
9
|
strategy:
|
10
10
|
matrix:
|
11
11
|
os: [ubuntu-latest]
|
12
|
-
node: [14
|
12
|
+
node: [14]
|
13
13
|
|
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
|
-
|
20
17
|
- uses: actions/checkout@v2
|
21
|
-
- name: Get yarn cache directory path
|
22
|
-
id: yarn-cache-dir-path
|
23
|
-
run: echo "::set-output name=dir::$(yarn cache dir)"
|
24
|
-
|
25
|
-
- uses: actions/cache@v2
|
26
|
-
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
|
27
|
-
with:
|
28
|
-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
29
|
-
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
30
|
-
restore-keys: |
|
31
|
-
${{ runner.os }}-yarn-
|
32
|
-
|
33
18
|
- name: Use Node.js ${{ matrix.node }}
|
34
|
-
uses: actions/setup-node@
|
19
|
+
uses: actions/setup-node@v2
|
35
20
|
with:
|
36
21
|
node-version: ${{ matrix.node }}
|
22
|
+
cache: yarn
|
23
|
+
|
24
|
+
- name: Install yarn maybe
|
25
|
+
run: which yarn || npm install -g yarn
|
37
26
|
|
38
27
|
- name: Install dependencies
|
39
28
|
run: yarn --frozen-lockfile
|
data/.github/workflows/ruby.yml
CHANGED
@@ -7,33 +7,21 @@ jobs:
|
|
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 }}
|
10
|
-
env:
|
11
|
-
BUNDLE_JOBS: 4
|
12
|
-
BUNDLE_RETRY: 3
|
13
10
|
strategy:
|
14
11
|
fail-fast: false
|
15
12
|
matrix:
|
16
13
|
os: [ubuntu-latest]
|
17
|
-
ruby:
|
18
|
-
2.
|
19
|
-
|
20
|
-
|
21
|
-
2.
|
22
|
-
|
23
|
-
|
24
|
-
gemfile: [
|
25
|
-
"gemfiles/Gemfile-rails.5.2.x",
|
26
|
-
"gemfiles/Gemfile-rails.6.0.x",
|
27
|
-
"gemfiles/Gemfile-rails.6.1.x"
|
28
|
-
]
|
14
|
+
ruby:
|
15
|
+
- 2.7
|
16
|
+
- "3.0"
|
17
|
+
gemfile:
|
18
|
+
- gemfiles/Gemfile-rails.5.2.x
|
19
|
+
- gemfiles/Gemfile-rails.6.0.x
|
20
|
+
- gemfiles/Gemfile-rails.6.1.x
|
29
21
|
exclude:
|
30
|
-
- ruby: 2.4
|
31
|
-
gemfile: gemfiles/Gemfile-rails.6.0.x
|
32
|
-
- ruby: 2.4
|
33
|
-
gemfile: gemfiles/Gemfile-rails.6.1.x
|
34
22
|
- ruby: 2.5
|
35
23
|
gemfile: gemfiles/Gemfile-rails.6.1.x
|
36
|
-
- ruby: 3.0
|
24
|
+
- ruby: "3.0"
|
37
25
|
gemfile: gemfiles/Gemfile-rails.5.2.x
|
38
26
|
experimental: [false]
|
39
27
|
include:
|
@@ -41,33 +29,20 @@ jobs:
|
|
41
29
|
os: ubuntu-latest
|
42
30
|
gemfile: gemfiles/Gemfile-rails-edge
|
43
31
|
experimental: true
|
44
|
-
- ruby: 3.0
|
32
|
+
- ruby: "3.0"
|
45
33
|
os: ubuntu-latest
|
46
34
|
gemfile: gemfiles/Gemfile-rails-edge
|
47
35
|
experimental: true
|
48
36
|
|
37
|
+
env:
|
38
|
+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
49
39
|
steps:
|
50
40
|
- uses: actions/checkout@v2
|
51
|
-
- uses: actions/cache@v2
|
52
|
-
with:
|
53
|
-
path: /home/runner/bundle
|
54
|
-
key: bundle-use-ruby-${{ matrix.ruby }}-${{ matrix.gemfile }}-gems-${{ hashFiles(matrix.gemfile) }}-${{ hashFiles('**/*.gemspec') }}
|
55
|
-
restore-keys: |
|
56
|
-
bundle-use-ruby-${{ matrix.ruby }}-${{ matrix.gemfile }}-gems-
|
57
|
-
|
58
|
-
- name: Install yarn maybe
|
59
|
-
run: which yarn || sudo npm install -g yarn
|
60
41
|
|
61
42
|
- uses: ruby/setup-ruby@v1
|
62
43
|
with:
|
63
44
|
ruby-version: ${{ matrix.ruby }}
|
64
|
-
|
65
|
-
- name: Bundle install
|
66
|
-
run: |
|
67
|
-
gem install bundler -v 2.1.4
|
68
|
-
bundle config path /home/runner/bundle
|
69
|
-
bundle config --global gemfile ${{ matrix.gemfile }}
|
70
|
-
bundle install --jobs 4 --retry 3
|
45
|
+
bundler-cache: true # Run "bundle install", and cache the result automatically.
|
71
46
|
|
72
47
|
- name: Ruby specs
|
73
|
-
run: bundle exec rake
|
48
|
+
run: bundle exec rake
|
data/.rubocop.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require: rubocop-performance
|
2
2
|
AllCops:
|
3
|
-
TargetRubyVersion: 2.
|
3
|
+
TargetRubyVersion: 2.7
|
4
4
|
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
|
5
5
|
# to ignore them, so only the ones explicitly set in this file are enabled.
|
6
6
|
DisabledByDefault: true
|
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
**Please note that Webpacker 4.1.0 has an installer bug. Please use 4.2.0 or above**
|
4
4
|
|
5
|
-
## [[6.0.0]](https://github.com/rails/webpacker/compare/v5.
|
5
|
+
## [[6.0.0]](https://github.com/rails/webpacker/compare/v5.4.3...master) - 2021-TBD
|
6
6
|
|
7
7
|
Please see [UPGRADE GUIDE](./docs/v6_upgrade.md) for more information.
|
8
8
|
|
@@ -26,14 +26,26 @@ environment.loaders.append('nodeModules', nodeModules)
|
|
26
26
|
- Splitchunks enabled by default
|
27
27
|
- CSS extraction enabled by default, except when devServer is configured and running
|
28
28
|
|
29
|
+
## [[5.4.3]](https://github.com/rails/webpacker/compare/v5.4.2...v5.4.3) - 2021-09-14
|
30
|
+
|
31
|
+
- Specify webpack-dev-server to be v3, to avoid getting webpack-dev-server v4 ([#3121](https://github.com/rails/webpacker/pull/3121))
|
32
|
+
|
33
|
+
## [[5.4.2]](https://github.com/rails/webpacker/compare/v5.4.1...v5.4.2) - 2021-08-20
|
34
|
+
|
35
|
+
- Fix babel warning about private-methods in `@babel/plugin-proposal-private-property-in-object` as well ([67fa6edf](https://github.com/rails/webpacker/commit/67fa6edf697340cbd5a5518afebac871ef74769b)).
|
36
|
+
|
37
|
+
## [[5.4.1]](https://github.com/rails/webpacker/compare/v5.4.0...v5.4.1) - 2021-08-20
|
38
|
+
|
39
|
+
- Update all dependencies within the same major version ([#3120](https://github.com/rails/webpacker/pull/3120))
|
40
|
+
- Fix babel warning about private-methods ([#3016](https://github.com/rails/webpacker/pull/3016))
|
41
|
+
|
29
42
|
## [[5.4.0]](https://github.com/rails/webpacker/compare/v5.3.0...v5.4.0) - 2021-05-18
|
30
43
|
|
31
|
-
- Fix compatibility with Psych 4
|
44
|
+
- Fix compatibility with Psych 4 ([ceaf826d](https://github.com/rails/webpacker/commit/ceaf826d84230aaadbefdbaaf560d474a96affcc))
|
32
45
|
|
33
46
|
## [[5.3.0]](https://github.com/rails/webpacker/compare/v5.2.1...v5.3.0) - 2021-04-27
|
34
47
|
|
35
48
|
- Adds experimental Yarn 2 support. Note you must manually set `nodeLinker: node-modules` in your `.yarnrc.yml`.
|
36
|
-
|
37
49
|
- Keep backups, even when they're old [#2912](https://github.com/rails/webpacker/pull/2912)
|
38
50
|
|
39
51
|
## [[5.2.2]](https://github.com/rails/webpacker/compare/v5.2.1...v5.2.2) - 2021-04-27
|
data/CONTRIBUTING.md
CHANGED
@@ -3,31 +3,50 @@
|
|
3
3
|
1. Install [Yarn](https://yarnpkg.com/)
|
4
4
|
|
5
5
|
2. Run the following commands to set up the development environment.
|
6
|
+
|
6
7
|
```
|
7
8
|
bundle install
|
8
9
|
yarn
|
9
10
|
```
|
10
11
|
|
11
12
|
## Making sure your changes pass all tests
|
13
|
+
|
12
14
|
There are a number of automated checks which run on GitHub Actions when a pull request is created.
|
15
|
+
|
13
16
|
You can run those checks on your own locally to make sure that your changes would not break the CI build.
|
14
17
|
|
15
18
|
### 1. Check the code for JavaScript style violations
|
19
|
+
|
16
20
|
```
|
17
21
|
yarn lint
|
18
22
|
```
|
19
23
|
|
20
24
|
### 2. Check the code for Ruby style violations
|
25
|
+
|
21
26
|
```
|
22
27
|
bundle exec rubocop
|
23
28
|
```
|
24
29
|
|
25
30
|
### 3. Run the JavaScript test suite
|
31
|
+
|
26
32
|
```
|
27
33
|
yarn test
|
28
34
|
```
|
29
35
|
|
30
36
|
### 4. Run the Ruby test suite
|
37
|
+
|
31
38
|
```
|
32
39
|
bundle exec rake test
|
33
40
|
```
|
41
|
+
|
42
|
+
#### 4.1 Run a single ruby test file
|
43
|
+
|
44
|
+
```
|
45
|
+
bundle exec rake test TEST=test/rake_tasks_test.rb
|
46
|
+
```
|
47
|
+
|
48
|
+
#### 4.2 Run a single ruby test
|
49
|
+
|
50
|
+
```
|
51
|
+
ruby -I test test/rake_tasks_test.rb -n test_rake_webpacker_install
|
52
|
+
```
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
webpacker (6.0.0.rc.
|
4
|
+
webpacker (6.0.0.rc.6)
|
5
5
|
activesupport (>= 5.2)
|
6
6
|
rack-proxy (>= 0.6.1)
|
7
7
|
railties (>= 5.2)
|
@@ -84,16 +84,16 @@ GEM
|
|
84
84
|
nokogiri (>= 1.5.9)
|
85
85
|
mail (2.7.1)
|
86
86
|
mini_mime (>= 0.1.1)
|
87
|
-
marcel (1.0.
|
87
|
+
marcel (1.0.2)
|
88
88
|
method_source (1.0.0)
|
89
89
|
mini_mime (1.1.1)
|
90
90
|
mini_portile2 (2.6.1)
|
91
91
|
minitest (5.14.4)
|
92
92
|
nio4r (2.5.8)
|
93
|
-
nokogiri (1.12.
|
93
|
+
nokogiri (1.12.4)
|
94
94
|
mini_portile2 (~> 2.6.1)
|
95
95
|
racc (~> 1.4)
|
96
|
-
parallel (1.
|
96
|
+
parallel (1.21.0)
|
97
97
|
parser (3.0.2.0)
|
98
98
|
ast (~> 2.4.1)
|
99
99
|
racc (1.5.2)
|
@@ -132,7 +132,7 @@ GEM
|
|
132
132
|
rake (13.0.6)
|
133
133
|
regexp_parser (2.1.1)
|
134
134
|
rexml (3.2.5)
|
135
|
-
rubocop (1.
|
135
|
+
rubocop (1.21.0)
|
136
136
|
parallel (~> 1.10)
|
137
137
|
parser (>= 3.0.0.0)
|
138
138
|
rainbow (>= 2.2.2, < 4.0)
|
@@ -158,7 +158,7 @@ GEM
|
|
158
158
|
thor (1.1.0)
|
159
159
|
tzinfo (2.0.4)
|
160
160
|
concurrent-ruby (~> 1.0)
|
161
|
-
unicode-display_width (2.
|
161
|
+
unicode-display_width (2.1.0)
|
162
162
|
websocket-driver (0.7.5)
|
163
163
|
websocket-extensions (>= 0.1.0)
|
164
164
|
websocket-extensions (0.1.5)
|
@@ -180,4 +180,4 @@ DEPENDENCIES
|
|
180
180
|
webpacker!
|
181
181
|
|
182
182
|
BUNDLED WITH
|
183
|
-
2.2.
|
183
|
+
2.2.30
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
Webpacker makes it easy to use the JavaScript pre-processor and bundler
|
12
12
|
[Webpack v5](https://webpack.js.org/)
|
13
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,
|
14
|
+
leaving Webpack responsible solely for app-like JavaScript, or it can be used exclusively, making it also responsible for images, fonts, and CSS.
|
15
15
|
|
16
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.
|
17
17
|
|
@@ -78,10 +78,10 @@ leaving Webpack responsible solely for app-like JavaScript, or it can be used ex
|
|
78
78
|
|
79
79
|
## Installation
|
80
80
|
|
81
|
-
You can configure a new Rails application with Webpacker right from the start using the
|
81
|
+
You can configure a new Rails application with Webpacker right from the start using the `-j webpack` option:
|
82
82
|
|
83
83
|
```bash
|
84
|
-
rails new myapp
|
84
|
+
rails new myapp -j webpack
|
85
85
|
```
|
86
86
|
|
87
87
|
Or you can add it later by changing your `Gemfile`:
|
@@ -113,11 +113,10 @@ yarn install
|
|
113
113
|
Once installed, you can start writing modern ES6-flavored JavaScript apps right away:
|
114
114
|
|
115
115
|
```yml
|
116
|
-
app/
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
│ └── application.css
|
116
|
+
app/javascript:
|
117
|
+
# Only Webpack entry files here
|
118
|
+
└── application.js
|
119
|
+
└── application.css
|
121
120
|
└── src:
|
122
121
|
│ └── my_component.js
|
123
122
|
└── stylesheets:
|
@@ -139,13 +138,13 @@ packs with the chunks in your view, which creates html tags for all the chunks.
|
|
139
138
|
The result looks like this:
|
140
139
|
|
141
140
|
```erb
|
142
|
-
<%= javascript_pack_tag 'calendar', 'map' %>
|
141
|
+
<%= javascript_pack_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
|
143
142
|
|
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>
|
143
|
+
<script src="/packs/vendor-16838bab065ae1e314.js" data-turbolinks-track="reload" defer></script>
|
144
|
+
<script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload" defer></script>
|
145
|
+
<script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload" defer"></script>
|
146
|
+
<script src="/packs/map~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload" defer></script>
|
147
|
+
<script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload" defer></script>
|
149
148
|
```
|
150
149
|
|
151
150
|
**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.
|
@@ -190,31 +189,41 @@ If you want to use images in your stylesheets:
|
|
190
189
|
background-image: url('../images/logo.svg')
|
191
190
|
}
|
192
191
|
```
|
192
|
+
##### Defer for `javascript_pack_tag`
|
193
|
+
Note, the default of "defer" for the `javascript_pack_tag`. You can override that to `false`. If you expose jquery globally with `expose-loader,` by using `import $ from "expose-loader?exposes=$,jQuery!jquery"` in your `app/packs/entrypoints/application.js`, pass the option `defer: false` to your `javascript_pack_tag`.
|
193
194
|
|
194
195
|
#### Server-Side Rendering (SSR)
|
195
196
|
|
196
|
-
Note, if you are using server-side rendering of JavaScript with dynamic code-
|
197
|
+
Note, if you are using server-side rendering of JavaScript with dynamic code-splitting, 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
|
|
198
199
|
**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.
|
199
200
|
|
200
|
-
|
201
201
|
### Development
|
202
202
|
|
203
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
204
|
|
205
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
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 `
|
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 relevant files, defined by `webpacker.yml` configuration settings for `source_path`, `source_entry_path`, and `additional_paths`, and it will then automatically reload the browser to match. This feature is also known as [Hot Module Replacement](https://webpack.js.org/concepts/hot-module-replacement/).
|
208
208
|
|
209
209
|
```bash
|
210
210
|
# webpack dev server
|
211
211
|
./bin/webpack-dev-server
|
212
212
|
|
213
213
|
# watcher
|
214
|
-
./bin/webpack --watch --
|
214
|
+
./bin/webpack --watch --progress
|
215
215
|
|
216
216
|
# standalone build
|
217
|
-
./bin/webpack
|
217
|
+
./bin/webpack --progress
|
218
|
+
|
219
|
+
# Help
|
220
|
+
./bin/webpack help
|
221
|
+
|
222
|
+
# Version
|
223
|
+
./bin/webpack version
|
224
|
+
|
225
|
+
# Info
|
226
|
+
./bin/webpack info
|
218
227
|
```
|
219
228
|
|
220
229
|
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`
|
data/docs/troubleshooting.md
CHANGED
@@ -160,7 +160,11 @@ default: &default
|
|
160
160
|
|
161
161
|
### Using global variables for dependencies
|
162
162
|
|
163
|
-
If you want to access any dependency without importing it everywhere or use it directly in your dev tools, please check: [https://webpack.js.org/plugins/provide-plugin/](https://webpack.js.org/plugins/provide-plugin/)
|
163
|
+
If you want to access any dependency without importing it everywhere or use it directly in your dev tools, please check: [https://webpack.js.org/plugins/provide-plugin/](https://webpack.js.org/plugins/provide-plugin/) and the [webpack docs on shimming globals](https://webpack.js.org/guides/shimming/#shimming-globals).
|
164
|
+
|
165
|
+
Note, if you are exposing globals, like jQuery, to non-webpack dependencies (like an inline script) via the [expose-loader](https://webpack.js.org/loaders/expose-loader/), you will need to override the default of `defer: true` to be `defer:false` your call to the `javascript_pack_tag` so that the browser will load your bundle to setup the global variable before other code depends on it. However, you really should try to remove the dependendency on such globals.
|
166
|
+
|
167
|
+
Thus ProvidePlugin manages build-time dependencies to global symbols whereas the expose-loader manages runtime dependencies to global symbols.
|
164
168
|
|
165
169
|
**You don't need to assign dependencies on `window`.**
|
166
170
|
|
data/docs/v6_upgrade.md
CHANGED
@@ -10,15 +10,29 @@ Webpacker used to configure Webpack indirectly, which lead to a [complicated sec
|
|
10
10
|
|
11
11
|
This means you have to configure integration with frameworks yourself, but webpack-merge helps with this. See this example for [Vue](https://github.com/rails/webpacker#other-frameworks).
|
12
12
|
|
13
|
-
## How to upgrade to Webpacker
|
13
|
+
## How to upgrade to Webpacker v6 from v5
|
14
14
|
|
15
|
-
1. If
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
1. If you are changing from the v5 default for `source_entry_path`:
|
16
|
+
```yml
|
17
|
+
source_path: app/javascript
|
18
|
+
source_entry_path: packs
|
19
|
+
```
|
20
|
+
to the v6 default:
|
21
|
+
```yml
|
22
|
+
source_path: app/javascript
|
23
|
+
source_entry_path: /
|
24
|
+
```
|
25
|
+
Then move your `app/javascript/packs/*` (including `application.js`) to `app/javascript/`.
|
26
|
+
|
27
|
+
Check if you had any entry point files in child directories of your `source_entry_path`. Files for entry points in child directories are not supported by rails/webpacker v6.
|
28
|
+
|
29
|
+
2. Rename `config/webpack` to `config/webpack_old`
|
30
|
+
|
31
|
+
3. Rename `config/webpacker.yml` to `config/webpacker_old.yml`
|
32
|
+
|
33
|
+
4. Uninstall the current version of `webpack-dev-server`: `yarn remove webpack-dev-server`
|
34
|
+
|
35
|
+
5. Upgrade the Webpacker Ruby gem and NPM package
|
22
36
|
|
23
37
|
Note: [Check the releases page to verify the latest version](https://github.com/rails/webpacker/releases), and make sure to install identical version numbers of webpacker gem and `@rails/webpacker` npm package. (Gems use a period and packages use a dot between the main version number and the beta version.)
|
24
38
|
|
@@ -41,9 +55,11 @@ Example going to a specific version:
|
|
41
55
|
bundle exec rails webpacker:install
|
42
56
|
```
|
43
57
|
|
44
|
-
|
45
|
-
|
46
|
-
|
58
|
+
6. Update API usage of the view helpers by changing `javascript_packs_with_chunks_tag` and `stylesheet_packs_with_chunks_tag` to `javascript_pack_tag` and `stylesheet_pack_tag`. Ensure that your layouts and views will only have **at most one call** to `javascript_pack_tag` and **at most one call** to `stylesheet_pack_tag`. You can now pass multiple bundles to these view helper methods. If you fail to changes this, you may experience performance issues, and other bugs related to multiple copies of React, like [issue 2932](https://github.com/rails/webpacker/issues/2932). If you expose jquery globally with `expose-loader,` by using `import $ from "expose-loader?exposes=$,jQuery!jquery"` in your `app/javascript/application.js`, pass the option `defer: false` to your `javascript_pack_tag`.
|
59
|
+
|
60
|
+
7. If you are using any integrations like `css`, `React` or `TypeScript`. Please see https://github.com/rails/webpacker#integrations section on how they work in v6.
|
61
|
+
|
62
|
+
8. Copy over any custom webpack config from `config/webpack_old`. Common code previously called 'environment' should be changed to 'base', and import `environment` changed to `webpackConfig`.
|
47
63
|
|
48
64
|
```js
|
49
65
|
// config/webpack/base.js
|
@@ -53,23 +69,45 @@ Example going to a specific version:
|
|
53
69
|
module.exports = merge(webpackConfig, customConfig)
|
54
70
|
```
|
55
71
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
"
|
62
|
-
"
|
63
|
-
|
64
|
-
|
65
|
-
```
|
66
|
-
12. Remove `postcss.config.js` if you don't use `PostCSS`.
|
67
|
-
13. `extensions` was removed from the `webpacker.yml` file. Move custom extensions to your configuration by merging an object like this. For more details, see docs for [Webpack Configuration](https://github.com/rails/webpacker/blob/master/README.md#webpack-configuration)
|
68
|
-
|
69
|
-
```js
|
70
|
-
{
|
71
|
-
resolve: {
|
72
|
-
extensions: ['.ts', '.tsx', '.vue', '.css']
|
72
|
+
9. Copy over custom browserlist config from `.browserslistrc` if it exists into the `"browserslist"` key in `package.json` and remove `.browserslistrc`.
|
73
|
+
|
74
|
+
10. Remove `babel.config.js` if you never changed it. Be sure to have this config in your `package.json`:
|
75
|
+
|
76
|
+
```json
|
77
|
+
"babel": {
|
78
|
+
"presets": [
|
79
|
+
"./node_modules/@rails/webpacker/package/babel/preset.js"
|
80
|
+
]
|
73
81
|
}
|
74
|
-
|
75
|
-
|
82
|
+
```
|
83
|
+
|
84
|
+
11. Remove `postcss.config.js` if you don't use `PostCSS`.
|
85
|
+
|
86
|
+
12. `extensions` was removed from the `webpacker.yml` file. Move custom extensions to your configuration by merging an object like this. For more details, see docs for [Webpack Configuration](https://github.com/rails/webpacker/blob/master/README.md#webpack-configuration)
|
87
|
+
|
88
|
+
```js
|
89
|
+
{
|
90
|
+
resolve: {
|
91
|
+
extensions: ['.ts', '.tsx', '.vue', '.css']
|
92
|
+
}
|
93
|
+
}
|
94
|
+
```
|
95
|
+
|
96
|
+
13. Some dependencies were removed in [PR 3056](https://github.com/rails/webpacker/pull/3056). If you see the error: `Error: Cannot find module 'babel-plugin-macros'`, or similar, then you need to `yarn add <dependency>` where <dependency> might include: `babel-plugin-macros`, `case-sensitive-paths-webpack-plugin`, `core-js`, `regenerator-runtime`. Or you might want to remove your dependency on those.
|
97
|
+
|
98
|
+
14. If `bin/yarn` does not exist, create an executable [yarn](https://github.com/rails/webpacker/blob/master/lib/install/bin/yarn) file in your `/bin` directory.
|
99
|
+
|
100
|
+
15. Remove overlapping dependencies from your `package.json` and rails/webpacker's `package.json`. For example, don't include `webpack` directly as that's a dependency of rails/webpacker.
|
101
|
+
|
102
|
+
16. Review the new default's changes to `webpacker.yml` and `config/webpack`. Consider each suggested change carefully, especially the change to have your `source_entry_path` be at the top level of your `source_path`.
|
103
|
+
|
104
|
+
17. Make sure that you can run `bin/webpack` without errors.
|
105
|
+
|
106
|
+
18. Try running `RAILS_ENV=production bin/rails assets:precompile`. If all goes well, don't forget to clean the generated assets with `bin/rails assets:clobber`.
|
107
|
+
|
108
|
+
19. Try your app!
|
109
|
+
|
110
|
+
## Examples of v5 to v6
|
111
|
+
|
112
|
+
1. [React on Rails Project with HMR and SSR](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/compare/webpacker-5.x...master)
|
113
|
+
2. [Vue and Sass Example](https://github.com/guillaumebriday/upgrade-webpacker-5-to-6)
|
@@ -1,19 +1,15 @@
|
|
1
1
|
/* eslint no-console:0 */
|
2
2
|
// This file is automatically compiled by Webpack, along with any other files
|
3
3
|
// present in this directory. You're encouraged to place your actual application logic in
|
4
|
-
// a relevant structure within app/
|
4
|
+
// a relevant structure within app/javascript and only use these pack files to reference
|
5
5
|
// that code so it'll be compiled.
|
6
6
|
//
|
7
7
|
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
|
8
8
|
// layout file, like app/views/layouts/application.html.erb
|
9
9
|
|
10
|
-
// Uncomment to copy all static images under
|
10
|
+
// Uncomment to copy all static images under ./images to the output folder and reference
|
11
11
|
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
|
12
12
|
// or the `imagePath` JavaScript helper below.
|
13
13
|
//
|
14
|
-
// const images = require.context('
|
14
|
+
// const images = require.context('./images', true)
|
15
15
|
// const imagePath = (name) => images(name, true)
|
16
|
-
|
17
|
-
// Activate Active Storage
|
18
|
-
// import * as ActiveStorage from "@rails/activestorage"
|
19
|
-
// ActiveStorage.start()
|
data/lib/install/bin/webpack
CHANGED
@@ -1,17 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
|
4
|
-
ENV["NODE_ENV"] ||= "development"
|
5
|
-
|
6
3
|
require "pathname"
|
7
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
8
|
-
Pathname.new(__FILE__).realpath)
|
9
|
-
|
10
4
|
require "bundler/setup"
|
11
|
-
|
12
5
|
require "webpacker"
|
13
6
|
require "webpacker/webpack_runner"
|
14
7
|
|
8
|
+
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
|
9
|
+
ENV["NODE_ENV"] ||= "development"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", Pathname.new(__FILE__).realpath)
|
11
|
+
|
15
12
|
APP_ROOT = File.expand_path("..", __dir__)
|
16
13
|
Dir.chdir(APP_ROOT) do
|
17
14
|
Webpacker::WebpackRunner.run(ARGV)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# Note: You must restart bin/webpack-dev-server for changes to take effect
|
2
2
|
|
3
3
|
default: &default
|
4
|
-
source_path: app/
|
5
|
-
source_entry_path:
|
4
|
+
source_path: app/javascript
|
5
|
+
source_entry_path: /
|
6
6
|
public_root_path: public
|
7
7
|
public_output_path: packs
|
8
8
|
cache_path: tmp/webpacker
|
@@ -26,6 +26,8 @@ development:
|
|
26
26
|
port: 3035
|
27
27
|
# Hot Module Replacement updates modules while the application is running without a full reload
|
28
28
|
hmr: false
|
29
|
+
# Defaults to the inverse of hmr. Uncomment to manually set this.
|
30
|
+
# live_reload: true
|
29
31
|
client:
|
30
32
|
# Should we show a full-screen overlay in the browser when there are compiler errors or warnings?
|
31
33
|
overlay: true
|