webpacker 5.2.1 → 6.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +1 -1
  3. data/.gitignore +2 -0
  4. data/.node-version +1 -1
  5. data/.rubocop.yml +11 -16
  6. data/6_0_upgrade.md +43 -0
  7. data/CHANGELOG.md +25 -0
  8. data/CONTRIBUTING.md +1 -1
  9. data/Gemfile.lock +17 -11
  10. data/README.md +220 -99
  11. data/lib/install/config/webpack/base.js +3 -0
  12. data/lib/install/config/webpack/development.js +2 -2
  13. data/lib/install/config/webpack/production.js +2 -2
  14. data/lib/install/config/webpack/test.js +2 -2
  15. data/lib/install/config/webpacker.yml +8 -37
  16. data/lib/install/javascript/packs/application.css +9 -0
  17. data/lib/install/javascript/packs/application.js +3 -1
  18. data/lib/install/template.rb +33 -19
  19. data/lib/tasks/webpacker.rake +2 -11
  20. data/lib/tasks/webpacker/binstubs.rake +6 -4
  21. data/lib/tasks/webpacker/check_binstubs.rake +4 -4
  22. data/lib/tasks/webpacker/check_yarn.rake +1 -2
  23. data/lib/tasks/webpacker/compile.rake +4 -2
  24. data/lib/tasks/webpacker/info.rake +12 -10
  25. data/lib/tasks/webpacker/install.rake +6 -4
  26. data/lib/tasks/webpacker/verify_install.rake +2 -1
  27. data/lib/tasks/webpacker/yarn_install.rake +9 -1
  28. data/lib/webpacker/commands.rb +1 -1
  29. data/lib/webpacker/compiler.rb +15 -8
  30. data/lib/webpacker/configuration.rb +6 -30
  31. data/lib/webpacker/dev_server_runner.rb +21 -2
  32. data/lib/webpacker/helper.rb +22 -32
  33. data/lib/webpacker/manifest.rb +1 -1
  34. data/lib/webpacker/version.rb +1 -1
  35. data/lib/webpacker/webpack_runner.rb +5 -0
  36. data/package.json +23 -39
  37. data/package/__tests__/config.js +5 -37
  38. data/package/__tests__/development.js +9 -11
  39. data/package/__tests__/env.js +12 -4
  40. data/package/__tests__/production.js +6 -6
  41. data/package/__tests__/staging.js +7 -6
  42. data/package/__tests__/test.js +4 -5
  43. data/package/babel/preset.js +55 -0
  44. data/package/config.js +3 -11
  45. data/package/env.js +8 -2
  46. data/package/environments/__tests__/base.js +15 -47
  47. data/package/environments/base.js +62 -125
  48. data/package/environments/development.js +45 -44
  49. data/package/environments/production.js +63 -68
  50. data/package/environments/test.js +2 -2
  51. data/package/index.js +13 -8
  52. data/package/rules/babel.js +9 -7
  53. data/package/rules/coffee.js +6 -0
  54. data/package/rules/erb.js +15 -0
  55. data/package/rules/file.js +19 -19
  56. data/package/rules/index.js +15 -18
  57. data/package/rules/less.js +22 -0
  58. data/package/rules/sass.js +12 -9
  59. data/package/rules/svg.js +20 -0
  60. data/package/utils/get_style_rule.js +26 -36
  61. data/package/utils/helpers.js +26 -35
  62. data/test/compiler_test.rb +0 -12
  63. data/test/configuration_test.rb +1 -32
  64. data/test/dev_server_runner_test.rb +24 -5
  65. data/test/engine_rake_tasks_test.rb +39 -0
  66. data/test/helper_test.rb +15 -9
  67. data/test/mounted_app/Rakefile +4 -0
  68. data/test/mounted_app/test/dummy/Rakefile +3 -0
  69. data/test/mounted_app/test/dummy/bin/rails +3 -0
  70. data/test/mounted_app/test/dummy/bin/rake +3 -0
  71. data/test/mounted_app/test/dummy/config.ru +5 -0
  72. data/test/mounted_app/test/dummy/config/application.rb +10 -0
  73. data/test/mounted_app/test/dummy/config/environment.rb +3 -0
  74. data/test/mounted_app/test/dummy/config/webpacker.yml +75 -0
  75. data/test/mounted_app/test/dummy/package.json +7 -0
  76. data/test/rake_tasks_test.rb +1 -10
  77. data/test/test_app/config/webpacker.yml +1 -25
  78. data/test/test_app/config/webpacker_public_root.yml +0 -1
  79. data/test/test_app/public/packs/manifest.json +17 -13
  80. data/test/test_app/some.config.js +0 -0
  81. data/test/webpack_runner_test.rb +9 -3
  82. data/webpacker.gemspec +1 -1
  83. data/yarn.lock +1858 -4915
  84. metadata +44 -90
  85. data/.travis.yml +0 -43
  86. data/docs/assets.md +0 -119
  87. data/docs/cloud9.md +0 -310
  88. data/docs/css.md +0 -308
  89. data/docs/deployment.md +0 -130
  90. data/docs/docker.md +0 -68
  91. data/docs/engines.md +0 -213
  92. data/docs/env.md +0 -63
  93. data/docs/es6.md +0 -72
  94. data/docs/folder-structure.md +0 -66
  95. data/docs/integrations.md +0 -220
  96. data/docs/misc.md +0 -23
  97. data/docs/props.md +0 -223
  98. data/docs/target.md +0 -22
  99. data/docs/testing.md +0 -136
  100. data/docs/troubleshooting.md +0 -158
  101. data/docs/typescript.md +0 -190
  102. data/docs/v4-upgrade.md +0 -142
  103. data/docs/webpack-dev-server.md +0 -92
  104. data/docs/webpack.md +0 -364
  105. data/docs/yarn.md +0 -23
  106. data/lib/install/angular.rb +0 -23
  107. data/lib/install/coffee.rb +0 -25
  108. data/lib/install/config/.browserslistrc +0 -1
  109. data/lib/install/config/babel.config.js +0 -70
  110. data/lib/install/config/postcss.config.js +0 -12
  111. data/lib/install/config/webpack/environment.js +0 -3
  112. data/lib/install/elm.rb +0 -39
  113. data/lib/install/erb.rb +0 -25
  114. data/lib/install/examples/angular/hello_angular.js +0 -7
  115. data/lib/install/examples/angular/hello_angular/app/app.component.ts +0 -9
  116. data/lib/install/examples/angular/hello_angular/app/app.module.ts +0 -16
  117. data/lib/install/examples/angular/hello_angular/index.ts +0 -8
  118. data/lib/install/examples/angular/hello_angular/polyfills.ts +0 -73
  119. data/lib/install/examples/coffee/hello_coffee.coffee +0 -4
  120. data/lib/install/examples/elm/Main.elm +0 -55
  121. data/lib/install/examples/elm/hello_elm.js +0 -16
  122. data/lib/install/examples/erb/hello_erb.js.erb +0 -6
  123. data/lib/install/examples/react/babel.config.js +0 -87
  124. data/lib/install/examples/react/hello_react.jsx +0 -26
  125. data/lib/install/examples/react/tsconfig.json +0 -21
  126. data/lib/install/examples/stimulus/application.js +0 -1
  127. data/lib/install/examples/stimulus/controllers/hello_controller.js +0 -18
  128. data/lib/install/examples/stimulus/controllers/index.js +0 -9
  129. data/lib/install/examples/svelte/app.svelte +0 -11
  130. data/lib/install/examples/svelte/hello_svelte.js +0 -20
  131. data/lib/install/examples/typescript/hello_typescript.ts +0 -4
  132. data/lib/install/examples/typescript/tsconfig.json +0 -24
  133. data/lib/install/examples/vue/app.vue +0 -22
  134. data/lib/install/examples/vue/hello_vue.js +0 -72
  135. data/lib/install/loaders/coffee.js +0 -6
  136. data/lib/install/loaders/elm.js +0 -25
  137. data/lib/install/loaders/erb.js +0 -11
  138. data/lib/install/loaders/svelte.js +0 -9
  139. data/lib/install/loaders/vue.js +0 -6
  140. data/lib/install/react.rb +0 -18
  141. data/lib/install/stimulus.rb +0 -12
  142. data/lib/install/svelte.rb +0 -29
  143. data/lib/install/typescript.rb +0 -39
  144. data/lib/install/vue.rb +0 -49
  145. data/lib/tasks/installers.rake +0 -42
  146. data/package/config_types/__tests__/config_list.js +0 -118
  147. data/package/config_types/__tests__/config_object.js +0 -43
  148. data/package/config_types/config_list.js +0 -75
  149. data/package/config_types/config_object.js +0 -55
  150. data/package/config_types/index.js +0 -7
  151. data/package/rules/module.css.js +0 -3
  152. data/package/rules/module.sass.js +0 -8
  153. data/package/rules/node_modules.js +0 -22
  154. data/package/utils/__tests__/deep_assign.js +0 -32
  155. data/package/utils/__tests__/deep_merge.js +0 -10
  156. data/package/utils/__tests__/get_style_rule.js +0 -65
  157. data/package/utils/__tests__/objectify.js +0 -9
  158. data/package/utils/deep_assign.js +0 -22
  159. data/package/utils/deep_merge.js +0 -22
  160. data/package/utils/objectify.js +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8190ac2a707c460f76018576f61a78d1a9f42da441d123619f708a18e3a120b
