webpacker 5.0.1 → 5.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) 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 +32 -3
  10. data/Gemfile.lock +112 -103
  11. data/README.md +20 -41
  12. data/docs/css.md +58 -3
  13. data/docs/env.md +0 -2
  14. data/docs/integrations.md +1 -1
  15. data/docs/target.md +22 -0
  16. data/docs/testing.md +2 -3
  17. data/docs/troubleshooting.md +3 -1
  18. data/docs/typescript.md +92 -27
  19. data/docs/webpack-dev-server.md +1 -1
  20. data/lib/install/config/babel.config.js +1 -3
  21. data/lib/install/config/webpacker.yml +1 -5
  22. data/lib/install/examples/react/tsconfig.json +2 -1
  23. data/lib/install/examples/typescript/tsconfig.json +2 -1
  24. data/lib/install/template.rb +9 -1
  25. data/lib/install/typescript.rb +6 -13
  26. data/lib/tasks/webpacker/check_node.rake +1 -1
  27. data/lib/tasks/webpacker/check_yarn.rake +2 -3
  28. data/lib/tasks/webpacker/yarn_install.rake +7 -1
  29. data/lib/webpacker/compiler.rb +9 -5
  30. data/lib/webpacker/configuration.rb +13 -9
  31. data/lib/webpacker/dev_server_proxy.rb +3 -1
  32. data/lib/webpacker/dev_server_runner.rb +2 -2
  33. data/lib/webpacker/helper.rb +37 -18
  34. data/lib/webpacker/railtie.rb +0 -43
  35. data/lib/webpacker/runner.rb +1 -0
  36. data/lib/webpacker/version.rb +1 -1
  37. data/lib/webpacker/webpack_runner.rb +2 -2
  38. data/package.json +35 -35
  39. data/package/__tests__/config.js +12 -1
  40. data/package/__tests__/dev_server.js +2 -0
  41. data/package/__tests__/development.js +14 -1
  42. data/package/config.js +4 -1
  43. data/package/configPath.js +3 -0
  44. data/package/dev_server.js +1 -1
  45. data/package/env.js +1 -2
  46. data/package/environments/__tests__/base.js +25 -8
  47. data/package/environments/base.js +5 -6
  48. data/package/environments/development.js +39 -33
  49. data/package/environments/production.js +1 -3
  50. data/package/rules/babel.js +12 -5
  51. data/package/rules/file.js +3 -2
  52. data/package/rules/node_modules.js +1 -3
  53. data/package/rules/sass.js +4 -1
  54. data/package/utils/helpers.js +1 -1
  55. data/test/compiler_test.rb +8 -3
  56. data/test/configuration_test.rb +8 -7
  57. data/test/dev_server_runner_test.rb +1 -1
  58. data/test/helper_test.rb +3 -0
  59. data/test/test_app/config/application.rb +0 -1
  60. data/test/test_app/config/webpacker.yml +7 -1
  61. data/test/test_app/public/packs/manifest.json +1 -0
  62. data/test/webpack_runner_test.rb +1 -1
  63. data/webpacker.gemspec +1 -1
  64. data/yarn.lock +3296 -3594
  65. metadata +19 -14
  66. data/lib/install/loaders/typescript.js +0 -11
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- webpacker (5.0.1)
4
+ webpacker (5.2.2)
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.1)
14
+ actionpack (= 6.1.3.1)
15
+ activesupport (= 6.1.3.1)
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.1)
19
+ actionpack (= 6.1.3.1)
20
+ activejob (= 6.1.3.1)
21
+ activerecord (= 6.1.3.1)
22
+ activestorage (= 6.1.3.1)
23
+ activesupport (= 6.1.3.1)
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.1)
26
+ actionpack (= 6.1.3.1)
27
+ actionview (= 6.1.3.1)
28
+ activejob (= 6.1.3.1)
29
+ activesupport (= 6.1.3.1)
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.1)
33
+ actionview (= 6.1.3.1)
34
+ activesupport (= 6.1.3.1)
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.1)
40
+ actionpack (= 6.1.3.1)
41
+ activerecord (= 6.1.3.1)
42
+ activestorage (= 6.1.3.1)
43
+ activesupport (= 6.1.3.1)
42
44
  nokogiri (>= 1.8.5)
