webpacker 5.1.1 → 5.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +8 -8
  3. data/.github/workflows/jest.yml +38 -0
  4. data/.github/workflows/js-lint.yml +39 -0
  5. data/.github/workflows/rubocop.yml +39 -0
  6. data/.github/workflows/ruby.yml +66 -0
  7. data/.node-version +1 -1
  8. data/.rubocop.yml +113 -13
  9. data/CHANGELOG.md +27 -3
  10. data/Gemfile.lock +112 -103
  11. data/README.md +11 -19
  12. data/docs/css.md +58 -3
  13. data/docs/integrations.md +1 -1
  14. data/docs/target.md +22 -0
  15. data/docs/testing.md +1 -1
  16. data/docs/troubleshooting.md +3 -1
  17. data/docs/typescript.md +44 -0
  18. data/docs/webpack-dev-server.md +1 -1
  19. data/lib/install/config/babel.config.js +1 -3
  20. data/lib/install/config/webpacker.yml +1 -1
  21. data/lib/install/template.rb +9 -1
  22. data/lib/install/typescript.rb +1 -1
  23. data/lib/tasks/webpacker/check_node.rake +1 -1
  24. data/lib/tasks/webpacker/check_yarn.rake +2 -3
  25. data/lib/tasks/webpacker/yarn_install.rake +7 -1
  26. data/lib/webpacker/commands.rb +1 -1
  27. data/lib/webpacker/compiler.rb +7 -2
  28. data/lib/webpacker/configuration.rb +27 -8
  29. data/lib/webpacker/dev_server_runner.rb +2 -2
  30. data/lib/webpacker/env.rb +5 -1
  31. data/lib/webpacker/helper.rb +25 -6
  32. data/lib/webpacker/runner.rb +1 -0
  33. data/lib/webpacker/version.rb +1 -1
  34. data/lib/webpacker/webpack_runner.rb +2 -2
  35. data/package.json +36 -36
  36. data/package/__tests__/config.js +12 -1
  37. data/package/__tests__/development.js +14 -1
  38. data/package/config.js +4 -1
  39. data/package/configPath.js +3 -0
  40. data/package/env.js +1 -2
  41. data/package/environments/__tests__/base.js +25 -8
  42. data/package/environments/base.js +5 -6
  43. data/package/environments/development.js +39 -33
  44. data/package/environments/production.js +1 -3
  45. data/package/rules/babel.js +11 -4
  46. data/package/rules/file.js +3 -2
  47. data/package/rules/node_modules.js +1 -3
  48. data/package/rules/sass.js +4 -1
  49. data/package/utils/helpers.js +1 -1
  50. data/test/compiler_test.rb +8 -3
  51. data/test/configuration_test.rb +8 -7
  52. data/test/dev_server_runner_test.rb +1 -1
  53. data/test/helper_test.rb +3 -0
  54. data/test/test_app/config/webpacker.yml +7 -1
  55. data/test/test_app/public/packs/manifest.json +1 -0
  56. data/test/webpack_runner_test.rb +1 -1
  57. data/webpacker.gemspec +1 -1
  58. data/yarn.lock +3497 -3628
  59. metadata +19 -13
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- webpacker (5.1.1)
4
+ webpacker (5.4.0)
5
5
  activesupport (>= 5.2)
6
6
  rack-proxy (>= 0.6.1)
7
7
  railties (>= 5.2)
@@ -10,150 +10,159 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- actioncable (6.0.1)
14
- actionpack (= 6.0.1)
13
+ actioncable (6.1.3.2)
14
+ actionpack (= 6.1.3.2)
15
+ activesupport (= 6.1.3.2)
15
16
  nio4r (~> 2.0)
16
17
  websocket-driver (>= 0.6.1)
17
- actionmailbox (6.0.1)
18
- actionpack (= 6.0.1)
19
- activejob (= 6.0.1)
20
- activerecord (= 6.0.1)
21
- activestorage (= 6.0.1)
22
- activesupport (= 6.0.1)
18
+ actionmailbox (6.1.3.2)
19
+ actionpack (= 6.1.3.2)
20
+ activejob (= 6.1.3.2)
21
+ activerecord (= 6.1.3.2)
22
+ activestorage (= 6.1.3.2)
23
+ activesupport (= 6.1.3.2)
23
24
  mail (>= 2.7.1)
