webpacker 6.0.0.beta.2 → 6.0.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -18
  3. data/Gemfile.lock +1 -1
  4. data/README.md +96 -219
  5. data/docs/assets.md +135 -0
  6. data/docs/cloud9.md +310 -0
  7. data/docs/css.md +303 -0
  8. data/docs/deployment.md +148 -0
  9. data/docs/docker.md +68 -0
  10. data/docs/engines.md +213 -0
  11. data/docs/env.md +68 -0
  12. data/docs/es6.md +72 -0
  13. data/docs/folder-structure.md +66 -0
  14. data/docs/integrations.md +220 -0
  15. data/docs/misc.md +23 -0
  16. data/docs/props.md +187 -0
  17. data/docs/react.md +183 -0
  18. data/docs/target.md +22 -0
  19. data/docs/testing.md +147 -0
  20. data/docs/troubleshooting.md +158 -0
  21. data/docs/typescript.md +190 -0
  22. data/docs/v4-upgrade.md +142 -0
  23. data/docs/webpack-dev-server.md +94 -0
  24. data/docs/webpack.md +315 -0
  25. data/docs/yarn.md +23 -0
  26. data/lib/install/examples/vue3/app.vue +27 -0
  27. data/lib/install/examples/vue3/hello_vue.js +15 -0
  28. data/lib/install/javascript/packs/application.js +1 -3
  29. data/lib/webpacker/compiler.rb +2 -8
  30. data/lib/webpacker/version.rb +1 -1
  31. data/package.json +1 -1
  32. data/package/babel/preset-react.js +62 -0
  33. data/package/babel/preset.js +13 -24
  34. data/package/environments/__tests__/base.js +1 -1
  35. data/package/environments/base.js +19 -19
  36. data/package/environments/production.js +30 -28
  37. data/package/index.js +2 -7
  38. data/package/rules/coffee.js +5 -5
  39. data/package/rules/erb.js +3 -5
  40. data/package/rules/file.js +3 -5
  41. data/package/rules/index.js +17 -9
  42. data/package/rules/less.js +10 -14
  43. data/package/rules/sass.js +9 -13
  44. data/package/rules/svg.js +23 -0
  45. data/package/utils/get_style_rule.js +31 -27
  46. data/package/utils/helpers.js +0 -23
  47. metadata +29 -7
  48. data/6_0_upgrade.md +0 -43
  49. data/package/rules/raw.js +0 -5
  50. data/package/rules/stylus.js +0 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70198a585cf22360094497e860a23dcd172c7926820eaa905b00eaf15c997010
4
- data.tar.gz: a1ff9f0cc031d1fffc69813b071b10947aa1648fbedaee826be547bd03adcdc2
3
+ metadata.gz: c5808c11756423a2f910b9aa3675b5d85c94c5cae43a2db1c5c726588bb70cc7
4
+ data.tar.gz: f1b92f83b8d9f06a136c2df4116144b5a70bf74c7ab5c426fc90900f18f8de6a
5
5
  SHA512:
6
- metadata.gz: 2e16cfe7311345f9e2af7e4b821ada9acdaff357ff64cbbbebf038a43199dcafa3b82c403bec1f9ab182ff456efd9ff14eb9756b4edbd76c68beba3cf8543cdc
7
- data.tar.gz: de893725da86a372346c6c552a49a4efb078e24343e16a173b6d51230dc2ccb8bc26d5fbf8726d6d8f8d1a7277eea81d3ed29a06c76998db98cb5970c040bcb0
6
+ metadata.gz: c8a10749bc365d1be38d214ab5cedc921ba5dc437193d2f0bf6da18a0e17650a7b35887fd340356de6f5476e388279f58324345685bfe848e2bcb26dfccbaf7a
7
+ data.tar.gz: 4106137abde49ccda533e7441d0e751f1540a4e175b8f392f486a9eea152083114fabd357db03dd57b9a2a2fe5774563a4cc6f7cf04b78c027b052190bd34d04
@@ -2,31 +2,19 @@
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
5
+ ## [[6.0.0]](https://github.com/rails/webpacker/compare/v5.1.1...v6.0.0) - 2020-TBD
6
6
 
7
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
8
  ```js
10
9
  const nodeModules = require('@rails/webpacker/rules/node_modules.js')
11
10
  environment.loaders.append('nodeModules', nodeModules)
12
11
  ```
13
-
14
12
  - 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)
13
+ - 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
14
  - 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
