webpacker 3.2.2 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -1
  3. data/Gemfile.lock +38 -38
  4. data/README.md +48 -49
  5. data/docs/css.md +31 -1
  6. data/docs/docker.md +1 -1
  7. data/docs/typescript.md +36 -1
  8. data/{exe → lib/install/bin}/webpack +7 -0
  9. data/{exe → lib/install/bin}/webpack-dev-server +7 -0
  10. data/lib/install/binstubs.rb +4 -0
  11. data/lib/install/config/webpacker.yml +3 -0
  12. data/lib/install/loaders/erb.js +1 -1
  13. data/lib/install/template.rb +1 -2
  14. data/lib/install/typescript.rb +1 -1
  15. data/lib/tasks/webpacker.rake +1 -0
  16. data/lib/tasks/webpacker/binstubs.rake +12 -0
  17. data/lib/tasks/webpacker/check_binstubs.rake +1 -1
  18. data/lib/webpacker.rb +1 -0
  19. data/lib/webpacker/compiler.rb +4 -2
  20. data/lib/webpacker/dev_server_runner.rb +1 -1
  21. data/lib/webpacker/env.rb +39 -0
  22. data/lib/webpacker/instance.rb +1 -12
  23. data/lib/webpacker/version.rb +1 -1
  24. data/package.json +2 -2
  25. data/package/__tests__/config.js +7 -4
  26. data/package/__tests__/dev_server.js +26 -0
  27. data/package/__tests__/env.js +28 -0
  28. data/package/__tests__/index.js +31 -0
  29. data/package/config.js +14 -30
  30. data/package/config_types/__tests__/config_list.js +0 -5
  31. data/package/config_types/config_list.js +0 -9
  32. data/package/dev_server.js +23 -0
  33. data/package/env.js +23 -0
  34. data/package/{__tests__/environment.js → environments/__tests__/base.js} +6 -6
  35. data/package/{environment.js → environments/base.js} +4 -4
  36. data/package/environments/development.js +4 -3
  37. data/package/environments/production.js +31 -25
  38. data/package/environments/test.js +2 -2
  39. data/package/index.js +10 -6
  40. data/package/rules/babel.js +8 -6
  41. data/package/rules/css.js +2 -38
  42. data/package/rules/file.js +9 -7
  43. data/package/rules/index.js +4 -0
  44. data/package/rules/module.css.js +3 -0
  45. data/package/rules/module.sass.js +8 -0
  46. data/package/rules/sass.js +5 -12
  47. data/package/utils/__tests__/get_style_rule.js +36 -0
  48. data/package/utils/get_style_rule.js +62 -0
  49. data/package/utils/helpers.js +17 -3
  50. data/test/env_test.rb +19 -0
  51. data/test/test_app/bin/webpack +15 -0
  52. data/test/test_app/bin/webpack-dev-server +15 -0
  53. data/test/test_app/config/webpacker.yml +3 -0
  54. data/test/test_helper.rb +3 -1
  55. data/webpacker.gemspec +0 -2
  56. data/yarn.lock +8 -4
  57. metadata +26 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c15a75f6c29cc05aae6839309adee7e0db2b51ef63976992e03b1d684e703b70
4
- data.tar.gz: c02f95838b9f7ca24c178053eeae3eed75523c72a17276e18a1b0b93b4be90c1
3
+ metadata.gz: c8a4af458838278327cdb33c8e8823c18b74b3c65346b8c15340cf2c2791d3b9
4
+ data.tar.gz: 447be8bfef3508fd9fdd7757b8e89c3dd78c09bf0f01b8280dbeb1452ea2cfc8
5
5
  SHA512:
6
- metadata.gz: 79e537a4b5ef7e67da86b59cf3a74c7182b79cd3787285fe06032b2a2d2c0a5fba8b35961caba36e125ffc65d17641eb331fe2d63baee59724efc9e4c0d849da
7
- data.tar.gz: 2905386f28390de59651c450c08cad42bcaadc35e2e59ff92ee7e310c9d85aeadf2a208f4634d29896fb749e4e4a1ac3e4fd28a80905315acd6da0d43067c2d5
6
+ metadata.gz: f66b910cd05928a6ef6a7fd6ca9832297207dcb4776ef838518f962ebaf82b0b49e9e7e7db26dd6ce7ffd90eca6904cc91efa3619c76014d09bf4e47cb4389a1
7
+ data.tar.gz: 2779a7c38d3b3130e2c4cd386181d0e2a3b73480cc61d343104ad5a525eb25d79fb1e6b5728c3a51b27acf233b9b7ef08232e56017a47dc04257a85bd6da460d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  **Please note that Webpacker 3.1.0 and 3.1.1 has some serious bugs so please consider using either 3.0.2 or 3.2.0**
2
2
 