24
- actionmailer (6.0.1)
25
- actionpack (= 6.0.1)
26
- actionview (= 6.0.1)
27
- activejob (= 6.0.1)
25
+ actionmailer (6.1.3.2)
26
+ actionpack (= 6.1.3.2)
27
+ actionview (= 6.1.3.2)
28
+ activejob (= 6.1.3.2)
29
+ activesupport (= 6.1.3.2)
28
30
  mail (~> 2.5, >= 2.5.4)
29
31
  rails-dom-testing (~> 2.0)
30
- actionpack (6.0.1)
31
- actionview (= 6.0.1)
32
- activesupport (= 6.0.1)
33
- rack (~> 2.0)
32
+ actionpack (6.1.3.2)
33
+ actionview (= 6.1.3.2)
34
+ activesupport (= 6.1.3.2)
35
+ rack (~> 2.0, >= 2.0.9)
34
36
  rack-test (>= 0.6.3)
35
37
  rails-dom-testing (~> 2.0)
36
38
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
37
- actiontext (6.0.1)
38
- actionpack (= 6.0.1)
39
- activerecord (= 6.0.1)
40
- activestorage (= 6.0.1)
41
- activesupport (= 6.0.1)
39
+ actiontext (6.1.3.2)
40
+ actionpack (= 6.1.3.2)
41
+ activerecord (= 6.1.3.2)
42
+ activestorage (= 6.1.3.2)
43
+ activesupport (= 6.1.3.2)
42
44
  nokogiri (>= 1.8.5)
43
- actionview (6.0.1)
44
- activesupport (= 6.0.1)
45
+ actionview (6.1.3.2)
46
+ activesupport (= 6.1.3.2)
45
47
  builder (~> 3.1)
46
48
  erubi (~> 1.4)
47
49
  rails-dom-testing (~> 2.0)
48
50
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
49
- activejob (6.0.1)
50
- activesupport (= 6.0.1)
51
+ activejob (6.1.3.2)
52
+ activesupport (= 6.1.3.2)
51
53
  globalid (>= 0.3.6)
52
- activemodel (6.0.1)
53
- activesupport (= 6.0.1)
54
- activerecord (6.0.1)
55
- activemodel (= 6.0.1)
56
- activesupport (= 6.0.1)
57
- activestorage (6.0.1)
58
- actionpack (= 6.0.1)
59
- activejob (= 6.0.1)
60
- activerecord (= 6.0.1)
61
- marcel (~> 0.3.1)
62
- activesupport (6.0.1)
54
+ activemodel (6.1.3.2)
55
+ activesupport (= 6.1.3.2)
56
+ activerecord (6.1.3.2)
57
+ activemodel (= 6.1.3.2)
58
+ activesupport (= 6.1.3.2)
59
+ activestorage (6.1.3.2)
60
+ actionpack (= 6.1.3.2)
61
+ activejob (= 6.1.3.2)
62
+ activerecord (= 6.1.3.2)
63
+ activesupport (= 6.1.3.2)
64
+ marcel (~> 1.0.0)
65
+ mini_mime (~> 1.0.2)
66
+ activesupport (6.1.3.2)
63
67
  concurrent-ruby (~> 1.0, >= 1.0.2)
64
- i18n (>= 0.7, < 2)
65
- minitest (~> 5.1)
66
- tzinfo (~> 1.1)
67
- zeitwerk (~> 2.2)
68
- ast (2.4.0)
69
- builder (3.2.3)
70
- byebug (11.0.1)
71
- concurrent-ruby (1.1.5)
72
- crass (1.0.5)
73
- erubi (1.9.0)
68
+ i18n (>= 1.6, < 2)
69
+ minitest (>= 5.1)
70
+ tzinfo (~> 2.0)
71
+ zeitwerk (~> 2.3)
72
+ ast (2.4.2)
73
+ builder (3.2.4)
74
+ byebug (11.1.3)
75
+ concurrent-ruby (1.1.8)
76
+ crass (1.0.6)
77
+ erubi (1.10.0)
74
78
  globalid (0.4.2)
