webpacker 6.0.0.beta.1 → 6.0.0.beta.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/jest.yml +1 -1
  3. data/.github/workflows/js-lint.yml +1 -1
  4. data/.github/workflows/ruby.yml +9 -6
  5. data/6_0_upgrade.md +29 -10
  6. data/CHANGELOG.md +2 -0
  7. data/CONTRIBUTING.md +1 -1
  8. data/Gemfile.lock +7 -5
  9. data/README.md +134 -54
  10. data/config/README.md +3 -0
  11. data/config/webpacker.yml +1 -0
  12. data/docs/troubleshooting.md +160 -0
  13. data/lib/install/config/webpacker.yml +4 -2
  14. data/lib/install/{javascript/packs → packs/entrypoints}/application.js +1 -1
  15. data/lib/install/template.rb +3 -3
  16. data/lib/webpacker/commands.rb +2 -1
  17. data/lib/webpacker/compiler.rb +2 -2
  18. data/lib/webpacker/dev_server_runner.rb +2 -0
  19. data/lib/webpacker/helper.rb +13 -43
  20. data/lib/webpacker/manifest.rb +1 -1
  21. data/lib/webpacker/version.rb +1 -1
  22. data/lib/webpacker/webpack_runner.rb +1 -0
  23. data/package.json +1 -1
  24. data/package/__tests__/development.js +2 -1
  25. data/package/__tests__/index.js +9 -0
  26. data/package/environments/__tests__/base.js +6 -6
  27. data/package/environments/base.js +7 -4
  28. data/package/environments/development.js +1 -0
  29. data/package/environments/production.js +29 -22
  30. data/package/index.js +3 -3
  31. data/package/rules/babel.js +1 -1
  32. data/package/rules/file.js +6 -2
  33. data/package/rules/index.js +2 -2
  34. data/package/rules/stylus.js +26 -0
  35. data/package/utils/helpers.js +4 -2
  36. data/test/configuration_test.rb +2 -2
  37. data/test/dev_server_runner_test.rb +10 -2
  38. data/test/helper_test.rb +33 -39
  39. data/test/manifest_test.rb +8 -0
  40. data/test/mounted_app/test/dummy/config/webpacker.yml +2 -2
  41. data/test/test_app/app/{javascript/packs → packs/entrypoints}/application.js +1 -1
  42. data/test/test_app/app/{javascript/packs → packs/entrypoints}/multi_entry.css +0 -0
  43. data/test/test_app/app/{javascript/packs → packs/entrypoints}/multi_entry.js +0 -0
  44. data/test/test_app/config/webpacker.yml +2 -2
  45. data/test/test_app/public/packs/manifest.json +7 -0
  46. metadata +16 -13
  47. data/lib/install/javascript/packs/application.css +0 -9
  48. data/package/rules/svg.js +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6443ddc11bf717fe1987306bc46527edf1692dfdc8bb3b827a8918a5e81b89b
4
- data.tar.gz: 9dd83b7b25ee965abe951b86e3529797ef8f51e7dd5e3b94011f4d781adfab8c
3
+ metadata.gz: 3e389b1e654d5e3b6e50adb6a908c94cb1039e978b119f32c49c07813f0733ca
4
+ data.tar.gz: 4843befc313e31f85996e36ce59c994f8c3842e82034da51872a2a4f8cb0e5d7
5
5
  SHA512:
6
- metadata.gz: 64209399bfb645bb325799c6f4267e78439d59481983a5906888203cdec03034bb592dc226d93da70f56b5567337a4cf91352a85d1dfc0e386fdceea8ef1ecb9
7
- data.tar.gz: 296d7238ffb6ad997ed71730304aeb34330610ccd2ec4f0838d3fbbec0bf4d39a0131b1f3fc2a9779c0a51e161f4a7952974ee04b47ca7edab9a6f2a9a5aa651
6
+ metadata.gz: 8238ffb0c0b369bbffdf26766a237ca9ab059989aa79c9fa752fe8f217a79ee2985d00ec52861b7320fe2a5610d5df48941ddb597995bf95c846b381a3f7544d
7
+ data.tar.gz: ce30d8500790565854a174e2ab67598a4fa7ff90eb67a226fb182861baba8d4bb7446958c0457c9b22aedaf345438f69f6542f52a672a6fa2204882220d5d277
@@ -8,7 +8,7 @@ jobs:
8
8
  strategy:
9
9
  matrix:
10
10
  os: [ubuntu-latest]
11
- node: [10.x, 12.x, 14.x]
11
+ node: [10.x, 12.x, 14.x, 15.x]
12
12
 
13
13
  runs-on: ${{ matrix.os }}
14
14
 
@@ -9,7 +9,7 @@ jobs:
9
9
  strategy:
10
10
  matrix:
11
11
  os: [ubuntu-latest]
12
- node: [12.x]
12
+ node: [14.x]
13
13
 
14
14
  runs-on: ${{ matrix.os }}
15
15
 
@@ -18,7 +18,8 @@ jobs:
18
18
  2.4,
19
19
  2.5,
20
20
  2.6,
21
- 2.7
21
+ 2.7,
22
+ 3.0
22
23
  ]
23
24
  gemfile: [
24
25
  "gemfiles/Gemfile-rails.5.2.x",
@@ -27,13 +28,11 @@ jobs:
27
28
  exclude:
28
29
  - ruby: "2.4"
29
30
  gemfile: gemfiles/Gemfile-rails.6.0.x
31
+ - ruby: "3.0"
32
+ gemfile: gemfiles/Gemfile-rails.5.2.x
30
33
  experimental: [false]
31
34
  include:
32
- - ruby: head
33
- os: ubuntu-latest
34
- gemfile: gemfiles/Gemfile-rails.6.0.x
35
- experimental: true
36
- - ruby: head
35
+ - ruby: 2.5
37
36
  os: ubuntu-latest
38
37
  gemfile: gemfiles/Gemfile-rails-edge
39
38
  experimental: true
@@ -45,6 +44,10 @@ jobs:
45
44
  os: ubuntu-latest
46
45
  gemfile: gemfiles/Gemfile-rails-edge
47
46
  experimental: true
47
+ - ruby: 3.0
48
+ os: ubuntu-latest
49
+ gemfile: gemfiles/Gemfile-rails-edge
50
+ experimental: true
48
51
 
49
52
  steps:
50
53
  - uses: actions/checkout@v2
data/6_0_upgrade.md CHANGED
@@ -6,17 +6,20 @@ straightforward.
6
6
 
7
7
  ## Preparation
8
8
 
9
- - Rename `config/webpack` to `config/webpack_old`
10
- - Rename `config/webpacker.yml` to `config/webpacker_old.yml`
11
- - Upgrade webpacker
9
+ 1. If your `source_path` is `app/javascript`, rename it to `app/packs`
10
+ 2. If your `source_entry_path` is `packs`, rename it to `entrypoints`
11
+ 3. Rename `config/webpack` to `config/webpack_old`
12
+ 4. Rename `config/webpacker.yml` to `config/webpacker_old.yml`
13
+ 5. Uninstall the current version of `webpack-dev-server`: `yarn remove webpack-dev-server`
14
+ 6. Upgrade webpacker
12
15
 
13
16
  ```ruby
14
17
  # Gemfile
15
- gem 'webpacker', '~> 6.x'
18
+ gem 'webpacker', '~> 6.0.0.pre.2'
16
19
  ```
17
20
 
18
- ```
19
- bundle
21
+ ```bash
22
+ bundle install
20
23
  ```
21
24
 
22
25
  ```bash
@@ -27,12 +30,15 @@ straightforward.
27
30
  bundle exec rails webpacker:install
28
31
  ```
29
32
 
30
- - Change `javascript_pack_tag` and `stylesheet_pack_tag` to `javascript_packs_with_chunks_tag` and
31
- `stylesheet_packs_with_chunks_tag`
33
+ - Change `javascript_packs_with_chunks_tag` and `stylesheet_packs_with_chunks_tag` to `javascript_pack_tag` and
34
+ `stylesheet_pack_tag`.
32
35
 
33
- - If you are using any integrations like css, react or typescript. Please see https://github.com/rails/webpacker#integrations section on how they work in v6.0
36
+ 7. If you are using any integrations like `css`, `React` or `TypeScript`. Please see https://github.com/rails/webpacker#integrations section on how they work in v6.0.
34
37
 
35
- - Copy over any custom webpack config from `config/webpack_old`
38
+ 8. Copy over any custom webpack config from `config/webpack_old`
39
+
40
+ - Common code previously called 'environment' changed to 'base'
41
+ - import `environment` changed name to `webpackConfig`.
36
42
 
37
43
  ```js
38
44
  // config/webpack/base.js
@@ -41,3 +47,16 @@ straightforward.
41
47
 
42
48
  module.exports = merge(webpackConfig, customConfig)
43
49
  ```
50
+
51
+ 9. Copy over custom browserlist config from `.browserlistrc` if it exists into the `"browserlist"` key in `package.json` and remove `.browserslistrc`.
52
+
53
+ 10. `extensions` was removed from the webpacker.yml file. Move custom extensions to
54
+ your configuration by by merging an object like this. For more details, see docs for
55
+ [Webpack Configuration](https://github.com/rails/webpacker/blob/master/README.md#webpack-configuration)
56
+ ```js
57
+ {
58
+ resolve: {
59
+ extensions: ['.ts', '.tsx']
60
+ }
61
+ }
62
+ ```
data/CHANGELOG.md CHANGED
@@ -17,6 +17,8 @@ environment.loaders.append('nodeModules', nodeModules)
17
17
  - Changes `@babel/preset-env` modules option to `'auto'` per recommendation in the Babel docs [#2709](https://github.com/rails/webpacker/pull/2709)
18
18
  - Adds experimental Yarn 2 support. Note you must manually set `nodeLinker: node-modules` in your `.yarnrc.yml`.
19
19
 
20
+ - Fixes dev server issues [#2898](https://github.com/rails/webpacker/pull/2898)
21
+
20
22
  ### Breaking changes
21
23
 
22
24
  - Simple webpack config
data/CONTRIBUTING.md CHANGED
@@ -9,7 +9,7 @@ yarn
9
9
  ```
10
10
 
11
11
  ## Making sure your changes pass all tests
12
- There are a number of automated checks which run on Github Actions when a pull request is created.
12
+ There are a number of automated checks which run on GitHub Actions when a pull request is created.
13
13
  You can run those checks on your own locally to make sure that your changes would not break the CI build.
14
14
 
15
15
  ### 1. Check the code for JavaScript style violations
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- webpacker (6.0.0.beta.1)
4
+ webpacker (6.0.0.beta.6)
5
5
  activesupport (>= 5.2)
6
6
  rack-proxy (>= 0.6.1)
7
7
  railties (>= 5.2)
@@ -85,14 +85,16 @@ GEM
85
85
  method_source (1.0.0)
86
86
  mimemagic (0.3.5)
87
87
  mini_mime (1.0.2)
88
- mini_portile2 (2.4.0)
89
- minitest (5.14.1)
88
+ mini_portile2 (2.5.0)
89
+ minitest (5.14.3)
90
90
  nio4r (2.5.2)
91
- nokogiri (1.10.10)
92
- mini_portile2 (~> 2.4.0)
91
+ nokogiri (1.11.1)
92
+ mini_portile2 (~> 2.5.0)
93
+ racc (~> 1.4)
93
94
  parallel (1.19.2)
94
95
  parser (2.7.2.0)
95
96
  ast (~> 2.4.1)
97
+ racc (1.5.2)
96
98
  rack (2.2.3)
97
99
  rack-proxy (0.6.5)
98
100
  rack
data/README.md CHANGED
@@ -36,7 +36,6 @@ in which case you may not even need the asset pipeline. This is mostly relevant
36
36
  - [Resolved](#resolved)
37
37
  - [Watched](#watched)
38
38
  - [Deployment](#deployment)
39
- - [Docs](#docs)
40
39
  - [Contributing](#contributing)
41
40
  - [License](#license)
42
41
 
@@ -59,13 +58,13 @@ in which case you may not even need the asset pipeline. This is mostly relevant
59
58
  - Rails view helpers
60
59
  - Extensible and configurable
61
60
 
62
- ### Optional support\*
61
+ ### Optional support
63
62
 
64
63
  _requires extra packages to be installed_
65
64
 
66
- - Stylesheets - SASS, LESS and CSS, PostCSS
67
- - Coffeescript
68
- - Typescript
65
+ - Stylesheets - Sass, Less, Stylus and Css, PostCSS
66
+ - CoffeeScript
67
+ - TypeScript
69
68
  - React
70
69
 
71
70
  ## Installation
@@ -108,7 +107,8 @@ yarn upgrade
108
107
  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:
109
108
 
110
109
  ```bash
111
- yarn install
110
+ # default for `yarn` is to install
111
+ yarn
112
112
  ```
113
113
 
114
114
  ### Usage
@@ -116,9 +116,9 @@ yarn install
116
116
  Once installed, you can start writing modern ES6-flavored JavaScript apps right away:
117
117
 
118
118
  ```yml
119
- app/javascript:
120
- ├── packs:
121
- │ # only webpack entry files here
119
+ app/packs:
120
+ ├── entrypoints:
121
+ │ # Only webpack entry files here
122
122
  │ └── application.js
123
123
  │ └── application.css
124
124
  └── src:
@@ -129,23 +129,50 @@ app/javascript:
129
129
  └── logo.svg
130
130
  ```
131
131
 
132
- You can then link the JavaScript pack in Rails views using the `javascript_packs_with_chunks_tag` helper. If you have styles imported in your pack file, you can link them by using `stylesheet_packs_with_chunks_tag`:
132
+ You can then link the JavaScript pack in Rails views using the `javascript_pack_tag` helper. If you have styles imported in your pack file, you can link them by using `stylesheet_pack_tag`:
133
133
 
134
134
  ```erb
135
- <%= javascript_packs_with_chunks_tag 'application' %>
136
- <%= stylesheet_packs_with_chunks_tag 'application' %>
135
+ <%= javascript_pack_tag 'application' %>
136
+ <%= stylesheet_pack_tag 'application' %>
137
137
  ```
138
138
 
139
- If you want to link a static asset for `<link rel="prefetch">` or `<img />` tag, you
140
- can use the `asset_pack_path` helper:
141
-
139
+ If you want to link a static asset for `<img />` tag, you can use the `asset_pack_path` helper:
142
140
  ```erb
143
- <link rel="prefetch" href="<%= asset_pack_path 'application.css' %>" />
144
141
  <img src="<%= asset_pack_path 'images/logo.svg' %>" />
145
142
  ```
146
143
 
144
+ Or use the dedicated helper:
145
+ ```erb
146
+ <%= image_pack_tag 'application.png', size: '16x10', alt: 'Edit Entry' %>
147
+ <%= image_pack_tag 'picture.png', srcset: { 'picture-2x.png' => '2x' } %>
148
+ ```
149
+
150
+ If you want to create a favicon:
151
+ ```erb
152
+ <%= favicon_pack_tag 'mb-icon.png', rel: 'apple-touch-icon', type: 'image/png' %>
153
+ ```
154
+
155
+ If you want to preload a static asset in your `<head>`, you can use the `preload_pack_asset` helper:
156
+ ```erb
157
+ <%= preload_pack_asset 'fonts/fa-regular-400.woff2' %>
158
+ ```
159
+
160
+ If you want to use images in your stylesheets:
161
+
162
+ ```css
163
+ .foo {
164
+ background-image: url('../images/logo.svg')
165
+ }
166
+ ```
167
+
168
+ Note, if you are using server-side rendering of JavaScript with dynamic code-spliting,
169
+ as is often done with extensions to Webpacker, like [React on Rails](https://github.com/shakacode/react_on_rails)
170
+ your JavaScript should create the link prefetch HTML tags that you will use, so you won't
171
+ need to use to `asset_pack_path` in those circumstances.
172
+
147
173
  **Note:** In order for your styles or static assets files to be available in your view,
148
- you would need to link them in your "pack" or entry file.
174
+ you would need to link them in your "pack" or entry file. Otherwise, Webpack won't know
175
+ to package up those files.
149
176
 
150
177
  ### Development
151
178
 
@@ -157,11 +184,20 @@ are loaded based on your environment.
157
184
  In development, Webpacker compiles on demand rather than upfront by default. This
158
185
  happens when you refer to any of the pack assets using the Webpacker helper methods.
159
186
  This means that you don't have to run any separate processes. Compilation errors are logged
160
- to the standard Rails log.
187
+ to the standard Rails log. However, this auto-compilation happens when a web request
188
+ is made that requires an updated webpack build, not when files change. Thus, that can
189
+ be painfully slow for front-end development in this default way. Instead, you should either
190
+ run the `bin/webpack --watch` or run `./bin/webpack-dev-server`
161
191
 
162
- 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
163
- in a terminal separate from `bundle exec rails s`. This process will watch for changes
164
- in the `app/javascript/packs/*.js` files and automatically reload the browser to match.
192
+ 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`.
193
+ Windows users will need to run these commands in a terminal separate from `bundle exec rails s`.
194
+ This process will watch for changes in the `app/packs/entrypoints/*.js` files and automatically
195
+ reload the browser to match. This feature is also known as
196
+ [Hot Module Replacement](https://webpack.js.org/concepts/hot-module-replacement/).
197
+
198
+ HMR is only the first step to running "Fast Refresh" with React. For more information
199
+ on how to configure rails/webpacker for Fast Refresh with React, see article
200
+ [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).
165
201
 
166
202
  ```bash
167
203
  # webpack dev server
@@ -174,9 +210,10 @@ in the `app/javascript/packs/*.js` files and automatically reload the browser to
174
210
  ./bin/webpack
175
211
  ```
176
212
 
177
- Once you start this development server, Webpacker will automatically start proxying all
178
- webpack asset requests to this server. When you stop the server, it'll revert back to
179
- on-demand compilation.
213
+ Once you start this webpack development server, Webpacker will automatically start proxying all
214
+ webpack asset requests to this server. When you stop this server, Rails will detect
215
+ that it's not running and Rails will revert back to on-demand compilation _if_ you have
216
+ the `compile` option set to true in your `config/webpacker.yml`
180
217
 
181
218
  You can use environment variables as options supported by
182
219
  [webpack-dev-server](https://webpack.js.org/configuration/dev-server/) in the
@@ -212,7 +249,7 @@ WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server
212
249
  Webpacker gives you a default set of configuration files for test, development and
213
250
  production environments in `config/webpack/*.js`. You can configure each individual
214
251
  environment in their respective files or configure them all in the base
215
- `config/webpack/environment.js` file.
252
+ `config/webpack/base.js` file.
216
253
 
217
254
  By default, you don't need to make any changes to `config/webpack/*.js`
218
255
  files since it's all standard production-ready configuration. However,
@@ -256,23 +293,26 @@ const { webpackConfig } = require('@rails/webpacker')
256
293
 
257
294
  console.log(webpackConfig.output_path)
258
295
  console.log(webpackConfig.source_path)
296
+
297
+ // Or to print out your whole webpack configuration
298
+ console.log(JSON.stringify(webpackConfig, undefined, 2))
259
299
  ```
260
300
 
261
301
  ### Integrations
262
302
 
263
303
  Webpacker out of the box supports JS and static assets (fonts, images etc.)
264
- compilation. To enable support for Coffeescript or Typescript install
265
- relevant packages,
304
+ compilation. To enable support for CoffeeScript or TypeScript install
305
+ relevant packages:
266
306
 
267
- **Coffeescript**
307
+ #### CoffeeScript
268
308
 
269
- ```
309
+ ```bash
270
310
  yarn add coffeescript coffee-loader
271
311
  ```
272
312
 
273
- **Typescript**
313
+ #### TypeScript
274
314
 
275
- ```
315
+ ```bash
276
316
  yarn add typescript @babel/preset-typescript
277
317
  ```
278
318
 
@@ -289,7 +329,7 @@ Add tsconfig.json
289
329
  "moduleResolution": "node",
290
330
  "baseUrl": ".",
291
331
  "paths": {
292
- "*": ["node_modules/*", "app/javascript/*"]
332
+ "*": ["node_modules/*", "app/packs/*"]
293
333
  },
294
334
  "sourceMap": true,
295
335
  "target": "es5",
@@ -300,15 +340,33 @@ Add tsconfig.json
300
340
  }
301
341
  ```
302
342
 
303
- #### CSS
343
+ Babel won’t perform any type-checking on TypeScript code. To optionally use type-checking run:
344
+
345
+ ```bash
346
+ yarn add fork-ts-checker-webpack-plugin
347
+ ```
348
+
349
+ Then modify the webpack config to use it as a plugin:
304
350
 
305
- To enable CSS support in your application, add following packages,
351
+ ```js
352
+ // config/webpack/base.js
353
+ const { webpackConfig, merge } = require("@rails/webpacker");
354
+ const ForkTSCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
306
355
 
356
+ module.exports = merge(webpackConfig, {
357
+ plugins: [new ForkTSCheckerWebpackPlugin()],
358
+ });
307
359
  ```
360
+
361
+ #### CSS
362
+
363
+ To enable CSS support in your application, add following packages:
364
+
365
+ ```bash
308
366
  yarn add css-loader mini-css-extract-plugin css-minimizer-webpack-plugin
309
367
  ```
310
368
 
311
- optionally, add css extension to webpack config for easy resolution
369
+ optionally, add the css extension to webpack config for easy resolution.
312
370
 
313
371
  ```js
314
372
  // config/webpack/base.js
@@ -327,27 +385,33 @@ then add the relevant pre-processors:
327
385
 
328
386
  #### Postcss
329
387
 
330
- ```
388
+ ```bash
331
389
  yarn add postcss-loader
332
390
  ```
333
391
 
334
392
  #### Sass
335
393
 
336
- ```
337
- yarn add sass-loader
394
+ ```bash
395
+ yarn add sass sass-loader
338
396
  ```
339
397
 
340
398
  #### Less
341
399
 
400
+ ```bash
401
+ yarn add less less-loader
342
402
  ```
343
- yarn add less-loader
403
+
404
+ #### Stylus
405
+
406
+ ```bash
407
+ yarn add stylus stylus-loader
344
408
  ```
345
409
 
346
410
  #### React
347
411
 
348
412
  React is supported and you just need to add relevant packages,
349
413
 
350
- ```
414
+ ```bash
351
415
  yarn add react react-dom @babel/preset-react
352
416
  ```
353
417
 
@@ -372,16 +436,19 @@ if you are using typescript, update your `tsconfig.json`
372
436
  }
373
437
  ```
374
438
 
439
+ For more information on React props hydration and Server-Side Rendering (SSR), see the article
440
+ [Rails/Webpacker React Integration Options](https://github.com/shakacode/react_on_rails/blob/master/docs/rails-webpacker-react-integration-options.md)
441
+ in the [ShakaCode/react_on_rails](https://github.com/shakacode/react_on_rails) repo.
442
+
375
443
  #### Other frameworks
376
444
 
377
445
  Please follow webpack integration guide for relevant framework or library,
378
446
 
379
- 1. Svelte - https://github.com/sveltejs/svelte-loader#install
380
- 2. Angular - https://v2.angular.io/docs/ts/latest/guide/webpack.html#!#configure-webpack
381
- 3. Vue - https://vue-loader.vuejs.org/guide/
382
-
383
- For example to add Vue support,
447
+ 1. [Svelte](https://github.com/sveltejs/svelte-loader#install)
448
+ 2. [Angular](https://v2.angular.io/docs/ts/latest/guide/webpack.html#!#configure-webpack)
449
+ 3. [Vue](https://vue-loader.vuejs.org/guide/)
384
450
 
451
+ For example to add Vue support:
385
452
  ```js
386
453
  // config/webpack/rules/vue.js
387
454
  const VueLoaderPlugin = require('vue-loader/lib/plugin')
@@ -397,7 +464,9 @@ module.exports = {
397
464
  },
398
465
  plugins: [new VueLoaderPlugin()]
399
466
  }
467
+ ```
400
468
 
469
+ ```js
401
470
  // config/webpack/base.js
402
471
  const { webpackConfig, merge } = require('@rails/webpacker')
403
472
  const vueConfig = require('./rules/vue')
@@ -445,11 +514,11 @@ Please note, binstubs compiles in development mode however rake tasks
445
514
  compiles in production mode.
446
515
 
447
516
  ```bash
448
- # Compiles in development mode unless NODE_ENV is specified
517
+ # Compiles in development mode unless NODE_ENV is specified, per the binstub source
449
518
  ./bin/webpack
450
519
  ./bin/webpack-dev-server
451
520
 
452
- # compiles in production mode by default unless NODE_ENV is specified
521
+ # Compiles in production mode by default unless NODE_ENV is specified, per `lib/tasks/webpacker/compile.rake`
453
522
  bundle exec rails assets:precompile
454
523
  bundle exec rails webpacker:compile
455
524
  ```
@@ -459,8 +528,12 @@ bundle exec rails webpacker:compile
459
528
  You can run following commands to upgrade Webpacker to the latest stable version. This process involves upgrading the gem and related JavaScript packages:
460
529
 
461
530
  ```bash
531
+ # check your Gemfile for version restrictions
462
532
  bundle update webpacker
533
+
534
+ # overwrite your changes to the default install files and revert any unwanted changes from the install
463
535
  rails webpacker:install
536
+
464
537
  yarn upgrade @rails/webpacker --latest
465
538
  yarn upgrade webpack-dev-server --latest
466
539
 
@@ -468,6 +541,8 @@ yarn upgrade webpack-dev-server --latest
468
541
  yarn add @rails/webpacker@next
469
542
  ```
470
543
 
544
+ Also, consult the [CHANGELOG](./CHANGELOG.md) for additional upgrade links.
545
+
471
546
  ## Paths
472
547
 
473
548
  By default, Webpacker ships with simple conventions for where the JavaScript
@@ -475,19 +550,18 @@ app files and compiled webpack bundles will go in your Rails app.
475
550
  All these options are configurable from `config/webpacker.yml` file.
476
551
 
477
552
  The configuration for what webpack is supposed to compile by default rests
478
- on the convention that every file in `app/javascript/packs/*`**(default)**
553
+ on the convention that every file in `app/packs/entrypoints/*`**(default)**
479
554
  or whatever path you set for `source_entry_path` in the `webpacker.yml` configuration
480
555
  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
481
556
  an entry file. As a rule of thumb, put all files you want to link in your views inside
482
- "packs" directory and keep everything else under `app/javascript`.
557
+ "packs" directory and keep everything else under `app/packs`.
483
558
 
484
- Suppose you want to change the source directory from `app/javascript`
559
+ Suppose you want to change the source directory from `app/packs`
485
560
  to `frontend` and output to `assets/packs`. This is how you would do it:
486
561
 
487
562
  ```yml
488
563
  # config/webpacker.yml
489
- source_path: frontend
490
- source_entry_path: packs
564
+ source_path: frontend # packs are in frontend/packs
491
565
  public_output_path: assets/packs # outputs to => public/assets/packs
492
566
  ```
493
567
 
@@ -501,7 +575,9 @@ development:
501
575
  port: 3035
502
576
  ```
503
577
 
504
- 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.
578
+ If you have `hmr` turned to true, then the `stylesheet_pack_tag` generates no output,
579
+ as you will want to configure your styles to be inlined in your JavaScript for hot reloading.
580
+ During production and testing, the `stylesheet_pack_tag` will create the appropriate HTML tags.
505
581
 
506
582
  ### Additional paths
507
583
 
@@ -512,7 +588,7 @@ option available in `config/webpacker.yml`. This lets you
512
588
  add additional paths that webpack should lookup when resolving modules:
513
589
 
514
590
  ```yml
515
- additional_paths: ['app/assets/**/*', 'vendor/assets/**/*.css', 'Gemfile']
591
+ additional_paths: ['app/assets', 'vendor/assets']
516
592
  ```
517
593
 
518
594
  You can then import these items inside your modules like so:
@@ -533,6 +609,10 @@ Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which
533
609
 
534
610
  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.
535
611
 
612
+ ## Troubleshooting
613
+
614
+ See the doc page for [Troubleshooting](./docs/troubleshooting.md).
615
+
536
616
  ## Contributing
537
617
 
538
618
  [![Code Helpers](https://www.codetriage.com/rails/webpacker/badges/users.svg)](https://www.codetriage.com/rails/webpacker)