webpacker 4.2.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.node-version +1 -1
- data/.travis.yml +7 -20
- data/CHANGELOG.md +90 -55
- data/Gemfile +1 -0
- data/Gemfile.lock +8 -5
- data/README.md +52 -280
- data/docs/css.md +3 -4
- data/docs/deployment.md +2 -2
- data/docs/docker.md +17 -17
- data/docs/engines.md +13 -0
- data/docs/env.md +0 -2
- data/docs/integrations.md +220 -0
- data/docs/testing.md +1 -2
- data/docs/typescript.md +4 -21
- data/lib/install/config/webpacker.yml +0 -4
- data/lib/install/examples/react/tsconfig.json +2 -1
- data/lib/install/examples/typescript/tsconfig.json +2 -1
- data/lib/install/loaders/svelte.js +2 -2
- data/lib/install/template.rb +2 -2
- data/lib/install/typescript.rb +8 -12
- data/lib/tasks/webpacker/check_node.rake +14 -7
- data/lib/tasks/webpacker/check_yarn.rake +16 -9
- data/lib/tasks/webpacker/clean.rake +16 -6
- data/lib/tasks/webpacker/clobber.rake +8 -4
- data/lib/tasks/webpacker/compile.rake +1 -9
- data/lib/tasks/webpacker/yarn_install.rake +5 -16
- data/lib/webpacker.rb +8 -0
- data/lib/webpacker/commands.rb +45 -19
- data/lib/webpacker/compiler.rb +2 -3
- data/lib/webpacker/configuration.rb +1 -5
- data/lib/webpacker/dev_server_proxy.rb +3 -1
- data/lib/webpacker/dev_server_runner.rb +4 -4
- data/lib/webpacker/helper.rb +8 -8
- data/lib/webpacker/manifest.rb +4 -4
- data/lib/webpacker/railtie.rb +0 -43
- data/lib/webpacker/version.rb +1 -1
- data/package.json +35 -35
- data/package/__tests__/dev_server.js +2 -0
- data/package/dev_server.js +1 -1
- data/package/environments/__tests__/base.js +10 -0
- data/package/environments/base.js +12 -1
- data/package/environments/development.js +0 -4
- data/package/rules/babel.js +1 -1
- data/package/rules/sass.js +7 -1
- data/test/manifest_test.rb +37 -6
- data/test/rake_tasks_test.rb +11 -0
- data/test/test_app/app/javascript/packs/multi_entry.css +4 -0
- data/test/test_app/app/javascript/packs/multi_entry.js +4 -0
- data/test/test_app/config/application.rb +0 -1
- data/webpacker.gemspec +4 -3
- data/yarn.lock +2627 -1547
- metadata +28 -13
- data/gemfiles/Gemfile-rails.4.2.x +0 -9
- data/gemfiles/Gemfile-rails.5.0.x +0 -9
- data/gemfiles/Gemfile-rails.5.1.x +0 -9
- data/lib/install/loaders/typescript.js +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f40a6c8d18cf109b9dcd47ffcd683eed4937e7a270d4b7012bbe19ef7c949801
|
4
|
+
data.tar.gz: be53580b891326ee7001338bc4a74304055910cb504f1cacf1f10315bb02287c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de6712a73fdcfa58bcfd45928884e252dbc1ab17f8caaa3c8494d8dd90e505070b160e182bb74ae3afac6fc14560fa38c72436c997a5cb0df054b4df3ff0d5e1
|
7
|
+
data.tar.gz: 11cc1597eaa0a29581670ceb03c3c30b3aabe509d272563e285eac57c04d9eba0dd4db991834074fc180df07294cabd9d06ded3179f79b6960070ccfccf0c61c
|
data/.node-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
10.13.0
|
data/.travis.yml
CHANGED
@@ -2,21 +2,14 @@ language: ruby
|
|
2
2
|
dist: xenial
|
3
3
|
before_install:
|
4
4
|
- gem install rubygems-update && update_rubygems
|
5
|
-
|
6
|
-
# v1.17.3. This is just for Ruby 2.5 which ships with bundler 2.x on Travis
|
7
|
-
# CI while Ruby 2.6 does not.
|
8
|
-
# https://github.com/travis-ci/travis-rubies/issues/57#issuecomment-458981237
|
9
|
-
- yes | rvm @global do gem install bundler -v 1.17.3 || true
|
5
|
+
- yes | rvm @global do gem install bundler -v 2.1.4 || true
|
10
6
|
rvm:
|
11
|
-
- 2.
|
12
|
-
- 2.4.6
|
7
|
+
- 2.4.9
|
13
8
|
- 2.5.5
|
14
|
-
- 2.6.
|
9
|
+
- 2.6.5
|
10
|
+
- 2.7.0
|
15
11
|
- ruby-head
|
16
12
|
gemfile:
|
17
|
-
- gemfiles/Gemfile-rails.4.2.x
|
18
|
-
- gemfiles/Gemfile-rails.5.0.x
|
19
|
-
- gemfiles/Gemfile-rails.5.1.x
|
20
13
|
- gemfiles/Gemfile-rails.5.2.x
|
21
14
|
- gemfiles/Gemfile-rails.6.0.x
|
22
15
|
- gemfiles/Gemfile-rails-edge
|
@@ -28,7 +21,7 @@ cache:
|
|
28
21
|
|
29
22
|
install:
|
30
23
|
- bundle install --jobs 3 --retry 3
|
31
|
-
- nvm install
|
24
|
+
- nvm install 12
|
32
25
|
- node -v
|
33
26
|
- npm i -g yarn
|
34
27
|
- yarn
|
@@ -42,15 +35,9 @@ matrix:
|
|
42
35
|
- gemfile: gemfiles/Gemfile-rails-edge
|
43
36
|
- rvm: ruby-head
|
44
37
|
exclude:
|
45
|
-
- rvm: 2.
|
46
|
-
gemfile: gemfiles/Gemfile-rails-edge
|
47
|
-
- rvm: 2.4.6
|
38
|
+
- rvm: 2.4.9
|
48
39
|
gemfile: gemfiles/Gemfile-rails-edge
|
49
40
|
- rvm: 2.5.5
|
50
41
|
gemfile: gemfiles/Gemfile-rails-edge
|
51
|
-
- rvm:
|
52
|
-
gemfile: gemfiles/Gemfile-rails.4.2.x
|
53
|
-
- rvm: 2.3.8
|
54
|
-
gemfile: gemfiles/Gemfile-rails.6.0.x
|
55
|
-
- rvm: 2.4.6
|
42
|
+
- rvm: 2.4.9
|
56
43
|
gemfile: gemfiles/Gemfile-rails.6.0.x
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,41 @@
|
|
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
|
+
## [[5.1.0]](https://github.com/rails/webpacker/compare/v5.0.1...v5.1.0) - 2020-04-19
|
6
|
+
|
7
|
+
- Remove yarn integrity check [#2518](https://github.com/rails/webpacker/pull/2518)
|
8
|
+
- Switch from ts-loader to babel-loader [#2449](https://github.com/rails/webpacker/pull/2449)
|
9
|
+
- Resolve multi-word snakecase WEBPACKER_DEV_SERVER env values [#2528](https://github.com/rails/webpacker/pull/2528)
|
10
|
+
|
11
|
+
## [[5.0.1]](https://github.com/rails/webpacker/compare/v5.0.0...v5.0.1) - 2020-03-22
|
12
|
+
|
13
|
+
- Upgrade deps and fix sass loader config options bug [#2508](https://github.com/rails/webpacker/pull/2508)
|
14
|
+
|
15
|
+
## [[5.0.0]](https://github.com/rails/webpacker/compare/v4.2.2...v5.0.0) - 2020-03-22
|
16
|
+
|
17
|
+
- Bump minimum node version [#2428](https://github.com/rails/webpacker/pull/2428)
|
18
|
+
- Bump minimum ruby/rails version [#2415](https://github.com/rails/webpacker/pull/2415)
|
19
|
+
- Add support for multiple files per entry [#2476](https://github.com/rails/webpacker/pull/2476)
|
20
|
+
|
21
|
+
```js
|
22
|
+
entry: {
|
23
|
+
home: ['./home.js', './home.scss'],
|
24
|
+
account: ['./account.js', './account.scss']
|
25
|
+
}
|
26
|
+
```
|
27
|
+
|
28
|
+
You can now have two entry files with same names inside packs folder, `home.scss` and `home.js`
|
29
|
+
|
30
|
+
And, other minor fixes, please see a list of changes [here](https://github.com/rails/webpacker/compare/v4.2.2...v5.0.0)
|
31
|
+
|
32
|
+
## [[4.2.2]](https://github.com/rails/webpacker/compare/v4.2.1...v4.2.2) - 2019-12-09
|
33
|
+
|
34
|
+
- Fixed issue with webpack clean task for nested assets [#2391](https://github.com/rails/webpacker/pull/2391)
|
35
|
+
|
36
|
+
## [[4.2.1]](https://github.com/rails/webpacker/compare/v4.2.0...v4.2.1) - 2019-12-09
|
37
|
+
|
38
|
+
- Fixed issue with webpack clean task [#2389](https://github.com/rails/webpacker/pull/2389)
|
39
|
+
|
5
40
|
## [[4.2.0]](https://github.com/rails/webpacker/compare/v4.1.0...v4.2.0) - 2019-11-12
|
6
41
|
|
7
42
|
- Fixed installer bug [#2366](https://github.com/rails/webpacker/pull/2366)
|
@@ -49,14 +84,14 @@ Please see the diff
|
|
49
84
|
In each of your `/packs/*.js` files, change this:
|
50
85
|
|
51
86
|
```js
|
52
|
-
import
|
87
|
+
import '@babel/polyfill'
|
53
88
|
```
|
54
89
|
|
55
90
|
to this:
|
56
91
|
|
57
92
|
```js
|
58
|
-
import
|
59
|
-
import
|
93
|
+
import 'core-js/stable'
|
94
|
+
import 'regenerator-runtime/runtime'
|
60
95
|
```
|
61
96
|
|
62
97
|
Don't forget to install those dependencies directly!
|
@@ -93,10 +128,10 @@ Source maps can be disabled in any environment configuration, e.g:
|
|
93
128
|
```js
|
94
129
|
// config/webpack/production.js
|
95
130
|
|
96
|
-
const environment = require(
|
97
|
-
environment.config.merge({ devtool:
|
131
|
+
const environment = require('./environment')
|
132
|
+
environment.config.merge({ devtool: 'none' })
|
98
133
|
|
99
|
-
module.exports = environment.toWebpackConfig()
|
134
|
+
module.exports = environment.toWebpackConfig()
|
100
135
|
```
|
101
136
|
|
102
137
|
- Reintroduced `context` to the file loader. Reverting the simpler paths change
|
@@ -147,12 +182,12 @@ To get old behaviour:
|
|
147
182
|
```js
|
148
183
|
// config/webpack/environment.js
|
149
184
|
|
150
|
-
const { environment, config } = require(
|
151
|
-
const { join } = require(
|
185
|
+
const { environment, config } = require('@rails/webpacker')
|
186
|
+
const { join } = require('path')
|
152
187
|
|
153
|
-
const fileLoader = environment.loaders.get(
|
154
|
-
fileLoader.use[0].options.name =
|
155
|
-
fileLoader.use[0].options.context = join(config.source_path)
|
188
|
+
const fileLoader = environment.loaders.get('file')
|
189
|
+
fileLoader.use[0].options.name = '[path][name]-[hash].[ext]'
|
190
|
+
fileLoader.use[0].options.context = join(config.source_path) // optional if you don't want to expose full paths
|
156
191
|
```
|
157
192
|
|
158
193
|
### Added
|
@@ -246,7 +281,7 @@ helper otherwise you will get duplicated chunks on the page.
|
|
246
281
|
depending on how you want to process packs [#1823](https://github.com/rails/webpacker/pull/1823)
|
247
282
|
|
248
283
|
```js
|
249
|
-
environment.loaders.prepend()
|
284
|
+
environment.loaders.prepend()
|
250
285
|
```
|
251
286
|
|
252
287
|
- Separate CSS extraction from build environment [#1625](https://github.com/rails/webpacker/pull/1625)
|
@@ -281,13 +316,13 @@ static_assets_extensions:
|
|
281
316
|
- Add split chunks api (undocumented)
|
282
317
|
|
283
318
|
```js
|
284
|
-
const { environment } = require(
|
319
|
+
const { environment } = require('@rails/webpacker')
|
285
320
|
// Enable with default config
|
286
|
-
environment.splitChunks()
|
321
|
+
environment.splitChunks()
|
287
322
|
// Configure via a callback
|
288
323
|
environment.splitChunks(config =>
|
289
324
|
Object.assign({}, config, { optimization: { splitChunks: false } })
|
290
|
-
)
|
325
|
+
)
|
291
326
|
```
|
292
327
|
|
293
328
|
- Allow changing static file extensions using webpacker.yml (undocumented)
|
@@ -418,12 +453,12 @@ bundle exec rails webpacker:binstubs
|
|
418
453
|
|
419
454
|
```js
|
420
455
|
// config/webpack/environment.js
|
421
|
-
const { environment } = require(
|
456
|
+
const { environment } = require('@rails/webpacker')
|
422
457
|
|
423
|
-
environment.loaders.append(
|
458
|
+
environment.loaders.append('json', {
|
424
459
|
test: /\.json$/,
|
425
|
-
use:
|
426
|
-
})
|
460
|
+
use: 'json-loader'
|
461
|
+
})
|
427
462
|
```
|
428
463
|
|
429
464
|
### Fixed
|
@@ -490,17 +525,17 @@ into your `config/webpack/loaders/`
|
|
490
525
|
directory and add it to webpack build from `config/webpack/environment.js`
|
491
526
|
|
492
527
|
```js
|
493
|
-
const erb = require(
|
494
|
-
const elm = require(
|
495
|
-
const typescript = require(
|
496
|
-
const vue = require(
|
497
|
-
const coffee = require(
|
498
|
-
|
499
|
-
environment.loaders.append(
|
500
|
-
environment.loaders.append(
|
501
|
-
environment.loaders.append(
|
502
|
-
environment.loaders.append(
|
503
|
-
environment.loaders.append(
|
528
|
+
const erb = require('./loaders/erb')
|
529
|
+
const elm = require('./loaders/elm')
|
530
|
+
const typescript = require('./loaders/typescript')
|
531
|
+
const vue = require('./loaders/vue')
|
532
|
+
const coffee = require('./loaders/coffee')
|
533
|
+
|
534
|
+
environment.loaders.append('coffee', coffee)
|
535
|
+
environment.loaders.append('vue', vue)
|
536
|
+
environment.loaders.append('typescript', typescript)
|
537
|
+
environment.loaders.append('elm', elm)
|
538
|
+
environment.loaders.append('erb', erb)
|
504
539
|
```
|
505
540
|
|
506
541
|
In `.postcssrc.yml` you need to change the plugin name from `postcss-smart-import` to `postcss-import`:
|
@@ -553,15 +588,15 @@ bundle exec rails webpacker:install:coffee
|
|
553
588
|
- Expose base config from environment
|
554
589
|
|
555
590
|
```js
|
556
|
-
environment.config.set(
|
557
|
-
environment.config.set(
|
558
|
-
environment.config.delete(
|
559
|
-
environment.config.get(
|
591
|
+
environment.config.set('resolve.extensions', ['.foo', '.bar'])
|
592
|
+
environment.config.set('output.filename', '[name].js')
|
593
|
+
environment.config.delete('output.chunkFilename')
|
594
|
+
environment.config.get('resolve')
|
560
595
|
environment.config.merge({
|
561
596
|
output: {
|
562
|
-
filename:
|
597
|
+
filename: '[name].js'
|
563
598
|
}
|
564
|
-
})
|
599
|
+
})
|
565
600
|
```
|
566
601
|
|
567
602
|
- Expose new API's for loaders and plugins to insert at position
|
@@ -570,34 +605,34 @@ environment.config.merge({
|
|
570
605
|
const jsonLoader = {
|
571
606
|
test: /\.json$/,
|
572
607
|
exclude: /node_modules/,
|
573
|
-
loader:
|
574
|
-
}
|
608
|
+
loader: 'json-loader'
|
609
|
+
}
|
575
610
|
|
576
|
-
environment.loaders.append(
|
577
|
-
environment.loaders.prepend(
|
578
|
-
environment.loaders.insert(
|
579
|
-
environment.loaders.insert(
|
611
|
+
environment.loaders.append('json', jsonLoader)
|
612
|
+
environment.loaders.prepend('json', jsonLoader)
|
613
|
+
environment.loaders.insert('json', jsonLoader, { after: 'style' })
|
614
|
+
environment.loaders.insert('json', jsonLoader, { before: 'babel' })
|
580
615
|
|
581
616
|
// Update a plugin
|
582
|
-
const manifestPlugin = environment.plugins.get(
|
583
|
-
manifestPlugin.opts.writeToFileEmit = false
|
617
|
+
const manifestPlugin = environment.plugins.get('Manifest')
|
618
|
+
manifestPlugin.opts.writeToFileEmit = false
|
584
619
|
|
585
620
|
// Update coffee loader to use coffeescript 2
|
586
|
-
const babelLoader = environment.loaders.get(
|
621
|
+
const babelLoader = environment.loaders.get('babel')
|
587
622
|
environment.loaders.insert(
|
588
|
-
|
623
|
+
'coffee',
|
589
624
|
{
|
590
625
|
test: /\.coffee(\.erb)?$/,
|
591
|
-
use: babelLoader.use.concat([
|
626
|
+
use: babelLoader.use.concat(['coffee-loader'])
|
592
627
|
},
|
593
|
-
{ before:
|
594
|
-
)
|
628
|
+
{ before: 'json' }
|
629
|
+
)
|
595
630
|
```
|
596
631
|
|
597
632
|
- Expose `resolve.modules` paths like loaders and plugins
|
598
633
|
|
599
634
|
```js
|
600
|
-
environment.resolvedModules.append(
|
635
|
+
environment.resolvedModules.append('vendor', 'vendor')
|
601
636
|
```
|
602
637
|
|
603
638
|
- Enable sourcemaps in `style` and `css` loader
|
@@ -608,13 +643,13 @@ environment.resolvedModules.append("vendor", "vendor");
|
|
608
643
|
|
609
644
|
```js
|
610
645
|
// Enable css modules with sass loader
|
611
|
-
const sassLoader = environment.loaders.get(
|
612
|
-
const cssLoader = sassLoader.use.find(loader => loader.loader ===
|
646
|
+
const sassLoader = environment.loaders.get('sass')
|
647
|
+
const cssLoader = sassLoader.use.find(loader => loader.loader === 'css-loader')
|
613
648
|
|
614
649
|
cssLoader.options = Object.assign({}, cssLoader.options, {
|
615
650
|
modules: true,
|
616
|
-
localIdentName:
|
617
|
-
})
|
651
|
+
localIdentName: '[path][name]__[local]--[hash:base64:5]'
|
652
|
+
})
|
618
653
|
```
|
619
654
|
|
620
655
|
- Expose rest of configurable dev server options from webpacker.yml
|
@@ -622,7 +657,7 @@ cssLoader.options = Object.assign({}, cssLoader.options, {
|
|
622
657
|
```yml
|
623
658
|
quiet: false
|
624
659
|
headers:
|
625
|
-
|
660
|
+
'Access-Control-Allow-Origin': '*'
|
626
661
|
watch_options:
|
627
662
|
ignored: /node_modules/
|
628
663
|
```
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
webpacker (
|
5
|
-
activesupport (>=
|
4
|
+
webpacker (5.1.0)
|
5
|
+
activesupport (>= 5.2)
|
6
6
|
rack-proxy (>= 0.6.1)
|
7
|
-
railties (>=
|
7
|
+
railties (>= 5.2)
|
8
|
+
semantic_range (>= 2.3.0)
|
8
9
|
|
9
10
|
GEM
|
10
11
|
remote: https://rubygems.org/
|
@@ -88,12 +89,12 @@ GEM
|
|
88
89
|
mini_portile2 (2.4.0)
|
89
90
|
minitest (5.13.0)
|
90
91
|
nio4r (2.5.2)
|
91
|
-
nokogiri (1.10.
|
92
|
+
nokogiri (1.10.8)
|
92
93
|
mini_portile2 (~> 2.4.0)
|
93
94
|
parallel (1.18.0)
|
94
95
|
parser (2.6.5.0)
|
95
96
|
ast (~> 2.4.0)
|
96
|
-
rack (2.0.
|
97
|
+
rack (2.0.8)
|
97
98
|
rack-proxy (0.6.5)
|
98
99
|
rack
|
99
100
|
rack-test (1.1.0)
|
@@ -136,6 +137,7 @@ GEM
|
|
136
137
|
rubocop-performance (1.3.0)
|
137
138
|
rubocop (>= 0.68.0)
|
138
139
|
ruby-progressbar (1.10.1)
|
140
|
+
semantic_range (2.3.0)
|
139
141
|
sprockets (4.0.0)
|
140
142
|
concurrent-ruby (~> 1.0)
|
141
143
|
rack (> 1, < 3)
|
@@ -165,6 +167,7 @@ DEPENDENCIES
|
|
165
167
|
rake (>= 11.1)
|
166
168
|
rubocop (< 0.69)
|
167
169
|
rubocop-performance
|
170
|
+
semantic_range
|
168
171
|
webpacker!
|
169
172
|
|
170
173
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Webpacker
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/rails/webpacker.svg?branch=master)](https://travis-ci.org/rails/webpacker)
|
4
|
-
[![node.js](https://img.shields.io/badge/node-%3E%3D%
|
5
|
-
[![Gem](https://img.shields.io/gem/v/webpacker.svg)](https://
|
4
|
+
[![node.js](https://img.shields.io/badge/node-%3E%3D%2010.13.0-brightgreen.svg)](https://www.npmjs.com/package/@rails/webpacker)
|
5
|
+
[![Gem](https://img.shields.io/gem/v/webpacker.svg)](https://rubygems.org/gems/webpacker)
|
6
6
|
|
7
7
|
Webpacker makes it easy to use the JavaScript pre-processor and bundler
|
8
8
|
[webpack 4.x.x+](https://webpack.js.org/)
|
@@ -13,10 +13,11 @@ even JavaScript Sprinkles (that all continues to live in app/assets).
|
|
13
13
|
However, it is possible to use Webpacker for CSS, images and fonts assets as well,
|
14
14
|
in which case you may not even need the asset pipeline. This is mostly relevant when exclusively using component-based JavaScript frameworks.
|
15
15
|
|
16
|
-
**NOTE:** The master branch now hosts the code for
|
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.
|
17
17
|
|
18
18
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
19
19
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
20
|
+
|
20
21
|
## Table of Contents
|
21
22
|
|
22
23
|
- [Prerequisites](#prerequisites)
|
@@ -27,16 +28,15 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
27
28
|
- [Webpack Configuration](#webpack-configuration)
|
28
29
|
- [Custom Rails environments](#custom-rails-environments)
|
29
30
|
- [Upgrading](#upgrading)
|
30
|
-
- [Yarn Integrity](#yarn-integrity)
|
31
31
|
- [Integrations](#integrations)
|
32
|
-
- [React](#react)
|
33
|
-
- [Angular with TypeScript](#angular-with-typescript)
|
34
|
-
- [Vue](#vue)
|
35
|
-
- [Elm](#elm)
|
36
|
-
- [Stimulus](#stimulus)
|
37
|
-
- [Svelte](#svelte)
|
38
|
-
- [CoffeeScript](#coffeescript)
|
39
|
-
- [Erb](#erb)
|
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
|
+
- [CoffeeScript](./docs/integrations.md#coffeescript)
|
39
|
+
- [Erb](./docs/integrations.md#erb)
|
40
40
|
- [Paths](#paths)
|
41
41
|
- [Resolved](#resolved)
|
42
42
|
- [Watched](#watched)
|
@@ -47,29 +47,26 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
47
47
|
|
48
48
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
49
49
|
|
50
|
-
|
51
50
|
## Prerequisites
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
52
|
+
- Ruby 2.4+
|
53
|
+
- Rails 5.2+
|
54
|
+
- Node.js 10.13.0+
|
55
|
+
- Yarn 1.x+
|
58
56
|
|
59
57
|
## Features
|
60
58
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
59
|
+
- [webpack 4.x.x](https://webpack.js.org/)
|
60
|
+
- ES6 with [babel](https://babeljs.io/)
|
61
|
+
- Automatic code splitting using multiple entry points
|
62
|
+
- Stylesheets - Sass and CSS
|
63
|
+
- Images and fonts
|
64
|
+
- PostCSS - Auto-Prefixer
|
65
|
+
- Asset compression, source-maps, and minification
|
66
|
+
- CDN support
|
67
|
+
- React, Angular, Elm and Vue support out-of-the-box
|
68
|
+
- Rails view helpers
|
69
|
+
- Extensible and configurable
|
73
70
|
|
74
71
|
## Installation
|
75
72
|
|
@@ -85,7 +82,7 @@ Or add it to your `Gemfile`:
|
|
85
82
|
|
86
83
|
```ruby
|
87
84
|
# Gemfile
|
88
|
-
gem 'webpacker', '~>
|
85
|
+
gem 'webpacker', '~> 5.x'
|
89
86
|
|
90
87
|
# OR if you prefer to use master
|
91
88
|
gem 'webpacker', git: 'https://github.com/rails/webpacker.git'
|
@@ -109,6 +106,12 @@ Optional: To fix ["unmet peer dependency" warnings](https://github.com/rails/web
|
|
109
106
|
yarn upgrade
|
110
107
|
```
|
111
108
|
|
109
|
+
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:
|
110
|
+
|
111
|
+
```bash
|
112
|
+
yarn install
|
113
|
+
```
|
114
|
+
|
112
115
|
### Usage
|
113
116
|
|
114
117
|
Once installed, you can start writing modern ES6-flavored JavaScript apps right away:
|
@@ -127,8 +130,8 @@ app/javascript:
|
|
127
130
|
In `/packs/application.js`, include this at the top of the file:
|
128
131
|
|
129
132
|
```js
|
130
|
-
import
|
131
|
-
import
|
133
|
+
import 'core-js/stable'
|
134
|
+
import 'regenerator-runtime/runtime'
|
132
135
|
```
|
133
136
|
|
134
137
|
You can then link the JavaScript pack in Rails views using the `javascript_pack_tag` helper.
|
@@ -175,7 +178,6 @@ helper otherwise you will get duplicated chunks on the page.
|
|
175
178
|
**Note:** In order for your styles or static assets files to be available in your view,
|
176
179
|
you would need to link them in your "pack" or entry file.
|
177
180
|
|
178
|
-
|
179
181
|
### Development
|
180
182
|
|
181
183
|
Webpacker ships with two binstubs: `./bin/webpack` and `./bin/webpack-dev-server`.
|
@@ -240,7 +242,6 @@ WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server
|
|
240
242
|
|
241
243
|
See [docs/webpack](docs/webpack.md) for modifying webpack configuration and loaders.
|
242
244
|
|
243
|
-
|
244
245
|
### Custom Rails environments
|
245
246
|
|
246
247
|
Out of the box Webpacker ships with - development, test and production environments in `config/webpacker.yml` however, in most production apps extra environments are needed as part of deployment workflow. Webpacker supports this out of the box from version 3.4.0+ onwards.
|
@@ -290,7 +291,6 @@ bundle exec rails assets:precompile
|
|
290
291
|
bundle exec rails webpacker:compile
|
291
292
|
```
|
292
293
|
|
293
|
-
|
294
294
|
### Upgrading
|
295
295
|
|
296
296
|
You can run following commands to upgrade Webpacker to the latest stable version. This process involves upgrading the gem and related JavaScript packages:
|
@@ -305,247 +305,23 @@ yarn upgrade webpack-dev-server --latest
|
|
305
305
|
yarn add @rails/webpacker@next
|
306
306
|
```
|
307
307
|
|
308
|
-
### Yarn Integrity
|
309
|
-
|
310
|
-
By default, in development, webpacker runs a yarn integrity check to ensure that all local JavaScript packages are up-to-date. This is similar to what bundler does currently in Rails, but for JavaScript packages. If your system is out of date, then Rails will not initialize. You will be asked to upgrade your local JavaScript packages by running `yarn install`.
|
311
|
-
|
312
|
-
To turn off this option, you will need to change the default setting in `config/webpacker.yml`:
|
313
|
-
|
314
|
-
```yaml
|
315
|
-
# config/webpacker.yml
|
316
|
-
development:
|
317
|
-
...
|
318
|
-
# Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
|
319
|
-
check_yarn_integrity: false
|
320
|
-
```
|
321
|
-
|
322
|
-
You may also turn on this feature by adding the config option for any Rails environment in `config/webpacker.yml`:
|
323
|
-
|
324
|
-
```yaml
|
325
|
-
check_yarn_integrity: true
|
326
|
-
```
|
327
|
-
|
328
308
|
## Integrations
|
329
309
|
|
330
|
-
Webpacker ships with basic out-of-the-box integration
|
331
|
-
You can see a list of available commands/tasks by running `bundle exec rails webpacker`:
|
332
|
-
|
333
|
-
### React
|
334
|
-
|
335
|
-
To use Webpacker with [React](https://facebook.github.io/react/), create a
|
336
|
-
new Rails 5.1+ app using `--webpack=react` option:
|
337
|
-
|
338
|
-
```bash
|
339
|
-
# Rails 5.1+
|
340
|
-
rails new myapp --webpack=react
|
341
|
-
```
|
342
|
-
|
343
|
-
(or run `bundle exec rails webpacker:install:react` in an existing Rails app already
|
344
|
-
setup with Webpacker).
|
345
|
-
|
346
|
-
The installer will add all relevant dependencies using Yarn, changes
|
347
|
-
to the configuration files, and an example React component to your
|
348
|
-
project in `app/javascript/packs` so that you can experiment with React right away.
|
349
|
-
|
350
|
-
|
351
|
-
### Angular with TypeScript
|
352
|
-
|
353
|
-
To use Webpacker with [Angular](https://angular.io/), create a
|
354
|
-
new Rails 5.1+ app using `--webpack=angular` option:
|
355
|
-
|
356
|
-
```bash
|
357
|
-
# Rails 5.1+
|
358
|
-
rails new myapp --webpack=angular
|
359
|
-
```
|
360
|
-
|
361
|
-
(or run `bundle exec rails webpacker:install:angular` on a Rails app already
|
362
|
-
setup with Webpacker).
|
363
|
-
|
364
|
-
The installer will add the TypeScript and Angular core libraries using Yarn alongside
|
365
|
-
a few changes to the configuration files. An example component written in
|
366
|
-
TypeScript will also be added to your project in `app/javascript` so that
|
367
|
-
you can experiment with Angular right away.
|
368
|
-
|
369
|
-
By default, Angular uses a JIT compiler for development environment. This
|
370
|
-
compiler is not compatible with restrictive CSP (Content Security
|
371
|
-
Policy) environments like Rails 5.2+. You can use Angular AOT compiler
|
372
|
-
in development with the [@ngtools/webpack](https://www.npmjs.com/package/@ngtools/webpack#usage) plugin.
|
373
|
-
|
374
|
-
Alternatively if you're using Rails 5.2+ you can enable `unsafe-eval` rule for your
|
375
|
-
development environment. This can be done in the `config/initializers/content_security_policy.rb`
|
376
|
-
with the following code:
|
377
|
-
|
378
|
-
```ruby
|
379
|
-
Rails.application.config.content_security_policy do |policy|
|
380
|
-
if Rails.env.development?
|
381
|
-
policy.script_src :self, :https, :unsafe_eval
|
382
|
-
else
|
383
|
-
policy.script_src :self, :https
|
384
|
-
end
|
385
|
-
end
|
386
|
-
```
|
387
|
-
|
388
|
-
|
389
|
-
### Vue
|
390
|
-
|
391
|
-
To use Webpacker with [Vue](https://vuejs.org/), create a
|
392
|
-
new Rails 5.1+ app using `--webpack=vue` option:
|
393
|
-
|
394
|
-
```bash
|
395
|
-
# Rails 5.1+
|
396
|
-
rails new myapp --webpack=vue
|
397
|
-
```
|
398
|
-
(or run `bundle exec rails webpacker:install:vue` on a Rails app already setup with Webpacker).
|
399
|
-
|
400
|
-
The installer will add Vue and its required libraries using Yarn alongside
|
401
|
-
automatically applying changes needed to the configuration files. An example component will
|
402
|
-
be added to your project in `app/javascript` so that you can experiment with Vue right away.
|
403
|
-
|
404
|
-
If you're using Rails 5.2+ you'll need to enable `unsafe-eval` rule for your development environment.
|
405
|
-
This can be done in the `config/initializers/content_security_policy.rb` with the following
|
406
|
-
configuration:
|
407
|
-
|
408
|
-
```ruby
|
409
|
-
Rails.application.config.content_security_policy do |policy|
|
410
|
-
if Rails.env.development?
|
411
|
-
policy.script_src :self, :https, :unsafe_eval
|
412
|
-
else
|
413
|
-
policy.script_src :self, :https
|
414
|
-
end
|
415
|
-
end
|
416
|
-
```
|
417
|
-
You can read more about this in the [Vue docs](https://vuejs.org/v2/guide/installation.html#CSP-environments).
|
310
|
+
Webpacker ships with basic out-of-the-box integration. You can see a list of available commands/tasks by running `bundle exec rails webpacker`.
|
418
311
|
|
419
|
-
|
312
|
+
Included install integrations:
|
420
313
|
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
Vue.component('VCard', VCard)
|
431
|
-
```
|
432
|
-
|
433
|
-
After:
|
434
|
-
```js
|
435
|
-
import Vue from 'vue'
|
436
|
-
|
437
|
-
// With destructuring assignment
|
438
|
-
Vue.component('VCard', import('vuetify/lib').then(({ VCard }) => VCard)
|
439
|
-
|
440
|
-
// Or without destructuring assignment
|
441
|
-
Vue.component('OtherComponent', () => import('./OtherComponent'))
|
442
|
-
```
|
443
|
-
|
444
|
-
You can use it in a Single File Component as well:
|
445
|
-
|
446
|
-
```html
|
447
|
-
<template>
|
448
|
-
...
|
449
|
-
</template>
|
450
|
-
|
451
|
-
<script>
|
452
|
-
export default {
|
453
|
-
components: {
|
454
|
-
OtherComponent: () => import('./OtherComponent')
|
455
|
-
}
|
456
|
-
}
|
457
|
-
</script>
|
458
|
-
```
|
459
|
-
|
460
|
-
By wrapping the import function into an arrow function, Vue will execute it only when it gets requested, loading the module in that moment.
|
461
|
-
|
462
|
-
##### Automatic registration
|
463
|
-
|
464
|
-
```js
|
465
|
-
/**
|
466
|
-
* The following block of code may be used to automatically register your
|
467
|
-
* Vue components. It will recursively scan this directory for the Vue
|
468
|
-
* components and automatically register them with their "basename".
|
469
|
-
*
|
470
|
-
* Eg. ./components/OtherComponent.vue -> <other-component></other-component>
|
471
|
-
* Eg. ./UI/ButtonComponent.vue -> <button-component></button-component>
|
472
|
-
*/
|
473
|
-
|
474
|
-
const files = require.context('./', true, /\.vue$/i)
|
475
|
-
files.keys().map(key => {
|
476
|
-
const component = key.split('/').pop().split('.')[0]
|
477
|
-
|
478
|
-
// With Lazy Loading
|
479
|
-
Vue.component(component, () => import(`${key}`))
|
480
|
-
|
481
|
-
// Or without Lazy Loading
|
482
|
-
Vue.component(component, files(key).default)
|
483
|
-
})
|
484
|
-
```
|
485
|
-
|
486
|
-
### Elm
|
487
|
-
|
488
|
-
To use Webpacker with [Elm](http://elm-lang.org), create a
|
489
|
-
new Rails 5.1+ app using `--webpack=elm` option:
|
490
|
-
|
491
|
-
```
|
492
|
-
# Rails 5.1+
|
493
|
-
rails new myapp --webpack=elm
|
494
|
-
```
|
495
|
-
|
496
|
-
(or run `bundle exec rails webpacker:install:elm` on a Rails app already setup with Webpacker).
|
497
|
-
|
498
|
-
The Elm library and its core packages will be added via Yarn and Elm.
|
499
|
-
An example `Main.elm` app will also be added to your project in `app/javascript`
|
500
|
-
so that you can experiment with Elm right away.
|
501
|
-
|
502
|
-
### Svelte
|
503
|
-
|
504
|
-
To use Webpacker with [Svelte](https://svelte.dev), create a
|
505
|
-
new Rails 5.1+ app using `--webpack=svelte` option:
|
506
|
-
|
507
|
-
```
|
508
|
-
# Rails 5.1+
|
509
|
-
rails new myapp --webpack=svelte
|
510
|
-
```
|
511
|
-
|
512
|
-
(or run `bundle exec rails webpacker:install:svelte` on a Rails app already setup with Webpacker).
|
513
|
-
|
514
|
-
Please play with the [Svelte Tutorial](https://svelte.dev/tutorial/basics) or learn more about its API at https://svelte.dev/docs
|
515
|
-
|
516
|
-
### Stimulus
|
517
|
-
|
518
|
-
To use Webpacker with [Stimulus](http://stimulusjs.org), create a
|
519
|
-
new Rails 5.1+ app using `--webpack=stimulus` option:
|
520
|
-
|
521
|
-
```
|
522
|
-
# Rails 5.1+
|
523
|
-
rails new myapp --webpack=stimulus
|
524
|
-
```
|
525
|
-
|
526
|
-
(or run `bundle exec rails webpacker:install:stimulus` on a Rails app already setup with Webpacker).
|
527
|
-
|
528
|
-
Please read [The Stimulus Handbook](https://stimulusjs.org/handbook/introduction) or learn more about its source code at https://github.com/stimulusjs/stimulus
|
529
|
-
|
530
|
-
### CoffeeScript
|
531
|
-
|
532
|
-
To add [CoffeeScript](http://coffeescript.org/) support,
|
533
|
-
run `bundle exec rails webpacker:install:coffee` on a Rails app already
|
534
|
-
setup with Webpacker.
|
535
|
-
|
536
|
-
An example `hello_coffee.coffee` file will also be added to your project
|
537
|
-
in `app/javascript/packs` so that you can experiment with CoffeeScript right away.
|
538
|
-
|
539
|
-
### Erb
|
540
|
-
|
541
|
-
To add [Erb](https://apidock.com/ruby/ERB) support in your JS templates,
|
542
|
-
run `bundle exec rails webpacker:install:erb` on a Rails app already
|
543
|
-
setup with Webpacker.
|
544
|
-
|
545
|
-
An example `hello_erb.js.erb` file will also be added to your project
|
546
|
-
in `app/javascript/packs` so that you can experiment with Erb-flavoured
|
547
|
-
javascript right away.
|
314
|
+
- [React](./docs/integrations.md#React)
|
315
|
+
- [Angular with TypeScript](./docs/integrations.md#Angular-with-TypeScript)
|
316
|
+
- [Vue](./docs/integrations.md#Vue)
|
317
|
+
- [Elm](./docs/integrations.md#Elm)
|
318
|
+
- [Svelte](./docs/integrations.md#Svelte)
|
319
|
+
- [Stimulus](./docs/integrations.md#Stimulus)
|
320
|
+
- [CoffeeScript](./docs/integrations.md#CoffeeScript)
|
321
|
+
- [Typescript](./docs/integrations.md)
|
322
|
+
- [Erb](./docs/integrations.md#Erb)
|
548
323
|
|
324
|
+
See [Integrations](./docs/integrations.md) for further details.
|
549
325
|
|
550
326
|
## Paths
|
551
327
|
|
@@ -582,7 +358,6 @@ development:
|
|
582
358
|
|
583
359
|
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.
|
584
360
|
|
585
|
-
|
586
361
|
### Resolved
|
587
362
|
|
588
363
|
If you are adding Webpacker to an existing app that has most of the assets inside
|
@@ -607,7 +382,6 @@ import 'images/rails.png'
|
|
607
382
|
will make the compilation slow, consider adding specific paths instead of
|
608
383
|
whole parent directory if you just need to reference one or two modules
|
609
384
|
|
610
|
-
|
611
385
|
### Watched
|
612
386
|
|
613
387
|
By default, the lazy compilation is cached until a file is changed under your
|
@@ -620,11 +394,11 @@ by adding new paths to `watched_paths` array. This is much like Rails' `autoload
|
|
620
394
|
Webpacker::Compiler.watched_paths << 'bower_components'
|
621
395
|
```
|
622
396
|
|
623
|
-
|
624
397
|
## Deployment
|
625
398
|
|
626
399
|
Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which gets run whenever you run `assets:precompile`. If you are not using Sprockets, `webpacker:compile` is automatically aliased to `assets:precompile`. Similar to sprockets both rake tasks will compile packs in production mode but will use `RAILS_ENV` to load configuration from `config/webpacker.yml` (if available).
|
627
400
|
|
401
|
+
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.
|
628
402
|
|
629
403
|
## Docs
|
630
404
|
|
@@ -633,9 +407,7 @@ Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which
|
|
633
407
|
- [Webpack-dev-server](./docs/webpack-dev-server.md)
|
634
408
|
- [Environment Variables](./docs/env.md)
|
635
409
|
- [Folder Structure](./docs/folder-structure.md)
|
636
|
-
- [Assets](./docs/assets.md)
|
637
|
-
- [CSS, Sass and SCSS](./docs/css.md)
|
638
|
-
- [ES6](./docs/es6.md)
|
410
|
+
- [Assets](./docs/assets.md) - [CSS, Sass and SCSS](./docs/css.md) - [ES6](./docs/es6.md)
|
639
411
|
- [Props](./docs/props.md)
|
640
412
|
- [Typescript](./docs/typescript.md)
|
641
413
|
- [Yarn](./docs/yarn.md)
|
@@ -648,12 +420,12 @@ Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which
|
|
648
420
|
- [Troubleshooting](./docs/troubleshooting.md)
|
649
421
|
- [v3 to v4 Upgrade Guide](./docs/v4-upgrade.md)
|
650
422
|
|
651
|
-
|
652
423
|
## Contributing
|
424
|
+
|
653
425
|
[![Code Helpers](https://www.codetriage.com/rails/webpacker/badges/users.svg)](https://www.codetriage.com/rails/webpacker)
|
654
426
|
|
655
427
|
We encourage you to contribute to Webpacker! See [CONTRIBUTING](CONTRIBUTING.md) for guidelines about how to proceed.
|
656
428
|
|
657
|
-
|
658
429
|
## License
|
430
|
+
|
659
431
|
Webpacker is released under the [MIT License](https://opensource.org/licenses/MIT).
|