75
79
  activesupport (>= 4.2.0)
76
- i18n (1.7.0)
80
+ i18n (1.8.10)
77
81
  concurrent-ruby (~> 1.0)
78
- jaro_winkler (1.5.4)
79
- loofah (2.3.1)
82
+ loofah (2.9.1)
80
83
  crass (~> 1.0.2)
81
84
  nokogiri (>= 1.5.9)
82
85
  mail (2.7.1)
83
86
  mini_mime (>= 0.1.1)
84
- marcel (0.3.3)
85
- mimemagic (~> 0.3.2)
86
- method_source (0.9.2)
87
- mimemagic (0.3.3)
88
- mini_mime (1.0.2)
89
- mini_portile2 (2.4.0)
90
- minitest (5.13.0)
91
- nio4r (2.5.2)
92
- nokogiri (1.10.8)
93
- mini_portile2 (~> 2.4.0)
94
- parallel (1.18.0)
95
- parser (2.6.5.0)
96
- ast (~> 2.4.0)
97
- rack (2.0.8)
87
+ marcel (1.0.1)
88
+ method_source (1.0.0)
89
+ mini_mime (1.0.3)
90
+ mini_portile2 (2.5.1)
91
+ minitest (5.14.4)
92
+ nio4r (2.5.7)
93
+ nokogiri (1.11.4)
94
+ mini_portile2 (~> 2.5.0)
95
+ racc (~> 1.4)
96
+ parallel (1.20.1)
97
+ parser (3.0.1.1)
98
+ ast (~> 2.4.1)
99
+ racc (1.5.2)
100
+ rack (2.2.3)
98
101
  rack-proxy (0.6.5)
99
102
  rack
100
103
  rack-test (1.1.0)
101
104
  rack (>= 1.0, < 3)
102
- rails (6.0.1)
103
- actioncable (= 6.0.1)
104
- actionmailbox (= 6.0.1)
105
- actionmailer (= 6.0.1)
106
- actionpack (= 6.0.1)
107
- actiontext (= 6.0.1)
108
- actionview (= 6.0.1)
109
- activejob (= 6.0.1)
110
- activemodel (= 6.0.1)
111
- activerecord (= 6.0.1)
112
- activestorage (= 6.0.1)
113
- activesupport (= 6.0.1)
114
- bundler (>= 1.3.0)
115
- railties (= 6.0.1)
105
+ rails (6.1.3.2)
106
+ actioncable (= 6.1.3.2)
107
+ actionmailbox (= 6.1.3.2)
108
+ actionmailer (= 6.1.3.2)
109
+ actionpack (= 6.1.3.2)
110
+ actiontext (= 6.1.3.2)
111
+ actionview (= 6.1.3.2)
112
+ activejob (= 6.1.3.2)
113
+ activemodel (= 6.1.3.2)
114
+ activerecord (= 6.1.3.2)
115
+ activestorage (= 6.1.3.2)
116
+ activesupport (= 6.1.3.2)
117
+ bundler (>= 1.15.0)
118
+ railties (= 6.1.3.2)
116
119
  sprockets-rails (>= 2.0.0)
117
120
  rails-dom-testing (2.0.3)
118
121
  activesupport (>= 4.2.0)
119
122
  nokogiri (>= 1.6)
120
123
  rails-html-sanitizer (1.3.0)
121
124
  loofah (~> 2.3)
122
- railties (6.0.1)
123
- actionpack (= 6.0.1)
124
- activesupport (= 6.0.1)
125
+ railties (6.1.3.2)
126
+ actionpack (= 6.1.3.2)
127
+ activesupport (= 6.1.3.2)
125
128
  method_source
126
129
  rake (>= 0.8.7)
127
- thor (>= 0.20.3, < 2.0)
130
+ thor (~> 1.0)
128
131
  rainbow (3.0.0)