4
- data.tar.gz: 6311e214c6fa99598a2f530b4950c6c3fbf0ed4cc313d99c16bff9515444adc1
3
+ metadata.gz: 19faa9561fccec8279b1d8031c2a386c44554ba0f24acc048ec4856853900fc5
4
+ data.tar.gz: a10901426f6b8ff524c243ddc21392ada8cf189fd85d63d3a6b558cd71b4237f
5
5
  SHA512:
6
- metadata.gz: c9a5a34f8a7fd156f6e31e6102439c19ce5247600901aab060fde1f929da8a4164379a439a8b67275ece33114a09f1fee3bb8401aede13c7369b51b9cd925a61
7
- data.tar.gz: e05b9e78d6c2b846b3ce3edd311fcca9b883137490a04be9c5cdce8cc5115efb1c5f9bcf8c1fdf6593417047d4ec9669de49975dc75088e449965577c5cedf4a
6
+ metadata.gz: cda09944b075aa8da83a0c568f656d63b040b4c110b5a87f1e5962b60c24e63d70020a4648c1133674611a64178f048ad081128ea891df1950f82957e7a2a5da
7
+ data.tar.gz: aa72ec1ac73614d32405ca4dfbfbd05e910167599b30e9ed91b3360bdbc0ba12db577fb55096942f6e1a468e21e1e05ccf8bfc5b80596fb3f68e187a73fe1a63
@@ -1,5 +1,5 @@
1
1
  module.exports = {
2
- extends: 'airbnb',
2
+ extends: ['airbnb', 'prettier'],
3
3
  rules: {
4
4
  'comma-dangle': ['error', 'never'],
5
5
  'import/no-unresolved': 'off',
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  /.bundle
2
2
  /pkg
3
+ /test/mounted_app/test/dummy/log
3
4
  /test/test_app/log
4
5
  node_modules
5
6
  .byebug_history
@@ -9,3 +10,4 @@ yarn-error.log*
9
10
  .yarn-integrity
10
11
  /log
11
12
  gemfiles/*.lock
13
+ .DS_Store
@@ -1 +1 @@
1
- 10.17.0
1
+ 10.22.1
@@ -1,23 +1,18 @@
1
1
  require: rubocop-performance
2
2
  AllCops:
3
- TargetRubyVersion: 2.2
3
+ TargetRubyVersion: 2.4
4
4
  # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
5
5
  # to ignore them, so only the ones explicitly set in this file are enabled.
6
6
  DisabledByDefault: true
7
7
  Exclude:
8
- - 'lib/install/templates/**'
9
- - 'vendor/**/*'
10
- - 'node_modules/**/*'
8
+ - "lib/install/templates/**"
9
+ - "vendor/**/*"
10
+ - "node_modules/**/*"
11
11
 
12
12
  # Prefer &&/|| over and/or.
13
13
  Style/AndOr:
14
14
  Enabled: true
15
15
 
16
- # Do not use braces for hash literals when they are the last argument of a
17
- # method call.
18
- Style/BracesAroundHashParameters:
19
- Enabled: true
20
-
21
16
  # Align `when` with `case`.
22
17
  Layout/CaseIndentation:
23
18
  Enabled: true
@@ -50,7 +45,11 @@ Style/HashSyntax:
50
45
  # extra level of indentation.
51
46
  Layout/IndentationConsistency:
52
47
  Enabled: true
53
- EnforcedStyle: rails
48
+ EnforcedStyle: indented_internal_methods
49
+
50
+ # Detect hard tabs, no hard tabs.
51
+ Layout/IndentationStyle:
52
+ Enabled: true
54
53
 
55
54
  # Two spaces, no tabs (for indentation).
56
55
  Layout/IndentationWidth:
@@ -98,12 +97,8 @@ Style/StringLiterals:
98
97
  Enabled: true
99
98
  EnforcedStyle: double_quotes
100
99
 
101
- # Detect hard tabs, no hard tabs.
102
- Layout/Tab:
103
- Enabled: true
104
-
105
100
  # Blank lines should not have any spaces.
106
- Layout/TrailingBlankLines:
101
+ Layout/TrailingEmptyLines:
107
102
  Enabled: true
108
103
 
109
104
  # No trailing whitespace.
@@ -111,7 +106,7 @@ Layout/TrailingWhitespace:
111
106
  Enabled: true
112
107
 
113
108
  # Use quotes for string literals when they are enough.
114
- Style/UnneededPercentQ:
109
+ Style/RedundantPercentQ:
115
110
  Enabled: true
116
111
 
117
112
  # Align `end` with the matching keyword or starting expression except for
@@ -0,0 +1,43 @@
1
+ # To webpacker v6 from v5
2
+
3
+ This guide aims to help you migrating to webpacker 6. If you are using
4
+ vanilla webpacker install then hopefully, the upgrade should be really
5
+ straightforward.
6
+
7
+ ## Preparation
8
+
9
+ - Rename `config/webpack` to `config/webpack_old`
10
+ - Rename `config/webpacker.yml` to `config/webpacker_old.yml`
11
+ - Upgrade webpacker
12
+
13
+ ```ruby
14
+ # Gemfile
15
+ gem 'webpacker', '~> 6.x'
16
+ ```
17
+
18
+ ```
19
+ bundle
20
+ ```
21
+
22
+ ```bash
23
+ yarn add @rails/webpacker@next
24
+ ```
25
+
26
+ ```bash
27
+ bundle exec rails webpacker:install
28
+ ```
29
+
30
+ - Change `javascript_pack_tag` and `stylesheet_pack_tag` to `javascript_packs_with_chunks_tag` and
31
+ `stylesheet_packs_with_chunks_tag`
32
+
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
34
+
35
+ - Copy over any custom webpack config from `config/webpack_old`
36
+
37
+ ```js
38
+ // config/webpack/base.js
39
+ const { webpackConfig, merge } = require('@rails/webpacker')
40
+ const customConfig = require('./custom')
41
+
42
+ module.exports = merge(webpackConfig, customConfig)
43
+ ```
@@ -2,6 +2,31 @@
2
2
 
3
3
  **Please note that Webpacker 4.1.0 has an installer bug. Please use 4.2.0 or above**
4
4
 
5
+ ## [[6.0.0]](https://github.com/rails/webpacker/compare/v5.1.1...master) - 2021-TBD
6
+
7
+ - `node_modules` will no longer be compiled by default. This primarily fixes [rails issue #35501](https://github.com/rails/rails/issues/35501) as well as [numerous other webpacker issues](https://github.com/rails/webpacker/issues/2131#issuecomment-581618497). The disabled loader can still be required explicitly via:
8
+
9
+ ```js
10
+ const nodeModules = require('@rails/webpacker/rules/node_modules.js')
11
+ environment.loaders.append('nodeModules', nodeModules)
12
+ ```
13
+
14
+ - If you have added `environment.loaders.delete('nodeModules')` to your `environment.js`, this must be removed or you will receive an error (`Item nodeModules not found`).
15
+ - The install task will now set the `extract_css` default to `true` in all environments and generate a separate `application.css` file for the default `application` pack, as supported by multiple files per entry introduced in 5.0.0. [#2608](https://github.com/rails/webpacker/pull/2608)
16
+ - Webpacker's wrapper to the `splitChunks()` API will now default `runtimeChunk: 'single'` which will help prevent potential issues when using multiple entry points per page [#2708](https://github.com/rails/webpacker/pull/2708).
17
+ - Changes `@babel/preset-env` modules option to `'auto'` per recommendation in the Babel docs [#2709](https://github.com/rails/webpacker/pull/2709)
18
+ - Adds experimental Yarn 2 support. Note you must manually set `nodeLinker: node-modules` in your `.yarnrc.yml`.
19
+
20
+ ### Breaking changes
21
+
22
+ - Simple webpack config
23
+ - Removed integration installers
24
+ - Splitchunks enabled by default
25
+ - CSS extraction enabled by default
26
+ - Optional CSS support
27
+
28
+ Please see upgrade [guide](./6_0_upgrade.md)
29
+
5
30
  ## [[5.2.1]](https://github.com/rails/webpacker/compare/v5.2.0...5.2.1) - 2020-08-17
6
31
 
7
32
  - Revert [#1311](https://github.com/rails/webpacker/pull/1311).
@@ -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 Travis CI 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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- webpacker (5.2.1)
4
+ webpacker (6.0.0.beta)
5
5
  activesupport (>= 5.2)
6
6
  rack-proxy (>= 0.6.1)
7
7
  railties (>= 5.2)
@@ -75,7 +75,6 @@ GEM
75
75
  activesupport (>= 4.2.0)
76
76
  i18n (1.8.5)
77
77
  concurrent-ruby (~> 1.0)
78
- jaro_winkler (1.5.4)
79
78
  loofah (2.6.0)
80
79
  crass (~> 1.0.2)
81
80
  nokogiri (>= 1.5.9)
@@ -92,7 +91,7 @@ GEM
92
91
  nokogiri (1.10.10)
93
92
  mini_portile2 (~> 2.4.0)
94
93
  parallel (1.19.2)
95
- parser (2.7.1.4)
94
+ parser (2.7.2.0)
96
95
  ast (~> 2.4.1)
97
96
  rack (2.2.3)
98
97
  rack-proxy (0.6.5)
@@ -127,15 +126,22 @@ GEM
127
126
  thor (>= 0.20.3, < 2.0)
128
127
  rainbow (3.0.0)
129
128
  rake (13.0.1)
130
- rubocop (0.68.1)
131
- jaro_winkler (~> 1.5.1)
129
+ regexp_parser (1.8.2)
130
+ rexml (3.2.4)
131
+ rubocop (0.93.1)
132
132
  parallel (~> 1.10)
133
- parser (>= 2.5, != 2.5.1.1)
133
+ parser (>= 2.7.1.5)
134
134
  rainbow (>= 2.2.2, < 4.0)
135
+ regexp_parser (>= 1.8)
136
+ rexml
137
+ rubocop-ast (>= 0.6.0)
135
138
  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
+ unicode-display_width (>= 1.4.0, < 2.0)
140
+ rubocop-ast (0.8.0)
141
+ parser (>= 2.7.1.5)
142
+ rubocop-performance (1.8.1)
143
+ rubocop (>= 0.87.0)
144
+ rubocop-ast (>= 0.4.0)
139
145
  ruby-progressbar (1.10.1)
140
146
  semantic_range (2.3.0)
141
147
  sprockets (4.0.2)
@@ -149,7 +155,7 @@ GEM
149
155
  thread_safe (0.3.6)
150
156
  tzinfo (1.2.7)
151
157
  thread_safe (~> 0.1)
152
- unicode-display_width (1.5.0)
158
+ unicode-display_width (1.7.0)
153
159
  websocket-driver (0.7.3)
154
160
  websocket-extensions (>= 0.1.0)
155
161
  websocket-extensions (0.1.5)
@@ -165,7 +171,7 @@ DEPENDENCIES
165
171
  rack-proxy
166
172
  rails
167
173
  rake (>= 11.1)
168
- rubocop (< 0.69)
174
+ rubocop (= 0.93.1)
169
175
  rubocop-performance
170
176
  semantic_range
171
177
  webpacker!
data/README.md CHANGED
@@ -1,11 +1,15 @@
1
1
  # Webpacker
2
2
 
3
- [![Build Status](https://travis-ci.org/rails/webpacker.svg?branch=master)](https://travis-ci.org/rails/webpacker)
3
+ [![Ruby specs](https://github.com/rails/webpacker/workflows/Ruby%20specs/badge.svg)](https://github.com/rails/webpacker/actions)
4
+ [![Jest specs](https://github.com/rails/webpacker/workflows/Jest%20specs/badge.svg)](https://github.com/rails/webpacker/actions)
5
+ [![Rubocop](https://github.com/rails/webpacker/workflows/Rubocop/badge.svg)](https://github.com/rails/webpacker/actions)
6
+ [![JS lint](https://github.com/rails/webpacker/workflows/JS%20lint/badge.svg)](https://github.com/rails/webpacker/actions)
7
+
4
8
  [![node.js](https://img.shields.io/badge/node-%3E%3D%2010.17.0-brightgreen.svg)](https://www.npmjs.com/package/@rails/webpacker)
5
9
  [![Gem](https://img.shields.io/gem/v/webpacker.svg)](https://rubygems.org/gems/webpacker)
6
10
 
7
11
  Webpacker makes it easy to use the JavaScript pre-processor and bundler
8
- [webpack 4.x.x+](https://webpack.js.org/)
12
+ [webpack 5.x.x+](https://webpack.js.org/)
9
13
  to manage application-like JavaScript in Rails. It coexists with the asset pipeline,
10
14
  as the primary purpose for webpack is app-like JavaScript, not images, CSS, or
11
15
  even JavaScript Sprinkles (that all continues to live in app/assets).
@@ -13,7 +17,7 @@ even JavaScript Sprinkles (that all continues to live in app/assets).
13
17
  However, it is possible to use Webpacker for CSS, images and fonts assets as well,
14
18
  in which case you may not even need the asset pipeline. This is mostly relevant when exclusively using component-based JavaScript frameworks.
15
19
 
16
- **NOTE:** The master branch now hosts the code for v5.x.x. Please refer to [4-x-stable](https://github.com/rails/webpacker/tree/4-x-stable) branch for 4.x documentation.
20
+ **NOTE:** The master branch now hosts the code for v6.x.x. Please refer to [5-x-stable](https://github.com/rails/webpacker/tree/5-x-stable) branch for 5.x documentation.
17
21
 
18
22
  <!-- START doctoc generated TOC please keep comment here to allow auto update -->
19
23
  <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
@@ -28,16 +32,6 @@ in which case you may not even need the asset pipeline. This is mostly relevant
28
32
  - [Webpack Configuration](#webpack-configuration)
29
33
  - [Custom Rails environments](#custom-rails-environments)
30
34
  - [Upgrading](#upgrading)
31
- - [Integrations](#integrations)
32
- - [React](./docs/integrations.md#react)
33
- - [Angular with TypeScript](./docs/integrations.md#angular-with-typescript)
34
- - [Vue](./docs/integrations.md#vue)
35
- - [Elm](./docs/integrations.md#elm)
36
- - [Stimulus](./docs/integrations.md#stimulus)
37
- - [Svelte](./docs/integrations.md#svelte)
38
- - [Typescript](./docs/typescript.md)
39
- - [CoffeeScript](./docs/integrations.md#coffeescript)
40
- - [Erb](./docs/integrations.md#erb)
41
35
  - [Paths](#paths)
42
36
  - [Resolved](#resolved)
43
37
  - [Watched](#watched)
@@ -52,23 +46,28 @@ in which case you may not even need the asset pipeline. This is mostly relevant
52
46
 
53
47
  - Ruby 2.4+
54
48
  - Rails 5.2+
55
- - Node.js 10.17.0+
49
+ - Node.js 10.22.1+ || 12+ || 14+
56
50
  - Yarn 1.x+
57
51
 
58
52
  ## Features
59
53
 
60
- - [webpack 4.x.x](https://webpack.js.org/)
54
+ - [webpack 5.x.x](https://webpack.js.org/)
61
55
  - ES6 with [babel](https://babeljs.io/)
62
56
  - Automatic code splitting using multiple entry points
63
- - Stylesheets - Sass and CSS
64
- - Images and fonts
65
- - PostCSS - Auto-Prefixer
66
57
  - Asset compression, source-maps, and minification
67
58
  - CDN support
68
- - React, Angular, Elm and Vue support out-of-the-box
69
59
  - Rails view helpers
70
60
  - Extensible and configurable
71
61
 
62
+ ### Optional support\*
63
+
64
+ _requires extra packages to be installed_
65
+
66
+ - Stylesheets - SASS, LESS and CSS, PostCSS
67
+ - Coffeescript
68
+ - Typescript
69
+ - React
70
+
72
71
  ## Installation
73
72
 
74
73
  You can either add Webpacker during setup of a new Rails 5.1+ application
@@ -83,12 +82,11 @@ Or add it to your `Gemfile`:
83
82
 
84
83
  ```ruby
85
84
  # Gemfile
86
- gem 'webpacker', '~> 5.x'
85
+ gem 'webpacker', '~> 6.x'
87
86
 
88
87
  # OR if you prefer to use master
89
88
  gem 'webpacker', git: 'https://github.com/rails/webpacker.git'
90
89
  yarn add https://github.com/rails/webpacker.git
91
- yarn add core-js regenerator-runtime
92
90
  ```
93
91
 
94
92
  Finally, run the following to install Webpacker:
@@ -131,19 +129,11 @@ app/javascript:
131
129
  └── logo.svg
132
130
  ```
133
131
 
134
- In `/packs/application.js`, include this at the top of the file:
135
-
136
- ```js
137
- import 'core-js/stable'
138
- import 'regenerator-runtime/runtime'
139
- ```
140
-
141
- You can then link the JavaScript pack in Rails views using the `javascript_pack_tag` helper.
142
- If you have styles imported in your pack file, you can link them by using `stylesheet_pack_tag`:
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`:
143
133
 
144
134
  ```erb
145
- <%= javascript_pack_tag 'application' %>
146
- <%= stylesheet_pack_tag 'application' %>
135
+ <%= javascript_packs_with_chunks_tag 'application' %>
136
+ <%= stylesheet_packs_with_chunks_tag 'application' %>
147
137
  ```
148
138
 
149
139
  If you want to link a static asset for `<link rel="prefetch">` or `<img />` tag, you
@@ -154,31 +144,6 @@ can use the `asset_pack_path` helper:
154
144
  <img src="<%= asset_pack_path 'images/logo.svg' %>" />
155
145
  ```
156
146
 
157
- If you are using new webpack 4 split chunks API, then consider using `javascript_packs_with_chunks_tag` helper, which creates html
158
- tags for a pack and all the dependent chunks.
159
-
160
- ```erb
161
- <%= javascript_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
162
-
163
- <script src="/packs/vendor-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
164
- <script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
165
- <script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
166
- <script src="/packs/map~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
167
- <script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
168
- ```
169
-
170
- **Important:** Pass all your pack names when using `javascript_packs_with_chunks_tag`
171
- helper otherwise you will get duplicated chunks on the page.
172
-
173
- ```erb
174
- <%# DO %>
175
- <%= javascript_packs_with_chunks_tag 'calendar', 'map' %>
176
-
177
- <%# DON'T %>
178
- <%= javascript_packs_with_chunks_tag 'calendar' %>
179
- <%= javascript_packs_with_chunks_tag 'map' %>
180
- ```
181
-
182
147
  **Note:** In order for your styles or static assets files to be available in your view,
183
148
  you would need to link them in your "pack" or entry file.
184
149
 
@@ -244,7 +209,201 @@ WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server
244
209
 
245
210
  ### Webpack Configuration
246
211
 
247
- See [docs/webpack](docs/webpack.md) for modifying webpack configuration and loaders.
212
+ Webpacker gives you a default set of configuration files for test, development and
213
+ production environments in `config/webpack/*.js`. You can configure each individual
214
+ environment in their respective files or configure them all in the base
215
+ `config/webpack/environment.js` file.
216
+
217
+ By default, you don't need to make any changes to `config/webpack/*.js`
218
+ files since it's all standard production-ready configuration. However,
219
+ if you do need to customize or add a new loader, this is where you would go.
220
+
221
+ Here is how you can modify webpack configuration:
222
+
223
+ You might add separate files to keep your code more organized.
224
+
225
+ ```js
226
+ // config/webpack/custom.js
227
+ module.exports = {
228
+ resolve: {
229
+ alias: {
230
+ jquery: 'jquery/src/jquery',
231
+ vue: 'vue/dist/vue.js',
232
+ React: 'react',
233
+ ReactDOM: 'react-dom',
234
+ vue_resource: 'vue-resource/dist/vue-resource'
235
+ }
236
+ }
237
+ }
238
+ ```
239
+
240
+ Then `require` this file in your `config/webpack/base.js`:
241
+
242
+ ```js
243
+ // config/webpack/base.js
244
+ const { webpackConfig, merge } = require('@rails/webpacker')
245
+ const customConfig = require('./custom')
246
+
247
+ module.exports = merge(webpackConfig, customConfig)
248
+ ```
249
+
250
+ If you need access to configs within Webpacker's configuration,
251
+ you can import them like so:
252
+
253
+ ```js
254
+ // config/webpack/base.js
255
+ const { webpackConfig } = require('@rails/webpacker')
256
+
257
+ console.log(webpackConfig.output_path)
258
+ console.log(webpackConfig.source_path)
259
+ ```
260
+
261
+ ### Integrations
262
+
263
+ 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,
266
+
267
+ **Coffeescript**
268
+
269
+ ```
270
+ yarn add coffeescript coffee-loader
271
+ ```
272
+
273
+ **Typescript**
274
+
275
+ ```
276
+ yarn add typescript @babel/preset-typescript
277
+ ```
278
+
279
+ Add tsconfig.json
280
+
281
+ ```json
282
+ {
283
+ "compilerOptions": {
284
+ "declaration": false,
285
+ "emitDecoratorMetadata": true,
286
+ "experimentalDecorators": true,
287
+ "lib": ["es6", "dom"],
288
+ "module": "es6",
289
+ "moduleResolution": "node",
290
+ "baseUrl": ".",
291
+ "paths": {
292
+ "*": ["node_modules/*", "app/javascript/*"]
293
+ },
294
+ "sourceMap": true,
295
+ "target": "es5",
296
+ "noEmit": true
297
+ },
298
+ "exclude": ["**/*.spec.ts", "node_modules", "vendor", "public"],
299
+ "compileOnSave": false
300
+ }
301
+ ```
302
+
303
+ #### CSS
304
+
305
+ To enable CSS support in your application, add following packages,
306
+
307
+ ```
308
+ yarn add css-loader mini-css-extract-plugin css-minimizer-webpack-plugin
309
+ ```
310
+
311
+ optionally, add css extension to webpack config for easy resolution
312
+
313
+ ```js
314
+ // config/webpack/base.js
315
+ const { webpackConfig, merge } = require('@rails/webpacker')
316
+ const customConfig = {
317
+ resolve: {
318
+ extensions: ['.css']
319
+ }
320
+ }
321
+
322
+ module.exports = merge(webpackConfig, customConfig)
323
+ ```
324
+
325
+ To enable postcss, sass or less support, add css support first and
326
+ then add the relevant pre-processors:
327
+
328
+ #### Postcss
329
+
330
+ ```
331
+ yarn add postcss-loader
332
+ ```
333
+
334
+ #### Sass
335
+
336
+ ```
337
+ yarn add sass-loader
338
+ ```
339
+
340
+ #### Less
341
+
342
+ ```
343
+ yarn add less-loader
344
+ ```
345
+
346
+ #### React
347
+
348
+ React is supported and you just need to add relevant packages,
349
+
350
+ ```
351
+ yarn add react react-dom @babel/preset-react
352
+ ```
353
+
354
+ if you are using typescript, update your `tsconfig.json`
355
+
356
+ ```json
357
+ {
358
+ "compilerOptions": {
359
+ "declaration": false,
360
+ "emitDecoratorMetadata": true,
361
+ "experimentalDecorators": true,
362
+ "lib": ["es6", "dom"],
363
+ "module": "es6",
364
+ "moduleResolution": "node",
365
+ "sourceMap": true,
366
+ "target": "es5",
367
+ "jsx": "react",
368
+ "noEmit": true
369
+ },
370
+ "exclude": ["**/*.spec.ts", "node_modules", "vendor", "public"],
371
+ "compileOnSave": false
372
+ }
373
+ ```
374
+
375
+ #### Other frameworks
376
+
377
+ Please follow webpack integration guide for relevant framework or library,
378
+
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,
384
+
385
+ ```js
386
+ // config/webpack/rules/vue.js
387
+ const VueLoaderPlugin = require('vue-loader/lib/plugin')
388
+
389
+ module.exports = {
390
+ module: {
391
+ rules: [
392
+ {
393
+ test: /\.vue$/,
394
+ loader: 'vue-loader'
395
+ }
396
+ ]
397
+ },
398
+ plugins: [new VueLoaderPlugin()]
399
+ }
400
+
401
+ // config/webpack/base.js
402
+ const { webpackConfig, merge } = require('@rails/webpacker')
403
+ const vueConfig = require('./rules/vue')
404
+
405
+ module.exports = merge(webpackConfig, vueConfig)
406
+ ```
248
407
 
249
408
  ### Custom Rails environments
250
409
 
@@ -301,7 +460,7 @@ You can run following commands to upgrade Webpacker to the latest stable version
301
460
 
302
461
  ```bash
303
462
  bundle update webpacker
304
- rails webpacker:binstubs
463
+ rails webpacker:install
305
464
  yarn upgrade @rails/webpacker --latest
306
465
  yarn upgrade webpack-dev-server --latest
307
466
 
@@ -309,24 +468,6 @@ yarn upgrade webpack-dev-server --latest
309
468
  yarn add @rails/webpacker@next
310
469
  ```
311
470
 
312
- ## Integrations
313
-
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`.
315
-
316
- Included install integrations:
317
-
318
- - [React](./docs/integrations.md#React)
319
- - [Angular with TypeScript](./docs/integrations.md#Angular-with-TypeScript)
320
- - [Vue](./docs/integrations.md#Vue)
321
- - [Elm](./docs/integrations.md#Elm)
322
- - [Svelte](./docs/integrations.md#Svelte)
323
- - [Stimulus](./docs/integrations.md#Stimulus)
324
- - [CoffeeScript](./docs/integrations.md#CoffeeScript)
325
- - [Typescript](./docs/typescript.md)
326
- - [Erb](./docs/integrations.md#Erb)
327
-
328
- See [Integrations](./docs/integrations.md) for further details.
329
-
330
471
  ## Paths
331
472
 
332
473
  By default, Webpacker ships with simple conventions for where the JavaScript
@@ -362,7 +503,7 @@ development:
362
503
 
363
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.
364
505
 
365
- ### Resolved
506
+ ### Additional paths
366
507
 
367
508
  If you are adding Webpacker to an existing app that has most of the assets inside
368
509
  `app/assets` or inside an engine, and you want to share that
@@ -371,7 +512,7 @@ option available in `config/webpacker.yml`. This lets you
371
512
  add additional paths that webpack should lookup when resolving modules:
372
513
 
373
514
  ```yml
374
- additional_paths: ['app/assets']
515
+ additional_paths: ['app/assets/**/*', 'vendor/assets/**/*.css', 'Gemfile']
375
516
  ```
376
517
 
377
518
  You can then import these items inside your modules like so:
@@ -392,26 +533,6 @@ Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which
392
533
 
393
534
  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
535
 
395
- ## Docs
396
-
397
- - [Development](https://github.com/rails/webpacker#development)
398
- - [Webpack](./docs/webpack.md)
399
- - [Webpack-dev-server](./docs/webpack-dev-server.md)
400
- - [Environment Variables](./docs/env.md)
401
- - [Folder Structure](./docs/folder-structure.md)
402
- - [Assets](./docs/assets.md) - [CSS, Sass and SCSS](./docs/css.md) - [ES6](./docs/es6.md), [Target browsers](./docs/target.md)
403
- - [Props](./docs/props.md)
404
- - [Typescript](./docs/typescript.md)
405
- - [Yarn](./docs/yarn.md)
406
- - [Misc](./docs/misc.md)
407
- - [Deployment](./docs/deployment.md)
408
- - [Docker](./docs/docker.md)
409
- - [Using in Rails engines](./docs/engines.md)
410
- - [Webpacker on Cloud9](./docs/cloud9.md)
411
- - [Testing](./docs/testing.md)
412
- - [Troubleshooting](./docs/troubleshooting.md)
413
- - [v3 to v4 Upgrade Guide](./docs/v4-upgrade.md)
414
-
415
536
  ## Contributing
416
537
 
417
538
  [![Code Helpers](https://www.codetriage.com/rails/webpacker/badges/users.svg)](https://www.codetriage.com/rails/webpacker)