3
+ ## [3.3.0] - 2018-03-03
4
+
5
+ ### Added
6
+
7
+ - Separate task for installing/updating binstubs
8
+ - CSS modules support [#1248](https://github.com/rails/webpacker/pull/1248)
9
+ - Pass `relative_url_root` to webpacker config [#1236](https://github.com/rails/webpacker/pull/1236)
10
+
11
+ ### Breaking changes
12
+
13
+ - Fixes #1281 by installing binstubs only as local executables. To upgrade:
14
+
15
+ ```
16
+ bundle exec rails webpacker:binstubs
17
+ ```
18
+
19
+ ### Fixed
20
+ - Limit ts-loader to 3.5.0 until webpack 4 support [#1308](https://github.com/rails/webpacker/pull/1308)
21
+ - Custom env support [#1304](https://github.com/rails/webpacker/pull/1304)
22
+
3
23
  ## [3.2.2] - 2018-02-11
4
24
 
5
25
  ### Added
@@ -12,7 +32,7 @@ bundle exec rails webpacker:install:stimulus
12
32
 
13
33
  - Upgrade gems and npm packages [#1254](https://github.com/rails/webpacker/pull/1254)
14
34
 
15
- And, bunch of bug fixes [See changes](https://github.com/rails/webpacker/compare/v3.2.1...3.2.2)
35
+ And, bunch of bug fixes [See changes](https://github.com/rails/webpacker/compare/v3.2.1...v3.2.2)
16
36
 
17
37
  ## [3.2.1] - 2018-01-21
18
38
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- webpacker (3.2.2)
4
+ webpacker (3.3.0)
5
5
  activesupport (>= 4.2)
6
6
  rack-proxy (>= 0.6.1)
7
7
  railties (>= 4.2)
@@ -9,39 +9,39 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actioncable (5.1.4)
13
- actionpack (= 5.1.4)
12
+ actioncable (5.1.5)
13
+ actionpack (= 5.1.5)
14
14
  nio4r (~> 2.0)
15
15
  websocket-driver (~> 0.6.1)
16
- actionmailer (5.1.4)
17
- actionpack (= 5.1.4)
18
- actionview (= 5.1.4)
19
- activejob (= 5.1.4)
16
+ actionmailer (5.1.5)
17
+ actionpack (= 5.1.5)
18
+ actionview (= 5.1.5)
19
+ activejob (= 5.1.5)
20
20
  mail (~> 2.5, >= 2.5.4)
21
21
  rails-dom-testing (~> 2.0)
22
- actionpack (5.1.4)
23
- actionview (= 5.1.4)
24
- activesupport (= 5.1.4)
22
+ actionpack (5.1.5)
23
+ actionview (= 5.1.5)
24
+ activesupport (= 5.1.5)
25
25
  rack (~> 2.0)
26
26
  rack-test (>= 0.6.3)
27
27
  rails-dom-testing (~> 2.0)
28
28
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
29
- actionview (5.1.4)
30
- activesupport (= 5.1.4)
29
+ actionview (5.1.5)
30
+ activesupport (= 5.1.5)
31
31
  builder (~> 3.1)
32
32
  erubi (~> 1.4)
33
33
  rails-dom-testing (~> 2.0)
34
34
  rails-html-sanitizer (~> 1.0, >= 1.0.3)
35
- activejob (5.1.4)
36
- activesupport (= 5.1.4)
35
+ activejob (5.1.5)
36
+ activesupport (= 5.1.5)
37
37
  globalid (>= 0.3.6)
38
- activemodel (5.1.4)
39
- activesupport (= 5.1.4)
40
- activerecord (5.1.4)
41
- activemodel (= 5.1.4)
42
- activesupport (= 5.1.4)
38
+ activemodel (5.1.5)
39
+ activesupport (= 5.1.5)
40
+ activerecord (5.1.5)
41
+ activemodel (= 5.1.5)
42
+ activesupport (= 5.1.5)
43
43
  arel (~> 8.0)
44
- activesupport (5.1.4)
44
+ activesupport (5.1.5)
45
45
  concurrent-ruby (~> 1.0, >= 1.0.2)
46
46
  i18n (~> 0.7)
47
47
  minitest (~> 5.1)
@@ -55,9 +55,9 @@ GEM
55
55
  erubi (1.7.0)
56
56
  globalid (0.4.1)
57
57
  activesupport (>= 4.2.0)
58
- i18n (0.9.3)
58
+ i18n (0.9.5)
59
59
  concurrent-ruby (~> 1.0)
60
- loofah (2.1.1)
60
+ loofah (2.2.0)
61
61
  crass (~> 1.0.2)
62
62
  nokogiri (>= 1.5.9)
63
63
  mail (2.7.0)
@@ -70,34 +70,34 @@ GEM
70
70
  nokogiri (1.8.2)
71
71
  mini_portile2 (~> 2.3.0)
72
72
  parallel (1.12.1)
73
- parser (2.4.0.2)
74
- ast (~> 2.3)
73
+ parser (2.5.0.2)
74
+ ast (~> 2.4.0)
75
75
  powerpack (0.1.1)
76
76
  rack (2.0.4)
77
77
  rack-proxy (0.6.3)
78
78
  rack
79
- rack-test (0.8.2)
79
+ rack-test (0.8.3)
80
80
  rack (>= 1.0, < 3)
81
- rails (5.1.4)
82
- actioncable (= 5.1.4)
83
- actionmailer (= 5.1.4)
84
- actionpack (= 5.1.4)
85
- actionview (= 5.1.4)
86
- activejob (= 5.1.4)
87
- activemodel (= 5.1.4)
88
- activerecord (= 5.1.4)
89
- activesupport (= 5.1.4)
81
+ rails (5.1.5)
82
+ actioncable (= 5.1.5)
83
+ actionmailer (= 5.1.5)
84
+ actionpack (= 5.1.5)
85
+ actionview (= 5.1.5)
86
+ activejob (= 5.1.5)
87
+ activemodel (= 5.1.5)
88
+ activerecord (= 5.1.5)
89
+ activesupport (= 5.1.5)
90
90
  bundler (>= 1.3.0)
91
- railties (= 5.1.4)
91
+ railties (= 5.1.5)
92
92
  sprockets-rails (>= 2.0.0)
93
93
  rails-dom-testing (2.0.3)
94
94
  activesupport (>= 4.2.0)
95
95
  nokogiri (>= 1.6)
96
96
  rails-html-sanitizer (1.0.3)
97
97
  loofah (~> 2.0)
98
- railties (5.1.4)
99
- actionpack (= 5.1.4)
100
- activesupport (= 5.1.4)
98
+ railties (5.1.5)
99
+ actionpack (= 5.1.5)
100
+ activesupport (= 5.1.5)
101
101
  method_source
102
102
  rake (>= 0.8.7)
103
103
  thor (>= 0.18.1, < 2.0)
data/README.md CHANGED
@@ -86,7 +86,7 @@ gem 'webpacker', '~> 3.2'
86
86
  gem 'webpacker', git: 'https://github.com/rails/webpacker.git'
87
87
  ```
88
88
 
89
- and finally, run following to install Webpacker:
89
+ Finally, run following to install Webpacker:
90
90
 
91
91
  ```bash
92
92
  bundle
@@ -99,7 +99,7 @@ bundle exec rake webpacker:install
99
99
 
100
100
  ### Usage
101
101
 
102
- Once installed you can start writing modern ES6-flavored JavaScript app today:
102
+ Once installed, you can start writing modern ES6-flavored JavaScript apps right away:
103
103
 
104
104
  ```yml
105
105
  app/javascript:
@@ -112,8 +112,8 @@ app/javascript:
112
112
  └── logo.svg
113
113
  ```
114
114
 
115
- You can then link the JavaScript pack in Rails view using `javascript_pack_tag` helper.
116
- If you have styles imported in your pack file, you can link using `stylesheet_pack_tag`:
115
+ You can then link the JavaScript pack in Rails views using the `javascript_pack_tag` helper.
116
+ If you have styles imported in your pack file, you can link them by using `stylesheet_pack_tag`:
117
117
 
118
118
  ```erb
119
119
  <%= javascript_pack_tag 'application' %>
@@ -121,7 +121,7 @@ If you have styles imported in your pack file, you can link using `stylesheet_pa
121
121
  ```
122
122
 
123
123
  If you want to link a static asset for `<link rel="prefetch">` or `<img />` tag, you
124
- can use `asset_pack_path` helper:
124
+ can use the `asset_pack_path` helper:
125
125
 
126
126
  ```erb
127
127
  <link rel="prefetch" href="<%= asset_pack_path 'application.css' %>" />
@@ -136,16 +136,16 @@ you would need to link them in your "pack" or entry file.
136
136
 
137
137
  Webpacker ships with two binstubs: `./bin/webpack` and `./bin/webpack-dev-server`.
138
138
  Both are thin wrappers around the standard `webpack.js` and `webpack-dev-server.js`
139
- executable to ensure that the right configuration file and environment variables
140
- are loaded depending on your environment.
139
+ executables to ensure that the right configuration files and environmental variables
140
+ are loaded based on your environment.
141
141
 
142
142
  In development, Webpacker compiles on demand rather than upfront by default. This
143
143
  happens when you refer to any of the pack assets using the Webpacker helper methods.
144
- That means you don't have to run any separate process. Compilation errors are logged
144
+ This means that you don't have to run any separate processes. Compilation errors are logged
145
145
  to the standard Rails log.
146
146
 
147
- 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` if on windows,
148
- in a separate terminal from `bundle exec rails s`. This process will watch for changes
147
+ 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
148
+ in a terminal separate from `bundle exec rails s`. This process will watch for changes
149
149
  in the `app/javascript/packs/*.js` files and automatically reload the browser to match.
150
150
 
151
151
  ```bash
@@ -160,35 +160,35 @@ in the `app/javascript/packs/*.js` files and automatically reload the browser to
160
160
  ```
161
161
 
162
162
  Once you start this development server, Webpacker will automatically start proxying all
163
- webpack asset requests to this server. When you stop the server, it'll revert to
164
- on-demand compilation again.
163
+ webpack asset requests to this server. When you stop the server, it'll revert back to
164
+ on-demand compilation.
165
165
 
166
166
  You can use environment variables as options supported by
167
167
  [webpack-dev-server](https://webpack.js.org/configuration/dev-server/) in the
168
- form `WEBPACKER_DEV_SERVER_<OPTION>`. Please note that these environment
168
+ form `WEBPACKER_DEV_SERVER_<OPTION>`. Please note that these environmental
169
169
  variables will always take precedence over the ones already set in the
170
- configuration file, and that the _same_ environment variables must
170
+ configuration file, and that the _same_ environmental variables must
171
171
  be available to the `rails server` process.
172
172
 
173
173
  ```bash
174
174
  WEBPACKER_DEV_SERVER_HOST=example.com WEBPACKER_DEV_SERVER_INLINE=true WEBPACKER_DEV_SERVER_HOT=false ./bin/webpack-dev-server
175
175
  ```
176
176
 
177
- By default, webpack dev server listens on `localhost` in development for security
178
- but if you want your app to be available over local LAN IP or VM instance like vagrant
177
+ By default, the webpack dev server listens on `localhost` in development for security purposes.
178
+ However, if you want your app to be available over local LAN IP or a VM instance like vagrant,
179
179
  you can set the `host` when running `./bin/webpack-dev-server` binstub:
180
180
 
181
181
  ```bash
182
182
  WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server
183
183
  ```
184
184
 
185
- **Note:** You need to allow webpack-dev-server host as 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+ for development environment in the CSP initializer `config/initializers/content_security_policy.rb` with a snippet like this:
185
+ **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:
186
186
 
187
187
  ```ruby
188
188
  p.connect_src :self, :https, 'http://localhost:3035', 'ws://localhost:3035' if Rails.env.development?
189
189
  ```
190
190
 
191
- **Note:** Don't forget to prefix `ruby` when running these binstubs on windows
191
+ **Note:** Don't forget to prefix `ruby` when running these binstubs on Windows
192
192
 
193
193
  ### webpack configuration
194
194
 
@@ -197,7 +197,7 @@ See [docs/webpack](docs/webpack.md) for modifying webpack configuration and load
197
197
 
198
198
  ### Upgrading
199
199
 
200
- You can run following commands to upgrade Webpacker to the latest stable version, this involves upgrading the gem and related npm modules:
200
+ You can run following commands to upgrade Webpacker to the latest stable version. This process involves upgrading the gem and related npm modules:
201
201
 
202
202
  ```bash
203
203
  bundle update webpacker
@@ -207,15 +207,15 @@ yarn upgrade webpack-dev-server --latest
207
207
 
208
208
  ### Yarn Integrity
209
209
 
210
- By default in development, webpacker runs a yarn integrity check to ensure that all local npm 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 and you will be asked to upgrade your local npm packages by running `yarn install`.
210
+ By default, in development, webpacker runs a yarn integrity check to ensure that all local npm 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 npm packages by running `yarn install`.
211
211
 
212
- To turn off this option, you will need to override the default by adding a new config options to your Rails development environment configuration file (`config/environment/development.rb`):
212
+ To turn off this option, you will need to override the default by adding a new config option to your Rails development environment configuration file (`config/environment/development.rb`):
213
213
 
214
214
  ```
215
215
  config.webpacker.check_yarn_integrity = false
216
216
  ```
217
217
 
218
- You may also turn on this option by adding the config option to any Rails environment configuration file:
218
+ You may also turn on this feature by adding the config option to any Rails environment configuration file:
219
219
 
220
220
  ```
221
221
  config.webpacker.check_yarn_integrity = true
@@ -239,8 +239,8 @@ rails new myapp --webpack=react
239
239
  (or run `bundle exec rails webpacker:install:react` in a existing Rails app already
240
240
  setup with Webpacker).
241
241
 
242
- The installer will add all relevant dependencies using Yarn, any changes
243
- to the configuration files and an example React component to your
242
+ The installer will add all relevant dependencies using Yarn, changes
243
+ to the configuration files, and an example React component to your
244
244
  project in `app/javascript/packs` so that you can experiment with React right away.
245
245
 
246
246
 
@@ -257,19 +257,19 @@ rails new myapp --webpack=angular
257
257
  (or run `bundle exec rails webpacker:install:angular` on a Rails app already
258
258
  setup with Webpacker).
259
259
 
260
- The installer will add TypeScript and Angular core libraries using Yarn plus
261
- any changes to the configuration files. An example component is written in
260
+ The installer will add the TypeScript and Angular core libraries using Yarn alongside
261
+ a few changes to the configuration files. An example component written in
262
262
  TypeScript will also be added to your project in `app/javascript` so that
263
263
  you can experiment with Angular right away.
264
264
 
265
- By default Angular uses a JIT compiler for development environment, this
265
+ By default, Angular uses a JIT compiler for development environment. This
266
266
  compiler is not compatible with restrictive CSP (Content Security
267
267
  Policy) environments like Rails 5.2+. You can use Angular AOT compiler
268
268
  in development with the [@ngtools/webpack](https://www.npmjs.com/package/@ngtools/webpack#usage) plugin.
269
269
 
270
- Alternatively if you're using Rails 5.2+ you can enable `unsafe-eval` rule for
271
- development environment, this can be done in the `config/initializers/content_security_policy.rb`
272
- with the following configuration:
270
+ Alternatively if you're using Rails 5.2+ you can enable `unsafe-eval` rule for your
271
+ development environment. This can be done in the `config/initializers/content_security_policy.rb`
272
+ with the following code:
273
273
 
274
274
  ```ruby
275
275
  if Rails.env.development?
@@ -291,13 +291,12 @@ rails new myapp --webpack=vue
291
291
  ```
292
292
  (or run `bundle exec rails webpacker:install:vue` on a Rails app already setup with Webpacker).
293
293
 
294
- The installer will add Vue and required libraries using Yarn plus
295
- any changes to the configuration files. An example component will
296
- also be added to your project in `app/javascript` so that you can
297
- experiment Vue right away.
294
+ The installer will add Vue and its required libraries using Yarn alongside
295
+ automatically applying changes needed to the configuration files. An example component will
296
+ be added to your project in `app/javascript` so that you can experiment with Vue right away.
298
297
 
299
- If you're using Rails 5.2+ you need to enable `unsafe-eval` rule for development environment,
300
- this can be done in the `config/initializers/content_security_policy.rb` with the following
298
+ If you're using Rails 5.2+ you'll need to enable `unsafe-eval` rule for your development environment.
299
+ This can be done in the `config/initializers/content_security_policy.rb` with the following
301
300
  configuration:
302
301
 
303
302
  ```ruby
@@ -322,7 +321,7 @@ rails new myapp --webpack=elm
322
321
 
323
322
  (or run `bundle exec rails webpacker:install:elm` on a Rails app already setup with Webpacker).
324
323
 
325
- The Elm library and core packages will be added via Yarn and Elm itself.
324
+ The Elm library and its core packages will be added via Yarn and Elm.
326
325
  An example `Main.elm` app will also be added to your project in `app/javascript`
327
326
  so that you can experiment with Elm right away.
328
327
 
@@ -356,15 +355,15 @@ run `bundle exec rails webpacker:install:erb` on a Rails app already
356
355
  setup with Webpacker.
357
356
 
358
357
  An example `hello_erb.js.erb` file will also be added to your project
359
- in `app/javascript/packs` so that you can experiment with Erb flavoured
358
+ in `app/javascript/packs` so that you can experiment with Erb-flavoured
360
359
  javascript right away.
361
360
 
362
361
 
363
362
  ## Paths
364
363
 
365
364
  By default, Webpacker ships with simple conventions for where the JavaScript
366
- app files and compiled webpack bundles will go in your Rails app,
367
- but all these options are configurable from `config/webpacker.yml` file.
365
+ app files and compiled webpack bundles will go in your Rails app.
366
+ All these options are configurable from `config/webpacker.yml` file.
368
367
 
369
368
  The configuration for what webpack is supposed to compile by default rests
370
369
  on the convention that every file in `app/javascript/packs/*`**(default)**
@@ -399,16 +398,16 @@ If you have `hmr` turned to true, then the `stylesheet_pack_tag` generates no ou
399
398
  ### Resolved
400
399
 
401
400
  If you are adding Webpacker to an existing app that has most of the assets inside
402
- `app/assets` or inside an engine and you want to share that
403
- with webpack modules then you can use `resolved_paths`
404
- option available in `config/webpacker.yml`, which lets you
405
- add additional paths webpack should lookup when resolving modules:
401
+ `app/assets` or inside an engine, and you want to share that
402
+ with webpack modules, you can use the `resolved_paths`
403
+ option available in `config/webpacker.yml`. This lets you
404
+ add additional paths that webpack should lookup when resolving modules:
406
405
 
407
406
  ```yml
408
407
  resolved_paths: ['app/assets']
409
408
  ```
410
409
 
411
- You can then import them inside your modules like so:
410
+ You can then import these items inside your modules like so:
412
411
 
413
412
  ```js
414
413
  // Note it's relative to parent directory i.e. app/assets
@@ -423,9 +422,9 @@ whole parent directory if you just need to reference one or two modules
423
422
 
424
423
  ### Watched
425
424
 
426
- By default, the lazy compilation is cached until a file is changed under
427
- tracked paths. You can configure the paths tracked
428
- by adding new paths to `watched_paths` array, much like Rails `autoload_paths`:
425
+ By default, the lazy compilation is cached until a file is changed under your
426
+ tracked paths. You can configure which paths are tracked
427
+ by adding new paths to `watched_paths` array. This is much like Rails' `autoload_paths`:
429
428
 
430
429
  ```rb
431
430
  # config/initializers/webpacker.rb
@@ -436,7 +435,7 @@ Webpacker::Compiler.watched_paths << 'bower_components'
436
435
 
437
436
  ## Deployment
438
437
 
439
- 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`. Remember to set NODE_ENV environment variable to production during deployment or when running the rake task.
438
+ 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`. Remember to set NODE_ENV environment variable to production during deployment or when running this rake task.
440
439
 
441
440
  ## Docs
442
441
 
data/docs/css.md CHANGED
@@ -4,7 +4,7 @@
4
4
  Webpacker supports importing CSS, Sass and SCSS files directly into your JavaScript files.
5
5
 
6
6
 
7
- ## Import styles into your JS app
7
+ ## Import global styles into your JS app
8
8
 
9
9
  ```sass
10
10
  // app/javascript/hello_react/styles/hello-react.sass
@@ -30,6 +30,36 @@ const Hello = props => (
30
30
  )
31
31
  ```
32
32
 
33
+ ## Import scoped styles into your JS app
34
+
35
+ Stylesheets end with `.module.*` is treated as [CSS Modules](https://github.com/css-modules/css-modules).
36
+
37
+ ```sass
38
+ // app/javascript/hello_react/styles/hello-react.module.sass
39
+
40
+ .helloReact
41
+ padding: 20px
42
+ font-size: 12px
43
+ ```
44
+
45
+ ```js
46
+ // React component example
47
+ // app/javascripts/packs/hello_react.jsx
48
+
49
+ import React from 'react'
50
+ import helloIcon from '../hello_react/images/icon.png'
51
+ import styles from '../hello_react/styles/hello-react'
52
+
53
+ const Hello = props => (
54
+ <div className={styles.helloReact}>
55
+ <img src={helloIcon} alt="hello-icon" />
56
+ <p>Hello {props.name}!</p>
57
+ </div>
58
+ )
59
+ ```
60
+
61
+ **Note:** Declared class is referenced as object property in JavaScript.
62
+
33
63
 
34
64
  ## Link styles from your Rails views
35
65