129
- rake (13.0.0)
130
- rubocop (0.68.1)
131
- jaro_winkler (~> 1.5.1)
132
+ rake (13.0.3)
133
+ regexp_parser (2.1.1)
134
+ rexml (3.2.5)
135
+ rubocop (0.93.1)
132
136
  parallel (~> 1.10)
133
- parser (>= 2.5, != 2.5.1.1)
137
+ parser (>= 2.7.1.5)
134
138
  rainbow (>= 2.2.2, < 4.0)
139
+ regexp_parser (>= 1.8)
140
+ rexml
141
+ rubocop-ast (>= 0.6.0)
135
142
  ruby-progressbar (~> 1.7)
136
- unicode-display_width (>= 1.4.0, < 1.6)
137
- rubocop-performance (1.3.0)
138
- rubocop (>= 0.68.0)
139
- ruby-progressbar (1.10.1)
140
- semantic_range (2.3.0)
141
- sprockets (4.0.0)
143
+ unicode-display_width (>= 1.4.0, < 2.0)
144
+ rubocop-ast (1.5.0)
145
+ parser (>= 3.0.1.1)
146
+ rubocop-performance (1.10.2)
147
+ rubocop (>= 0.90.0, < 2.0)
148
+ rubocop-ast (>= 0.4.0)
149
+ ruby-progressbar (1.11.0)
150
+ semantic_range (3.0.0)
151
+ sprockets (4.0.2)
142
152
  concurrent-ruby (~> 1.0)
143
153
  rack (> 1, < 3)
144
- sprockets-rails (3.2.1)
154
+ sprockets-rails (3.2.2)
145
155
  actionpack (>= 4.0)
146
156
  activesupport (>= 4.0)
147
157
  sprockets (>= 3.0.0)
148
- thor (0.20.3)
149
- thread_safe (0.3.6)
150
- tzinfo (1.2.5)
151
- thread_safe (~> 0.1)
152
- unicode-display_width (1.5.0)
153
- websocket-driver (0.7.1)
158
+ thor (1.1.0)
159
+ tzinfo (2.0.4)
160
+ concurrent-ruby (~> 1.0)
161
+ unicode-display_width (1.7.0)
162
+ websocket-driver (0.7.3)
154
163
  websocket-extensions (>= 0.1.0)
155
- websocket-extensions (0.1.4)
156
- zeitwerk (2.2.1)
164
+ websocket-extensions (0.1.5)
165
+ zeitwerk (2.4.2)
157
166
 
158
167
  PLATFORMS
159
168
  ruby
@@ -165,10 +174,10 @@ DEPENDENCIES
165
174
  rack-proxy
166
175
  rails
167
176
  rake (>= 11.1)
168
- rubocop (< 0.69)
177
+ rubocop (= 0.93.1)
169
178
  rubocop-performance
170
179
  semantic_range
171
180
  webpacker!
172
181
 
173
182
  BUNDLED WITH
174
- 1.17.3
183
+ 2.2.3
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Webpacker
2
2
 
