webpacker 6.0.0.rc.1 → 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/Gemfile.lock +82 -82
- data/README.md +95 -150
- data/docs/developing_webpacker.md +4 -4
- data/docs/v6_upgrade.md +7 -7
- data/lib/install/bin/yarn +18 -0
- data/lib/install/config/webpacker.yml +12 -11
- data/lib/install/package.json +17 -0
- data/lib/install/template.rb +27 -14
- data/lib/tasks/yarn.rake +36 -0
- data/lib/webpacker/commands.rb +19 -15
- data/lib/webpacker/dev_server_runner.rb +1 -1
- data/lib/webpacker/helper.rb +2 -2
- data/lib/webpacker/version.rb +1 -1
- data/package/__tests__/development.js +3 -3
- data/package/config.js +3 -3
- data/package/env.js +3 -6
- data/package/environments/development.js +34 -28
- data/package.json +8 -8
- data/test/command_test.rb +76 -0
- data/test/dev_server_runner_test.rb +1 -1
- data/test/helper_test.rb +13 -4
- data/webpacker.gemspec +1 -1
- data/yarn.lock +719 -1725
- metadata +11 -8
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/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.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,7 +174,7 @@ 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!
|
data/README.md
CHANGED
@@ -10,12 +10,8 @@
|
|
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
|
|
@@ -32,7 +28,9 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
32
28
|
- [Server-Side Rendering (SSR)](#server-side-rendering-ssr)
|
33
29
|
- [Development](#development)
|
34
30
|
- [Webpack Configuration](#webpack-configuration)
|
31
|
+
- [Babel Configuration](#babel-configuration)
|
35
32
|
- [Integrations](#integrations)
|
33
|
+
- [React](#react)
|
36
34
|
- [CoffeeScript](#coffeescript)
|
37
35
|
- [TypeScript](#typescript)
|
38
36
|
- [CSS](#css)
|
@@ -40,7 +38,6 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
40
38
|
- [Sass](#sass)
|
41
39
|
- [Less](#less)
|
42
40
|
- [Stylus](#stylus)
|
43
|
-
- [React](#react)
|
44
41
|
- [Other frameworks](#other-frameworks)
|
45
42
|
- [Custom Rails environments](#custom-rails-environments)
|
46
43
|
- [Upgrading](#upgrading)
|
@@ -57,8 +54,8 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
57
54
|
|
58
55
|
- Ruby 2.4+
|
59
56
|
- Rails 5.2+
|
60
|
-
- Node.js 12+ || 14+
|
61
|
-
- Yarn
|
57
|
+
- Node.js 12.13.0+ || 14+
|
58
|
+
- Yarn
|
62
59
|
|
63
60
|
## Features
|
64
61
|
|
@@ -81,39 +78,28 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
81
78
|
|
82
79
|
## Installation
|
83
80
|
|
84
|
-
You can
|
85
|
-
using new `--webpack` option:
|
81
|
+
You can configure a new Rails application with Webpacker right from the start using the `--webpack` option:
|
86
82
|
|
87
83
|
```bash
|
88
|
-
# Available Rails 5.1+
|
89
84
|
rails new myapp --webpack
|
90
85
|
```
|
91
86
|
|
92
|
-
Or add it
|
87
|
+
Or you can add it later by changing your `Gemfile`:
|
93
88
|
|
94
89
|
```ruby
|
95
90
|
# Gemfile
|
96
|
-
gem 'webpacker', '~> 6.
|
91
|
+
gem 'webpacker', '~> 6.0'
|
97
92
|
|
98
93
|
# OR if you prefer to use master
|
99
94
|
gem 'webpacker', git: 'https://github.com/rails/webpacker.git'
|
100
95
|
yarn add https://github.com/rails/webpacker.git
|
101
96
|
```
|
102
97
|
|
103
|
-
|
104
|
-
|
105
|
-
```bash
|
106
|
-
bundle
|
107
|
-
bundle exec rails webpacker:install
|
108
|
-
|
109
|
-
# OR (on rails version < 5.0)
|
110
|
-
bundle exec rake webpacker:install
|
111
|
-
```
|
112
|
-
|
113
|
-
Optional: To fix ["unmet peer dependency" warnings](https://github.com/rails/webpacker/issues/1078),
|
98
|
+
Then running the following to install Webpacker:
|
114
99
|
|
115
100
|
```bash
|
116
|
-
|
101
|
+
./bin/bundle install
|
102
|
+
./bin/rails webpacker:install
|
117
103
|
```
|
118
104
|
|
119
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:
|
@@ -162,8 +148,7 @@ The result looks like this:
|
|
162
148
|
<script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
163
149
|
```
|
164
150
|
|
165
|
-
**Important:** Pass all your pack names as multiple arguments, not multiple calls, when using
|
166
|
-
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.
|
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.
|
167
152
|
|
168
153
|
```erb
|
169
154
|
<%# DO %>
|
@@ -207,39 +192,19 @@ If you want to use images in your stylesheets:
|
|
207
192
|
```
|
208
193
|
|
209
194
|
#### Server-Side Rendering (SSR)
|
210
|
-
Note, if you are using server-side rendering of JavaScript with dynamic code-spliting,
|
211
|
-
as is often done with extensions to Webpacker, like [React on Rails](https://github.com/shakacode/react_on_rails)
|
212
|
-
your JavaScript should create the link prefetch HTML tags that you will use, so you won't
|
213
|
-
need to use to `asset_pack_path` in those circumstances.
|
214
195
|
|
215
|
-
|
216
|
-
|
217
|
-
to package up those files.
|
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.
|
199
|
+
|
218
200
|
|
219
201
|
### Development
|
220
202
|
|
221
|
-
Webpacker ships with two binstubs: `./bin/webpack` and `./bin/webpack-dev-server`.
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
In development, Webpacker compiles on demand rather than upfront by default. This
|
227
|
-
happens when you refer to any of the pack assets using the Webpacker helper methods.
|
228
|
-
This means that you don't have to run any separate processes. Compilation errors are logged
|
229
|
-
to the standard Rails log. However, this auto-compilation happens when a web request
|
230
|
-
is made that requires an updated webpack build, not when files change. Thus, that can
|
231
|
-
be painfully slow for front-end development in this default way. Instead, you should either
|
232
|
-
run the `bin/webpack --watch` or run `./bin/webpack-dev-server`
|
233
|
-
|
234
|
-
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`.
|
235
|
-
Windows users will need to run these commands in a terminal separate from `bundle exec rails s`.
|
236
|
-
This process will watch for changes in the `app/packs/entrypoints/*.js` files and automatically
|
237
|
-
reload the browser to match. This feature is also known as
|
238
|
-
[Hot Module Replacement](https://webpack.js.org/concepts/hot-module-replacement/).
|
239
|
-
|
240
|
-
HMR is only the first step to running "Fast Refresh" with React. For more information
|
241
|
-
on how to configure rails/webpacker for Fast Refresh with React, see article
|
242
|
-
[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/).
|
243
208
|
|
244
209
|
```bash
|
245
210
|
# webpack dev server
|
@@ -252,25 +217,15 @@ on how to configure rails/webpacker for Fast Refresh with React, see article
|
|
252
217
|
./bin/webpack
|
253
218
|
```
|
254
219
|
|
255
|
-
Once you start this webpack development server, Webpacker will automatically start proxying all
|
256
|
-
webpack asset requests to this server. When you stop this server, Rails will detect
|
257
|
-
that it's not running and Rails will revert back to on-demand compilation _if_ you have
|
258
|
-
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`
|
259
221
|
|
260
|
-
You can use environment variables as options supported by
|
261
|
-
[webpack-dev-server](https://webpack.js.org/configuration/dev-server/) in the
|
262
|
-
form `WEBPACKER_DEV_SERVER_<OPTION>`. Please note that these environmental
|
263
|
-
variables will always take precedence over the ones already set in the
|
264
|
-
configuration file, and that the _same_ environmental variables must
|
265
|
-
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.
|
266
223
|
|
267
224
|
```bash
|
268
225
|
WEBPACKER_DEV_SERVER_HOST=example.com WEBPACKER_DEV_SERVER_INLINE=true WEBPACKER_DEV_SERVER_HOT=false ./bin/webpack-dev-server
|
269
226
|
```
|
270
227
|
|
271
|
-
By default, the webpack dev server listens on `localhost` in development for security purposes.
|
272
|
-
However, if you want your app to be available over local LAN IP or a VM instance like vagrant,
|
273
|
-
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:
|
274
229
|
|
275
230
|
```bash
|
276
231
|
WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server
|
@@ -279,23 +234,20 @@ WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server
|
|
279
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:
|
280
235
|
|
281
236
|
```ruby
|
282
|
-
|
283
|
-
|
284
|
-
|
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
|
285
240
|
```
|
286
241
|
|
287
242
|
**Note:** Don't forget to prefix `ruby` when running these binstubs on Windows
|
288
243
|
|
244
|
+
|
289
245
|
### Webpack Configuration
|
290
246
|
|
291
|
-
Webpacker gives you a default set of configuration files for test, development and
|
292
|
-
production environments in `config/webpack/*.js`. You can configure each individual
|
293
|
-
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
|
294
248
|
`config/webpack/base.js` file.
|
295
249
|
|
296
|
-
By default, you don't need to make any changes to `config/webpack/*.js`
|
297
|
-
files since it's all standard production-ready configuration. However,
|
298
|
-
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.
|
299
251
|
|
300
252
|
Here is how you can modify webpack configuration:
|
301
253
|
|
@@ -326,8 +278,7 @@ const customConfig = require('./custom')
|
|
326
278
|
module.exports = merge(webpackConfig, customConfig)
|
327
279
|
```
|
328
280
|
|
329
|
-
If you need access to configs within Webpacker's configuration,
|
330
|
-
you can import them like so:
|
281
|
+
If you need access to configs within Webpacker's configuration, you can import them like so:
|
331
282
|
|
332
283
|
```js
|
333
284
|
// config/webpack/base.js
|
@@ -340,11 +291,51 @@ console.log(webpackConfig.source_path)
|
|
340
291
|
console.log(JSON.stringify(webpackConfig, undefined, 2))
|
341
292
|
```
|
342
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
|
+
|
343
309
|
### Integrations
|
344
310
|
|
345
|
-
Webpacker out of the box supports JS and static assets (fonts, images etc.)
|
346
|
-
|
347
|
-
|
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
|
+
```
|
348
339
|
|
349
340
|
#### CoffeeScript
|
350
341
|
|
@@ -358,6 +349,12 @@ yarn add coffeescript coffee-loader
|
|
358
349
|
yarn add typescript @babel/preset-typescript
|
359
350
|
```
|
360
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
|
+
|
361
358
|
Add tsconfig.json
|
362
359
|
|
363
360
|
```json
|
@@ -382,12 +379,6 @@ Add tsconfig.json
|
|
382
379
|
}
|
383
380
|
```
|
384
381
|
|
385
|
-
Babel won’t perform any type-checking on TypeScript code. To optionally use type-checking run:
|
386
|
-
|
387
|
-
```bash
|
388
|
-
yarn add fork-ts-checker-webpack-plugin
|
389
|
-
```
|
390
|
-
|
391
382
|
Then modify the webpack config to use it as a plugin:
|
392
383
|
|
393
384
|
```js
|
@@ -454,39 +445,6 @@ yarn add less less-loader
|
|
454
445
|
yarn add stylus stylus-loader
|
455
446
|
```
|
456
447
|
|
457
|
-
#### React
|
458
|
-
|
459
|
-
React is supported and you just need to add relevant packages,
|
460
|
-
|
461
|
-
```bash
|
462
|
-
yarn add react react-dom @babel/preset-react
|
463
|
-
```
|
464
|
-
|
465
|
-
if you are using typescript, update your `tsconfig.json`
|
466
|
-
|
467
|
-
```json
|
468
|
-
{
|
469
|
-
"compilerOptions": {
|
470
|
-
"declaration": false,
|
471
|
-
"emitDecoratorMetadata": true,
|
472
|
-
"experimentalDecorators": true,
|
473
|
-
"lib": ["es6", "dom"],
|
474
|
-
"module": "es6",
|
475
|
-
"moduleResolution": "node",
|
476
|
-
"sourceMap": true,
|
477
|
-
"target": "es5",
|
478
|
-
"jsx": "react",
|
479
|
-
"noEmit": true
|
480
|
-
},
|
481
|
-
"exclude": ["**/*.spec.ts", "node_modules", "vendor", "public"],
|
482
|
-
"compileOnSave": false
|
483
|
-
}
|
484
|
-
```
|
485
|
-
|
486
|
-
For more information on React props hydration and Server-Side Rendering (SSR), see the article
|
487
|
-
[Rails/Webpacker React Integration Options](https://github.com/shakacode/react_on_rails/blob/master/docs/rails-webpacker-react-integration-options.md)
|
488
|
-
in the [ShakaCode/react_on_rails](https://github.com/shakacode/react_on_rails) repo.
|
489
|
-
|
490
448
|
#### Other frameworks
|
491
449
|
|
492
450
|
Please follow webpack integration guide for relevant framework or library,
|
@@ -524,6 +482,7 @@ const vueConfig = require('./rules/vue')
|
|
524
482
|
module.exports = merge(vueConfig, webpackConfig)
|
525
483
|
```
|
526
484
|
|
485
|
+
|
527
486
|
### Custom Rails environments
|
528
487
|
|
529
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.
|
@@ -544,8 +503,7 @@ staging:
|
|
544
503
|
public_output_path: packs-staging
|
545
504
|
```
|
546
505
|
|
547
|
-
|
548
|
-
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`.
|
549
507
|
|
550
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:
|
551
509
|
|
@@ -553,15 +511,13 @@ For example, the below command will compile assets in production mode but will u
|
|
553
511
|
RAILS_ENV=staging bundle exec rails assets:precompile
|
554
512
|
```
|
555
513
|
|
556
|
-
And, this will compile in development mode and load configuration for cucumber environment
|
557
|
-
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
|
558
515
|
|
559
516
|
```bash
|
560
517
|
RAILS_ENV=cucumber NODE_ENV=development bundle exec rails assets:precompile
|
561
518
|
```
|
562
519
|
|
563
|
-
Please note, binstubs compiles in development mode however rake tasks
|
564
|
-
compiles in production mode.
|
520
|
+
Please note, binstubs compiles in development mode however rake tasks compiles in production mode.
|
565
521
|
|
566
522
|
```bash
|
567
523
|
# Compiles in development mode unless NODE_ENV is specified, per the binstub source
|
@@ -600,19 +556,11 @@ Also, consult the [CHANGELOG](./CHANGELOG.md) for additional upgrade links.
|
|
600
556
|
|
601
557
|
## Paths
|
602
558
|
|
603
|
-
By default, Webpacker ships with simple conventions for where the JavaScript
|
604
|
-
app files and compiled webpack bundles will go in your Rails app.
|
605
|
-
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.
|
606
560
|
|
607
|
-
The configuration for what webpack is supposed to compile by default rests
|
608
|
-
on the convention that every file in `app/packs/entrypoints/*`**(default)**
|
609
|
-
or whatever path you set for `source_entry_path` in the `webpacker.yml` configuration
|
610
|
-
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
|
611
|
-
an entry file. As a rule of thumb, put all files you want to link in your views inside
|
612
|
-
"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`.
|
613
562
|
|
614
|
-
Suppose you want to change the source directory from `app/packs`
|
615
|
-
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:
|
616
564
|
|
617
565
|
```yml
|
618
566
|
# config/webpacker.yml
|
@@ -630,16 +578,11 @@ development:
|
|
630
578
|
port: 3035
|
631
579
|
```
|
632
580
|
|
633
|
-
If you have `hmr` turned to true, then the `stylesheet_pack_tag` generates no output,
|
634
|
-
as you will want to configure your styles to be inlined in your JavaScript for hot reloading.
|
635
|
-
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.
|
636
582
|
|
637
583
|
### Additional paths
|
638
584
|
|
639
|
-
If you are adding Webpacker to an existing app that has most of the assets inside
|
640
|
-
`app/assets` or inside an engine, and you want to share that
|
641
|
-
with webpack modules, you can use the `additional_paths`
|
642
|
-
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
|
643
586
|
add additional paths that webpack should look up when resolving modules:
|
644
587
|
|
645
588
|
```yml
|
@@ -654,12 +597,11 @@ import 'stylesheets/main'
|
|
654
597
|
import 'images/rails.png'
|
655
598
|
```
|
656
599
|
|
657
|
-
**Note:** Please be careful when adding paths here otherwise it
|
658
|
-
will make the compilation slow, consider adding specific paths instead of
|
659
|
-
whole parent directory if you just need to reference one or two modules
|
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
|
660
601
|
|
661
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.
|
662
603
|
|
604
|
+
|
663
605
|
## Deployment
|
664
606
|
|
665
607
|
Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which gets run whenever you run `assets:precompile`. If you are not using Sprockets, `webpacker:compile` is automatically aliased to `assets:precompile`. Similar to sprockets both rake tasks will compile packs in production mode but will use `RAILS_ENV` to load configuration from `config/webpacker.yml` (if available).
|
@@ -668,16 +610,19 @@ When compiling assets for production on a remote server, such as a continuous in
|
|
668
610
|
|
669
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.
|
670
612
|
|
613
|
+
|
671
614
|
## Troubleshooting
|
672
615
|
|
673
616
|
See the doc page for [Troubleshooting](./docs/troubleshooting.md).
|
674
617
|
|
618
|
+
|
675
619
|
## Contributing
|
676
620
|
|
677
621
|
[![Code Helpers](https://www.codetriage.com/rails/webpacker/badges/users.svg)](https://www.codetriage.com/rails/webpacker)
|
678
622
|
|
679
623
|
We encourage you to contribute to Webpacker! See [CONTRIBUTING](CONTRIBUTING.md) for guidelines about how to proceed.
|
680
624
|
|
625
|
+
|
681
626
|
## License
|
682
627
|
|
683
628
|
Webpacker is released under the [MIT License](https://opensource.org/licenses/MIT).
|