43
- actionview (6.0.1)
44
- activesupport (= 6.0.1)
45
+ actionview (6.1.3.1)
46
+ activesupport (= 6.1.3.1)
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.1)
52
+ activesupport (= 6.1.3.1)
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.1)
55
+ activesupport (= 6.1.3.1)
56
+ activerecord (6.1.3.1)
57
+ activemodel (= 6.1.3.1)
58
+ activesupport (= 6.1.3.1)
59
+ activestorage (6.1.3.1)
60
+ actionpack (= 6.1.3.1)
61
+ activejob (= 6.1.3.1)
62
+ activerecord (= 6.1.3.1)
63
+ activesupport (= 6.1.3.1)
64
+ marcel (~> 1.0.0)
65
+ mini_mime (~> 1.0.2)
66
+ activesupport (6.1.3.1)
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.0)
91
+ minitest (5.14.4)
92
+ nio4r (2.5.7)
93
+ nokogiri (1.11.3)
94
+ mini_portile2 (~> 2.5.0)
95
+ racc (~> 1.4)
96
+ parallel (1.20.1)
97
+ parser (3.0.1.0)
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.1)
106
+ actioncable (= 6.1.3.1)
107
+ actionmailbox (= 6.1.3.1)
108
+ actionmailer (= 6.1.3.1)
109
+ actionpack (= 6.1.3.1)
110
+ actiontext (= 6.1.3.1)
111
+ actionview (= 6.1.3.1)
112
+ activejob (= 6.1.3.1)
113
+ activemodel (= 6.1.3.1)
114
+ activerecord (= 6.1.3.1)
115
+ activestorage (= 6.1.3.1)
116
+ activesupport (= 6.1.3.1)
117
+ bundler (>= 1.15.0)
118
+ railties (= 6.1.3.1)
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.1)
126
+ actionpack (= 6.1.3.1)
127
+ activesupport (= 6.1.3.1)
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.4.1)
145
+ parser (>= 2.7.1.5)
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
@@ -28,7 +28,6 @@ in which case you may not even need the asset pipeline. This is mostly relevant
28
28
  - [Webpack Configuration](#webpack-configuration)
29
29
  - [Custom Rails environments](#custom-rails-environments)
30
30
  - [Upgrading](#upgrading)
31
- - [Yarn Integrity](#yarn-integrity)
32
31
  - [Integrations](#integrations)
33
32
  - [React](./docs/integrations.md#react)
34
33
  - [Angular with TypeScript](./docs/integrations.md#angular-with-typescript)
@@ -36,6 +35,7 @@ in which case you may not even need the asset pipeline. This is mostly relevant
36
35
  - [Elm](./docs/integrations.md#elm)
37
36
  - [Stimulus](./docs/integrations.md#stimulus)
38
37
  - [Svelte](./docs/integrations.md#svelte)
38
+ - [Typescript](./docs/typescript.md)
39
39
  - [CoffeeScript](./docs/integrations.md#coffeescript)
40
40
  - [Erb](./docs/integrations.md#erb)
41
41
  - [Paths](#paths)
@@ -52,7 +52,7 @@ in which case you may not even need the asset pipeline. This is mostly relevant
52
52
 
53
53
  - Ruby 2.4+
54
54
  - Rails 5.2+
55
- - Node.js 10.13.0+
55
+ - Node.js 10.17.0+
56
56
  - Yarn 1.x+
57
57
 
58
58
  ## Features
@@ -83,7 +83,7 @@ Or add it to your `Gemfile`:
83
83
 
84
84
  ```ruby
85
85
  # Gemfile
86
- gem 'webpacker', '~> 4.x'
86
+ gem 'webpacker', '~> 5.x'
87
87
 
88
88
  # OR if you prefer to use master
89
89
  gem 'webpacker', git: 'https://github.com/rails/webpacker.git'
@@ -107,6 +107,12 @@ Optional: To fix ["unmet peer dependency" warnings](https://github.com/rails/web
107
107
  yarn upgrade
108
108
  ```
109
109
 
110
+ 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:
111
+
112
+ ```bash
113
+ yarn install
114
+ ```
115
+
110
116
  ### Usage
111
117
 
112
118
  Once installed, you can start writing modern ES6-flavored JavaScript apps right away:
@@ -116,8 +122,11 @@ app/javascript:
116
122
  ├── packs:
117
123
  │ # only webpack entry files here
118
124
  │ └── application.js
119
- └── src:
120
125
  │ └── application.css
126
+ └── src:
127
+ │ └── my_component.js
128
+ └── stylesheets:
129
+ │ └── my_styles.css
121
130
  └── images:
122
131
  └── logo.svg
123
132
  ```
@@ -300,26 +309,6 @@ yarn upgrade webpack-dev-server --latest
300
309
  yarn add @rails/webpacker@next
301
310
  ```
302
311
 
303
- ### Yarn Integrity
304
-
305
- By default, in development, webpacker runs a yarn integrity check to ensure that all local JavaScript packages are up-to-date. This is similar to what bundler does currently in Rails, but for JavaScript packages. If your system is out of date, then Rails will not initialize. You will be asked to upgrade your local JavaScript packages by running `yarn install`.
306
-
307
- To turn off this option, you will need to change the default setting in `config/webpacker.yml`:
308
-
309
- ```yaml
310
- # config/webpacker.yml
311
- development:
312
- ...
313
- # Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
314
- check_yarn_integrity: false
315
- ```
316
-
317
- You may also turn on this feature by adding the config option for any Rails environment in `config/webpacker.yml`:
318
-
319
- ```yaml
320
- check_yarn_integrity: true
321
- ```
322
-
323
312
  ## Integrations
324
313
 
325
314
  Webpacker ships with basic out-of-the-box integration. You can see a list of available commands/tasks by running `bundle exec rails webpacker`.
@@ -333,7 +322,7 @@ Included install integrations:
333
322
  - [Svelte](./docs/integrations.md#Svelte)
334
323
  - [Stimulus](./docs/integrations.md#Stimulus)
335
324
  - [CoffeeScript](./docs/integrations.md#CoffeeScript)
336
- - [Typescript](./docs/integrations.md)
325
+ - [Typescript](./docs/typescript.md)
337
326
  - [Erb](./docs/integrations.md#Erb)
338
327
 
339
328
  See [Integrations](./docs/integrations.md) for further details.
@@ -377,12 +366,12 @@ If you have `hmr` turned to true, then the `stylesheet_pack_tag` generates no ou
377
366
 
378
367
  If you are adding Webpacker to an existing app that has most of the assets inside
379
368
  `app/assets` or inside an engine, and you want to share that
380
- with webpack modules, you can use the `resolved_paths`
369
+ with webpack modules, you can use the `additional_paths`
381
370
  option available in `config/webpacker.yml`. This lets you
382
371
  add additional paths that webpack should lookup when resolving modules:
383
372
 
384
373
  ```yml
385
- resolved_paths: ['app/assets']
374
+ additional_paths: ['app/assets']
386
375
  ```
387
376
 
388
377
  You can then import these items inside your modules like so:
@@ -397,22 +386,12 @@ import 'images/rails.png'
397
386
  will make the compilation slow, consider adding specific paths instead of
398
387
  whole parent directory if you just need to reference one or two modules
399
388
 
400
- ### Watched
401
-
402
- By default, the lazy compilation is cached until a file is changed under your
403
- tracked paths. You can configure which paths are tracked
404
- by adding new paths to `watched_paths` array. This is much like Rails' `autoload_paths`:
405
-
406
- ```rb
407
- # config/initializers/webpacker.rb
408
- # or config/application.rb
409
- Webpacker::Compiler.watched_paths << 'bower_components'
410
- ```
411
-
412
389
  ## Deployment
413
390
 
414
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).
415
392
 
393
+ When compiling assets for production on a remote server, such as a continuous integration environment, it's recommended to use `yarn install --frozen-lockfile` to install NPM packages on the remote host to ensure that the installed packages match the `yarn.lock` file.
394
+
416
395
  ## Docs
417
396
 
418
397
  - [Development](https://github.com/rails/webpacker#development)
@@ -420,7 +399,7 @@ Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which
420
399
  - [Webpack-dev-server](./docs/webpack-dev-server.md)
421
400
  - [Environment Variables](./docs/env.md)
422
401
  - [Folder Structure](./docs/folder-structure.md)
423
- - [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)
424
403
  - [Props](./docs/props.md)
425
404
  - [Typescript](./docs/typescript.md)
426
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