3
3
  [![Build Status](https://travis-ci.org/rails/webpacker.svg?branch=master)](https://travis-ci.org/rails/webpacker)
4
- [![node.js](https://img.shields.io/badge/node-%3E%3D%2010.13.0-brightgreen.svg)](https://www.npmjs.com/package/@rails/webpacker)
4
+ [![node.js](https://img.shields.io/badge/node-%3E%3D%2010.17.0-brightgreen.svg)](https://www.npmjs.com/package/@rails/webpacker)
5
5
  [![Gem](https://img.shields.io/gem/v/webpacker.svg)](https://rubygems.org/gems/webpacker)
6
6
 
7
7
  Webpacker makes it easy to use the JavaScript pre-processor and bundler
@@ -35,6 +35,7 @@ in which case you may not even need the asset pipeline. This is mostly relevant
35
35
  - [Elm](./docs/integrations.md#elm)
36
36
  - [Stimulus](./docs/integrations.md#stimulus)
37
37
  - [Svelte](./docs/integrations.md#svelte)
38
+ - [Typescript](./docs/typescript.md)
38
39
  - [CoffeeScript](./docs/integrations.md#coffeescript)
39
40
  - [Erb](./docs/integrations.md#erb)
40
41
  - [Paths](#paths)
@@ -51,7 +52,7 @@ in which case you may not even need the asset pipeline. This is mostly relevant
51
52
 
52
53
  - Ruby 2.4+
53
54
  - Rails 5.2+
54
- - Node.js 10.13.0+
55
+ - Node.js 10.17.0+
55
56
  - Yarn 1.x+
56
57
 
57
58
  ## Features
@@ -121,8 +122,11 @@ app/javascript:
121
122
  ├── packs:
122
123
  │ # only webpack entry files here
123
124
  │ └── application.js
124
- └── src:
125
125
  │ └── application.css
126
+ └── src:
127
+ │ └── my_component.js
128
+ └── stylesheets:
129
+ │ └── my_styles.css
126
130
  └── images:
127
131
  └── logo.svg
128
132
  ```
@@ -318,7 +322,7 @@ Included install integrations:
318
322
  - [Svelte](./docs/integrations.md#Svelte)
319
323
  - [Stimulus](./docs/integrations.md#Stimulus)
320
324
  - [CoffeeScript](./docs/integrations.md#CoffeeScript)
321
- - [Typescript](./docs/integrations.md)
325
+ - [Typescript](./docs/typescript.md)
322
326
  - [Erb](./docs/integrations.md#Erb)
323
327
 
324
328
  See [Integrations](./docs/integrations.md) for further details.
@@ -362,12 +366,12 @@ If you have `hmr` turned to true, then the `stylesheet_pack_tag` generates no ou
362
366
 
363
367
  If you are adding Webpacker to an existing app that has most of the assets inside
364
368
  `app/assets` or inside an engine, and you want to share that
365
- with webpack modules, you can use the `resolved_paths`
369
+ with webpack modules, you can use the `additional_paths`
366
370
  option available in `config/webpacker.yml`. This lets you
367
371
  add additional paths that webpack should lookup when resolving modules:
368
372
 
369
373
  ```yml
370
- resolved_paths: ['app/assets']
374
+ additional_paths: ['app/assets']
371
375
  ```
372
376
 
373
377
  You can then import these items inside your modules like so:
@@ -382,18 +386,6 @@ import 'images/rails.png'
382
386
  will make the compilation slow, consider adding specific paths instead of
383
387
  whole parent directory if you just need to reference one or two modules
384
388
 
385
- ### Watched
386
-
387
- By default, the lazy compilation is cached until a file is changed under your
388
- tracked paths. You can configure which paths are tracked
389
- by adding new paths to `watched_paths` array. This is much like Rails' `autoload_paths`:
390
-
391
- ```rb
392
- # config/initializers/webpacker.rb
393
- # or config/application.rb
394
- Webpacker::Compiler.watched_paths << 'bower_components'
395
- ```
396
-
397
389
  ## Deployment
398
390
 
399
391
  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).
@@ -407,7 +399,7 @@ When compiling assets for production on a remote server, such as a continuous in
407
399
  - [Webpack-dev-server](./docs/webpack-dev-server.md)
408
400
  - [Environment Variables](./docs/env.md)
409
401
  - [Folder Structure](./docs/folder-structure.md)
410
- - [Assets](./docs/assets.md) - [CSS, Sass and SCSS](./docs/css.md) - [ES6](./docs/es6.md)
402
+ - [Assets](./docs/assets.md) - [CSS, Sass and SCSS](./docs/css.md) - [ES6](./docs/es6.md), [Target browsers](./docs/target.md)
411
403
  - [Props](./docs/props.md)
412
404
  - [Typescript](./docs/typescript.md)
413
405
  - [Yarn](./docs/yarn.md)
data/docs/css.md CHANGED
@@ -6,7 +6,7 @@ Webpacker supports importing CSS, Sass and SCSS files directly into your JavaScr
6
6
  Importing and loading styles is a two step process:
7
7
 
8
8
  1. You need to tell webpack which file(s) it has to compile and know how to load
9
-
9
+
10
10
  When you do `import '../scss/application.scss'`, you're telling webpack to include `application.scss` in the build. This does not mean it's going to be compiled into your javascript, only that webpack now compiles and knows how to load this file. (How that file compilation is handled is depending on how your loaders (`css-loader`, `sass-loader`, `file-loader`, etc.) are configured.)
11
11
 
12
12
  2. You need to load those files in your views
@@ -18,6 +18,51 @@ Importing and loading styles is a two step process:
18
18
 
19
19
  ## Import global styles into your JS app
20
20
 
21
+ ### Importing CSS as a multi-file pack (Webpacker v5)
22
+
23
+ When you add a CSS/SCSS/SASS file to `app/javascript/packs/` directory, make sure to use the same pack name as its complementary JavaScript pack, e.g. `application.js` and `application.css`. By Webpacker convention (as of Webpacker v5), this will bundle `application.js` and `application.scss` as part of the same entry point (also described as [a multi-file entry point in the webpack docs](https://webpack.js.org/concepts/entry-points/#single-entry-shorthand-syntax)). With this approach, you can avoid importing CSS from JS, if desired.
24
+
25
+ ```
26
+ app/
27
+ javascript/
28
+ packs/
29
+ application.js
30
+ application.scss
31
+ ```
32
+
33
+ ### Importing CSS from CSS
34
+
35
+ You can import additional CSS/SCSS/SASS files from within a CSS file:
36
+
37
+ ```
38
+ app/
39
+ javascript/
40
+ stylesheets/
41
+ application.scss
42
+ posts.scss
43
+ comments.scss
44
+ ```
45
+
46
+ ```css
47
+ /* app/javascript/stylesheets/application.scss */
48
+
49
+ @import './posts';
50
+ @import './comments';
51
+ ```
52
+
53
+ ### Importing CSS provided by an NPM package from SCSS/CSS
54
+
55
+ Given your application installs an NPM package that provides CSS, such as `flatpickr`, you can import the CSS file(s) by path from the package directory within `node_modules/`:
56
+
57
+ ```js
58
+ /* app/javascript/stylesheets/application.scss */
59
+
60
+ @import "flatpickr/dist/flatpickr.css"
61
+ ```
62
+
63
+
64
+ ### Importing CSS from JS
65
+
21
66
  ```sass
22
67
  // app/javascript/hello_react/styles/hello-react.sass
23
68
 
@@ -42,6 +87,16 @@ const Hello = props => (
42
87
  )
43
88
  ```
44
89
 
90
+ ### Importing CSS provided by an NPM package from JS
91
+
92
+ Given your application installs an NPM package that provides CSS, such as `flatpickr`, you can import the CSS file(s) by path from the package directory within `node_modules/`. This is an alternative to importing from within a CSS file, as above:
93
+
94
+ ```js
95
+ // app/javascript/packs/application.js
96
+
97
+ import "flatpickr/dist/flatpickr.css"
98
+ ```
99
+
45
100
  ## Import scoped styles into your JS app
46
101
 
47
102
  Stylesheets that end with `.module.*` are treated as [CSS Modules](https://github.com/css-modules/css-modules).
@@ -147,14 +202,14 @@ You can use Yarn to add bootstrap or any other modules available on npm:
147
202
  yarn add bootstrap
148
203
  ```
149
204
 
150
- Import Bootstrap and theme (optional) CSS in your app/javascript/packs/app.js file:
205
+ Import Bootstrap and theme (optional) CSS in your app/javascript/packs/application.js file:
151
206
 
152
207
  ```js
153
208
  import 'bootstrap/dist/css/bootstrap'
154
209
  import 'bootstrap/dist/css/bootstrap-theme'
155
210
  ```
156
211
 
157
- Or in your app/javascript/app.sass file:
212
+ Or in your app/javascript/packs/application.sass file:
158
213
 
159
214
  ```sass
160
215
  // ~ to tell that this is not a relative import