15
  - Changes `@babel/preset-env` modules option to `'auto'` per recommendation in the Babel docs [#2709](https://github.com/rails/webpacker/pull/2709)
18
16
  - Adds experimental Yarn 2 support. Note you must manually set `nodeLinker: node-modules` in your `.yarnrc.yml`.
19
17
 
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
-
30
18
  ## [[5.2.1]](https://github.com/rails/webpacker/compare/v5.2.0...5.2.1) - 2020-08-17
31
19
 
32
20
  - Revert [#1311](https://github.com/rails/webpacker/pull/1311).
@@ -358,7 +346,7 @@ const { environment } = require('@rails/webpacker')
358
346
  // Enable with default config
359
347
  environment.splitChunks()
360
348
  // Configure via a callback
361
- environment.splitChunks((config) =>
349
+ environment.splitChunks(config =>
362
350
  Object.assign({}, config, { optimization: { splitChunks: false } })
363
351
  )
364
352
  ```
@@ -682,9 +670,7 @@ environment.resolvedModules.append('vendor', 'vendor')
682
670
  ```js
683
671
  // Enable css modules with sass loader
684
672
  const sassLoader = environment.loaders.get('sass')
685
- const cssLoader = sassLoader.use.find(
686
- (loader) => loader.loader === 'css-loader'
687
- )
673
+ const cssLoader = sassLoader.use.find(loader => loader.loader === 'css-loader')
688
674
 
689
675
  cssLoader.options = Object.assign({}, cssLoader.options, {
690
676
  modules: true,
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- webpacker (6.0.0.beta.2)
4
+ webpacker (6.0.0.pre.1)
5
5
  activesupport (>= 5.2)
6
6
  rack-proxy (>= 0.6.1)
7
7
  railties (>= 5.2)
data/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  [![Gem](https://img.shields.io/gem/v/webpacker.svg)](https://rubygems.org/gems/webpacker)
10
10
 
11
11
  Webpacker makes it easy to use the JavaScript pre-processor and bundler
12
- [webpack 5.x.x+](https://webpack.js.org/)
12
+ [webpack 4.x.x+](https://webpack.js.org/)
13
13
  to manage application-like JavaScript in Rails. It coexists with the asset pipeline,
14
14
  as the primary purpose for webpack is app-like JavaScript, not images, CSS, or
15
15
  even JavaScript Sprinkles (that all continues to live in app/assets).
@@ -32,6 +32,16 @@ in which case you may not even need the asset pipeline. This is mostly relevant
32
32
  - [Webpack Configuration](#webpack-configuration)
33
33
  - [Custom Rails environments](#custom-rails-environments)
34
34
  - [Upgrading](#upgrading)
35
+ - [Integrations](#integrations)
36
+ - [React](./docs/integrations.md#react)
37
+ - [Angular with TypeScript](./docs/integrations.md#angular-with-typescript)
38
+ - [Vue](./docs/integrations.md#vue)
39
+ - [Elm](./docs/integrations.md#elm)
40
+ - [Stimulus](./docs/integrations.md#stimulus)
41
+ - [Svelte](./docs/integrations.md#svelte)
42
+ - [Typescript](./docs/typescript.md)
43
+ - [CoffeeScript](./docs/integrations.md#coffeescript)
44
+ - [Erb](./docs/integrations.md#erb)
35
45
  - [Paths](#paths)
36
46
  - [Resolved](#resolved)
37
47
  - [Watched](#watched)
@@ -46,28 +56,23 @@ in which case you may not even need the asset pipeline. This is mostly relevant
46
56
 
47
57
  - Ruby 2.4+
48
58
  - Rails 5.2+
49
- - Node.js 10.22.1+ || 12+ || 14+
59
+ - Node.js 10.17.0+ || 12+ || 14+
50
60
  - Yarn 1.x+
51
61
 
52
62
  ## Features
53
63
 
54
- - [webpack 5.x.x](https://webpack.js.org/)
64
+ - [webpack 4.x.x](https://webpack.js.org/)
55
65
  - ES6 with [babel](https://babeljs.io/)
56
66
  - Automatic code splitting using multiple entry points
67
+ - Stylesheets - Sass and CSS
68
+ - Images and fonts
69
+ - PostCSS - Auto-Prefixer
57
70
  - Asset compression, source-maps, and minification
58
71
  - CDN support
72
+ - React, Angular, Elm and Vue support out-of-the-box
59
73
  - Rails view helpers
60
74
  - Extensible and configurable
61
75
 
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
-
71
76
  ## Installation
72
77
 
73
78
  You can either add Webpacker during setup of a new Rails 5.1+ application
@@ -82,11 +87,12 @@ Or add it to your `Gemfile`:
82
87
 
83
88
  ```ruby
84
89
  # Gemfile
85
- gem 'webpacker', '~> 6.x'
90
+ gem 'webpacker', '~> 5.x'
86
91
 
87
92
  # OR if you prefer to use master
88
93
  gem 'webpacker', git: 'https://github.com/rails/webpacker.git'
89
94
  yarn add https://github.com/rails/webpacker.git
95
+ yarn add core-js regenerator-runtime
90
96
  ```
91
97
 
92
98
  Finally, run the following to install Webpacker:
@@ -129,11 +135,19 @@ app/javascript:
129
135
  └── logo.svg
130
136
  ```
131
137
 
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`:
138
+ In `/packs/application.js`, include this at the top of the file:
139
+
140
+ ```js
141
+ import 'core-js/stable'
142
+ import 'regenerator-runtime/runtime'
143
+ ```
144
+
145
+ You can then link the JavaScript pack in Rails views using the `javascript_pack_tag` helper.
146
+ If you have styles imported in your pack file, you can link them by using `stylesheet_pack_tag`:
133
147
 
134
148
  ```erb
135
- <%= javascript_packs_with_chunks_tag 'application' %>
136
- <%= stylesheet_packs_with_chunks_tag 'application' %>
149
+ <%= javascript_pack_tag 'application' %>
150
+ <%= stylesheet_pack_tag 'application' %>
137
151
  ```
138
152
 
139
153
  If you want to link a static asset for `<link rel="prefetch">` or `<img />` tag, you
@@ -144,6 +158,31 @@ can use the `asset_pack_path` helper:
144
158
  <img src="<%= asset_pack_path 'images/logo.svg' %>" />
145
159
  ```
146
160
 
161
+ If you are using new webpack 4 split chunks API, then consider using `javascript_packs_with_chunks_tag` helper, which creates html
162
+ tags for a pack and all the dependent chunks.
163
+
164
+ ```erb
165
+ <%= javascript_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
166
+
167
+ <script src="/packs/vendor-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
168
+ <script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
169
+ <script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
170
+ <script src="/packs/map~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
171
+ <script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
172
+ ```
173
+
174
+ **Important:** Pass all your pack names when using `javascript_packs_with_chunks_tag`
175
+ helper otherwise you will get duplicated chunks on the page.
176
+
177
+ ```erb
178
+ <%# DO %>
179
+ <%= javascript_packs_with_chunks_tag 'calendar', 'map' %>
180
+
181
+ <%# DON'T %>
182
+ <%= javascript_packs_with_chunks_tag 'calendar' %>
183
+ <%= javascript_packs_with_chunks_tag 'map' %>
184
+ ```
185
+
147
186
  **Note:** In order for your styles or static assets files to be available in your view,
148
187
  you would need to link them in your "pack" or entry file.
149
188
 
@@ -209,207 +248,7 @@ WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server
209
248
 
210
249
  ### Webpack Configuration
211
250
 
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 sass-loader
338
- ```
339
-
340
- #### Less
341
-
342
- ```
343
- yarn add less less-loader
344
- ```
345
-
346
- #### Less
347
-
348
- ```
349
- yarn add stylus stylus-loader
350
- ```
351
-
352
- #### React
353
-
354
- React is supported and you just need to add relevant packages,
355
-
356
- ```
357
- yarn add react react-dom @babel/preset-react
358
- ```
359
-
360
- if you are using typescript, update your `tsconfig.json`
361
-
362
- ```json
363
- {
364
- "compilerOptions": {
365
- "declaration": false,
366
- "emitDecoratorMetadata": true,
367
- "experimentalDecorators": true,
368
- "lib": ["es6", "dom"],
369
- "module": "es6",
370
- "moduleResolution": "node",
371
- "sourceMap": true,
372
- "target": "es5",
373
- "jsx": "react",
374
- "noEmit": true
375
- },
376
- "exclude": ["**/*.spec.ts", "node_modules", "vendor", "public"],
377
- "compileOnSave": false
378
- }
379
- ```
380
-
381
- #### Other frameworks
382
-
383
- Please follow webpack integration guide for relevant framework or library,
384
-
385
- 1. Svelte - https://github.com/sveltejs/svelte-loader#install
386
- 2. Angular - https://v2.angular.io/docs/ts/latest/guide/webpack.html#!#configure-webpack
387
- 3. Vue - https://vue-loader.vuejs.org/guide/
388
-
389
- For example to add Vue support,
390
-
391
- ```js
392
- // config/webpack/rules/vue.js
393
- const VueLoaderPlugin = require('vue-loader/lib/plugin')
394
-
395
- module.exports = {
396
- module: {
397
- rules: [
398
- {
399
- test: /\.vue$/,
400
- loader: 'vue-loader'
401
- }
402
- ]
403
- },
404
- plugins: [new VueLoaderPlugin()]
405
- }
406
-
407
- // config/webpack/base.js
408
- const { webpackConfig, merge } = require('@rails/webpacker')
409
- const vueConfig = require('./rules/vue')
410
-
411
- module.exports = merge(webpackConfig, vueConfig)
412
- ```
251
+ See [docs/webpack](docs/webpack.md) for modifying webpack configuration and loaders.
413
252
 
414
253
  ### Custom Rails environments
415
254
 
@@ -474,6 +313,24 @@ yarn upgrade webpack-dev-server --latest
474
313
  yarn add @rails/webpacker@next
475
314
  ```
476
315
 
316
+ ## Integrations
317
+
318
+ Webpacker ships with basic out-of-the-box integration. You can see a list of available commands/tasks by running `bundle exec rails webpacker`.
319
+
320
+ Included install integrations:
321
+
322
+ - [React](./docs/integrations.md#React)
323
+ - [Angular with TypeScript](./docs/integrations.md#Angular-with-TypeScript)
324
+ - [Vue](./docs/integrations.md#Vue)
325
+ - [Elm](./docs/integrations.md#Elm)
326
+ - [Svelte](./docs/integrations.md#Svelte)
327
+ - [Stimulus](./docs/integrations.md#Stimulus)
328
+ - [CoffeeScript](./docs/integrations.md#CoffeeScript)
329
+ - [Typescript](./docs/typescript.md)
330
+ - [Erb](./docs/integrations.md#Erb)
331
+
332
+ See [Integrations](./docs/integrations.md) for further details.
333
+
477
334
  ## Paths
478
335
 
479
336
  By default, Webpacker ships with simple conventions for where the JavaScript
@@ -509,7 +366,7 @@ development:
509
366
 
510
367
  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.
511
368
 
512
- ### Additional paths
369
+ ### Resolved
513
370
 
514
371
  If you are adding Webpacker to an existing app that has most of the assets inside
515
372
  `app/assets` or inside an engine, and you want to share that
@@ -518,7 +375,7 @@ option available in `config/webpacker.yml`. This lets you
518
375
  add additional paths that webpack should lookup when resolving modules:
519
376
 
520
377
  ```yml
521
- additional_paths: ['app/assets/**/*', 'vendor/assets/**/*.css', 'Gemfile']
378
+ additional_paths: ['app/assets']
522
379
  ```
523
380
 
524
381
  You can then import these items inside your modules like so:
@@ -539,6 +396,26 @@ Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which
539
396
 
540
397
  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.
541
398
 
399
+ ## Docs
400
+
401
+ - [Development](https://github.com/rails/webpacker#development)
402
+ - [Webpack](./docs/webpack.md)
403
+ - [Webpack-dev-server](./docs/webpack-dev-server.md)
404
+ - [Environment Variables](./docs/env.md)
405
+ - [Folder Structure](./docs/folder-structure.md)
406
+ - [Assets](./docs/assets.md) - [CSS, Sass and SCSS](./docs/css.md) - [ES6](./docs/es6.md), [Target browsers](./docs/target.md)
407
+ - [Props](./docs/props.md)
408
+ - [Typescript](./docs/typescript.md)
409
+ - [Yarn](./docs/yarn.md)
410
+ - [Misc](./docs/misc.md)
411
+ - [Deployment](./docs/deployment.md)
412
+ - [Docker](./docs/docker.md)
413
+ - [Using in Rails engines](./docs/engines.md)
414
+ - [Webpacker on Cloud9](./docs/cloud9.md)
415
+ - [Testing](./docs/testing.md)
416
+ - [Troubleshooting](./docs/troubleshooting.md)
417
+ - [v3 to v4 Upgrade Guide](./docs/v4-upgrade.md)
418
+
542
419
  ## Contributing
543
420
 
544
421
  [![Code Helpers](https://www.codetriage.com/rails/webpacker/badges/users.svg)](https://www.codetriage.com/rails/webpacker)