webpacker 4.0.6 → 4.2.2
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/.rubocop.yml +2 -1
- data/.travis.yml +7 -4
- data/CHANGELOG.md +233 -136
- data/Gemfile.lock +78 -59
- data/README.md +110 -3
- data/docs/css.md +12 -0
- data/docs/deployment.md +38 -9
- data/docs/docker.md +25 -6
- data/docs/engines.md +40 -3
- data/docs/es6.md +19 -1
- data/docs/troubleshooting.md +37 -9
- data/docs/typescript.md +8 -5
- data/docs/webpack-dev-server.md +1 -1
- data/docs/webpack.md +18 -3
- data/gemfiles/Gemfile-rails.6.0.x +9 -0
- data/lib/install/bin/webpack +0 -1
- data/lib/install/bin/webpack-dev-server +0 -1
- data/lib/install/coffee.rb +1 -1
- data/lib/install/config/babel.config.js +11 -11
- data/lib/install/config/webpacker.yml +2 -1
- data/lib/install/elm.rb +1 -1
- data/lib/install/erb.rb +2 -2
- data/lib/install/examples/angular/hello_angular/polyfills.ts +2 -2
- data/lib/install/examples/react/babel.config.js +18 -15
- data/lib/install/examples/svelte/app.svelte +11 -0
- data/lib/install/examples/svelte/hello_svelte.js +20 -0
- data/lib/install/loaders/elm.js +9 -6
- data/lib/install/loaders/svelte.js +9 -0
- data/lib/install/loaders/typescript.js +1 -1
- data/lib/install/svelte.rb +29 -0
- data/lib/install/template.rb +1 -1
- data/lib/install/typescript.rb +1 -1
- data/lib/install/vue.rb +1 -1
- data/lib/tasks/installers.rake +1 -0
- data/lib/tasks/webpacker.rake +2 -0
- data/lib/tasks/webpacker/clean.rake +19 -0
- data/lib/tasks/webpacker/compile.rake +2 -10
- data/lib/tasks/webpacker/yarn_install.rake +15 -0
- data/lib/webpacker.rb +9 -1
- data/lib/webpacker/commands.rb +29 -1
- data/lib/webpacker/compiler.rb +15 -8
- data/lib/webpacker/configuration.rb +9 -1
- data/lib/webpacker/dev_server.rb +1 -1
- data/lib/webpacker/dev_server_proxy.rb +2 -8
- data/lib/webpacker/env.rb +1 -1
- data/lib/webpacker/helper.rb +39 -13
- data/lib/webpacker/railtie.rb +6 -0
- data/lib/webpacker/version.rb +1 -1
- data/package.json +36 -37
- data/package/__tests__/config.js +0 -23
- data/package/config.js +2 -10
- data/package/config_types/config_list.js +3 -3
- data/package/config_types/config_object.js +1 -1
- data/package/environments/base.js +2 -2
- data/package/environments/development.js +1 -1
- data/package/environments/production.js +12 -0
- data/package/rules/babel.js +1 -1
- data/package/rules/node_modules.js +2 -2
- data/package/rules/sass.js +1 -1
- data/package/utils/__tests__/get_style_rule.js +9 -0
- data/package/utils/deep_merge.js +5 -5
- data/package/utils/get_style_rule.js +7 -12
- data/package/utils/helpers.js +9 -9
- data/test/command_test.rb +6 -0
- data/test/compiler_test.rb +5 -6
- data/test/configuration_test.rb +36 -27
- data/test/dev_server_test.rb +22 -0
- data/test/helper_test.rb +34 -0
- data/test/rake_tasks_test.rb +6 -0
- data/test/test_app/bin/webpack +0 -1
- data/test/test_app/bin/webpack-dev-server +0 -1
- data/test/test_app/config/webpacker.yml +1 -0
- data/test/test_app/public/packs/manifest.json +3 -0
- data/webpacker.gemspec +1 -0
- data/yarn.lock +1934 -1642
- metadata +24 -4
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
webpacker (4.
|
4
|
+
webpacker (4.2.2)
|
5
5
|
activesupport (>= 4.2)
|
6
6
|
rack-proxy (>= 0.6.1)
|
7
7
|
railties (>= 4.2)
|
@@ -9,60 +9,73 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
actioncable (
|
13
|
-
actionpack (=
|
12
|
+
actioncable (6.0.1)
|
13
|
+
actionpack (= 6.0.1)
|
14
14
|
nio4r (~> 2.0)
|
15
15
|
websocket-driver (>= 0.6.1)
|
16
|
-
|
17
|
-
actionpack (=
|
18
|
-
|
19
|
-
|
16
|
+
actionmailbox (6.0.1)
|
17
|
+
actionpack (= 6.0.1)
|
18
|
+
activejob (= 6.0.1)
|
19
|
+
activerecord (= 6.0.1)
|
20
|
+
activestorage (= 6.0.1)
|
21
|
+
activesupport (= 6.0.1)
|
22
|
+
mail (>= 2.7.1)
|
23
|
+
actionmailer (6.0.1)
|
24
|
+
actionpack (= 6.0.1)
|
25
|
+
actionview (= 6.0.1)
|
26
|
+
activejob (= 6.0.1)
|
20
27
|
mail (~> 2.5, >= 2.5.4)
|
21
28
|
rails-dom-testing (~> 2.0)
|
22
|
-
actionpack (
|
23
|
-
actionview (=
|
24
|
-
activesupport (=
|
29
|
+
actionpack (6.0.1)
|
30
|
+
actionview (= 6.0.1)
|
31
|
+
activesupport (= 6.0.1)
|
25
32
|
rack (~> 2.0)
|
26
33
|
rack-test (>= 0.6.3)
|
27
34
|
rails-dom-testing (~> 2.0)
|
28
|
-
rails-html-sanitizer (~> 1.0, >= 1.0
|
29
|
-
|
30
|
-
|
35
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
36
|
+
actiontext (6.0.1)
|
37
|
+
actionpack (= 6.0.1)
|
38
|
+
activerecord (= 6.0.1)
|
39
|
+
activestorage (= 6.0.1)
|
40
|
+
activesupport (= 6.0.1)
|
41
|
+
nokogiri (>= 1.8.5)
|
42
|
+
actionview (6.0.1)
|
43
|
+
activesupport (= 6.0.1)
|
31
44
|
builder (~> 3.1)
|
32
45
|
erubi (~> 1.4)
|
33
46
|
rails-dom-testing (~> 2.0)
|
34
|
-
rails-html-sanitizer (~> 1.
|
35
|
-
activejob (
|
36
|
-
activesupport (=
|
47
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
48
|
+
activejob (6.0.1)
|
49
|
+
activesupport (= 6.0.1)
|
37
50
|
globalid (>= 0.3.6)
|
38
|
-
activemodel (
|
39
|
-
activesupport (=
|
40
|
-
activerecord (
|
41
|
-
activemodel (=
|
42
|
-
activesupport (=
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
activerecord (=
|
51
|
+
activemodel (6.0.1)
|
52
|
+
activesupport (= 6.0.1)
|
53
|
+
activerecord (6.0.1)
|
54
|
+
activemodel (= 6.0.1)
|
55
|
+
activesupport (= 6.0.1)
|
56
|
+
activestorage (6.0.1)
|
57
|
+
actionpack (= 6.0.1)
|
58
|
+
activejob (= 6.0.1)
|
59
|
+
activerecord (= 6.0.1)
|
47
60
|
marcel (~> 0.3.1)
|
48
|
-
activesupport (
|
61
|
+
activesupport (6.0.1)
|
49
62
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
50
63
|
i18n (>= 0.7, < 2)
|
51
64
|
minitest (~> 5.1)
|
52
65
|
tzinfo (~> 1.1)
|
53
|
-
|
66
|
+
zeitwerk (~> 2.2)
|
54
67
|
ast (2.4.0)
|
55
68
|
builder (3.2.3)
|
56
69
|
byebug (11.0.1)
|
57
70
|
concurrent-ruby (1.1.5)
|
58
|
-
crass (1.0.
|
59
|
-
erubi (1.
|
71
|
+
crass (1.0.5)
|
72
|
+
erubi (1.9.0)
|
60
73
|
globalid (0.4.2)
|
61
74
|
activesupport (>= 4.2.0)
|
62
|
-
i18n (1.
|
75
|
+
i18n (1.7.0)
|
63
76
|
concurrent-ruby (~> 1.0)
|
64
|
-
jaro_winkler (1.5.
|
65
|
-
loofah (2.
|
77
|
+
jaro_winkler (1.5.4)
|
78
|
+
loofah (2.3.1)
|
66
79
|
crass (~> 1.0.2)
|
67
80
|
nokogiri (>= 1.5.9)
|
68
81
|
mail (2.7.1)
|
@@ -71,46 +84,48 @@ GEM
|
|
71
84
|
mimemagic (~> 0.3.2)
|
72
85
|
method_source (0.9.2)
|
73
86
|
mimemagic (0.3.3)
|
74
|
-
mini_mime (1.0.
|
87
|
+
mini_mime (1.0.2)
|
75
88
|
mini_portile2 (2.4.0)
|
76
|
-
minitest (5.
|
77
|
-
nio4r (2.
|
78
|
-
nokogiri (1.10.
|
89
|
+
minitest (5.13.0)
|
90
|
+
nio4r (2.5.2)
|
91
|
+
nokogiri (1.10.5)
|
79
92
|
mini_portile2 (~> 2.4.0)
|
80
|
-
parallel (1.
|
81
|
-
parser (2.6.
|
93
|
+
parallel (1.18.0)
|
94
|
+
parser (2.6.5.0)
|
82
95
|
ast (~> 2.4.0)
|
83
96
|
rack (2.0.7)
|
84
97
|
rack-proxy (0.6.5)
|
85
98
|
rack
|
86
99
|
rack-test (1.1.0)
|
87
100
|
rack (>= 1.0, < 3)
|
88
|
-
rails (
|
89
|
-
actioncable (=
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
101
|
+
rails (6.0.1)
|
102
|
+
actioncable (= 6.0.1)
|
103
|
+
actionmailbox (= 6.0.1)
|
104
|
+
actionmailer (= 6.0.1)
|
105
|
+
actionpack (= 6.0.1)
|
106
|
+
actiontext (= 6.0.1)
|
107
|
+
actionview (= 6.0.1)
|
108
|
+
activejob (= 6.0.1)
|
109
|
+
activemodel (= 6.0.1)
|
110
|
+
activerecord (= 6.0.1)
|
111
|
+
activestorage (= 6.0.1)
|
112
|
+
activesupport (= 6.0.1)
|
98
113
|
bundler (>= 1.3.0)
|
99
|
-
railties (=
|
114
|
+
railties (= 6.0.1)
|
100
115
|
sprockets-rails (>= 2.0.0)
|
101
116
|
rails-dom-testing (2.0.3)
|
102
117
|
activesupport (>= 4.2.0)
|
103
118
|
nokogiri (>= 1.6)
|
104
|
-
rails-html-sanitizer (1.0
|
105
|
-
loofah (~> 2.
|
106
|
-
railties (
|
107
|
-
actionpack (=
|
108
|
-
activesupport (=
|
119
|
+
rails-html-sanitizer (1.3.0)
|
120
|
+
loofah (~> 2.3)
|
121
|
+
railties (6.0.1)
|
122
|
+
actionpack (= 6.0.1)
|
123
|
+
activesupport (= 6.0.1)
|
109
124
|
method_source
|
110
125
|
rake (>= 0.8.7)
|
111
|
-
thor (>= 0.
|
126
|
+
thor (>= 0.20.3, < 2.0)
|
112
127
|
rainbow (3.0.0)
|
113
|
-
rake (
|
128
|
+
rake (13.0.0)
|
114
129
|
rubocop (0.68.1)
|
115
130
|
jaro_winkler (~> 1.5.1)
|
116
131
|
parallel (~> 1.10)
|
@@ -118,8 +133,10 @@ GEM
|
|
118
133
|
rainbow (>= 2.2.2, < 4.0)
|
119
134
|
ruby-progressbar (~> 1.7)
|
120
135
|
unicode-display_width (>= 1.4.0, < 1.6)
|
136
|
+
rubocop-performance (1.3.0)
|
137
|
+
rubocop (>= 0.68.0)
|
121
138
|
ruby-progressbar (1.10.1)
|
122
|
-
sprockets (
|
139
|
+
sprockets (4.0.0)
|
123
140
|
concurrent-ruby (~> 1.0)
|
124
141
|
rack (> 1, < 3)
|
125
142
|
sprockets-rails (3.2.1)
|
@@ -131,9 +148,10 @@ GEM
|
|
131
148
|
tzinfo (1.2.5)
|
132
149
|
thread_safe (~> 0.1)
|
133
150
|
unicode-display_width (1.5.0)
|
134
|
-
websocket-driver (0.7.
|
151
|
+
websocket-driver (0.7.1)
|
135
152
|
websocket-extensions (>= 0.1.0)
|
136
|
-
websocket-extensions (0.1.
|
153
|
+
websocket-extensions (0.1.4)
|
154
|
+
zeitwerk (2.2.1)
|
137
155
|
|
138
156
|
PLATFORMS
|
139
157
|
ruby
|
@@ -146,6 +164,7 @@ DEPENDENCIES
|
|
146
164
|
rails
|
147
165
|
rake (>= 11.1)
|
148
166
|
rubocop (< 0.69)
|
167
|
+
rubocop-performance
|
149
168
|
webpacker!
|
150
169
|
|
151
170
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
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%
|
4
|
+
[![node.js](https://img.shields.io/badge/node-%3E%3D%208.16.0-brightgreen.svg)](https://nodejs.org/en/)
|
5
5
|
[![Gem](https://img.shields.io/gem/v/webpacker.svg)](https://github.com/rails/webpacker)
|
6
6
|
|
7
7
|
Webpacker makes it easy to use the JavaScript pre-processor and bundler
|
@@ -34,6 +34,7 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
34
34
|
- [Vue](#vue)
|
35
35
|
- [Elm](#elm)
|
36
36
|
- [Stimulus](#stimulus)
|
37
|
+
- [Svelte](#svelte)
|
37
38
|
- [CoffeeScript](#coffeescript)
|
38
39
|
- [Erb](#erb)
|
39
40
|
- [Paths](#paths)
|
@@ -51,7 +52,7 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
51
52
|
|
52
53
|
* Ruby 2.2+
|
53
54
|
* Rails 4.2+
|
54
|
-
* Node.js
|
55
|
+
* Node.js 8.16.0+
|
55
56
|
* Yarn 1.x+
|
56
57
|
|
57
58
|
|
@@ -89,6 +90,7 @@ gem 'webpacker', '~> 4.x'
|
|
89
90
|
# OR if you prefer to use master
|
90
91
|
gem 'webpacker', git: 'https://github.com/rails/webpacker.git'
|
91
92
|
yarn add https://github.com/rails/webpacker.git
|
93
|
+
yarn add core-js regenerator-runtime
|
92
94
|
```
|
93
95
|
|
94
96
|
Finally, run the following to install Webpacker:
|
@@ -122,6 +124,13 @@ app/javascript:
|
|
122
124
|
└── logo.svg
|
123
125
|
```
|
124
126
|
|
127
|
+
In `/packs/application.js`, include this at the top of the file:
|
128
|
+
|
129
|
+
```js
|
130
|
+
import "core-js/stable";
|
131
|
+
import "regenerator-runtime/runtime";
|
132
|
+
```
|
133
|
+
|
125
134
|
You can then link the JavaScript pack in Rails views using the `javascript_pack_tag` helper.
|
126
135
|
If you have styles imported in your pack file, you can link them by using `stylesheet_pack_tag`:
|
127
136
|
|
@@ -407,6 +416,72 @@ end
|
|
407
416
|
```
|
408
417
|
You can read more about this in the [Vue docs](https://vuejs.org/v2/guide/installation.html#CSP-environments).
|
409
418
|
|
419
|
+
#### Lazy loading integration
|
420
|
+
|
421
|
+
See [docs/es6](docs/es6.md) to know more about Webpack and Webpacker configuration.
|
422
|
+
|
423
|
+
For instance, you can lazy load Vue JS components:
|
424
|
+
|
425
|
+
Before:
|
426
|
+
```js
|
427
|
+
import Vue from 'vue'
|
428
|
+
import { VCard } from 'vuetify/lib'
|
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
|
+
```
|
410
485
|
|
411
486
|
### Elm
|
412
487
|
|
@@ -424,6 +499,20 @@ The Elm library and its core packages will be added via Yarn and Elm.
|
|
424
499
|
An example `Main.elm` app will also be added to your project in `app/javascript`
|
425
500
|
so that you can experiment with Elm right away.
|
426
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
|
+
|
427
516
|
### Stimulus
|
428
517
|
|
429
518
|
To use Webpacker with [Stimulus](http://stimulusjs.org), create a
|
@@ -539,7 +628,25 @@ Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which
|
|
539
628
|
|
540
629
|
## Docs
|
541
630
|
|
542
|
-
|
631
|
+
- [Development](https://github.com/rails/webpacker#development)
|
632
|
+
- [Webpack](./docs/webpack.md)
|
633
|
+
- [Webpack-dev-server](./docs/webpack-dev-server.md)
|
634
|
+
- [Environment Variables](./docs/env.md)
|
635
|
+
- [Folder Structure](./docs/folder-structure.md)
|
636
|
+
- [Assets](./docs/assets.md)
|
637
|
+
- [CSS, Sass and SCSS](./docs/css.md)
|
638
|
+
- [ES6](./docs/es6.md)
|
639
|
+
- [Props](./docs/props.md)
|
640
|
+
- [Typescript](./docs/typescript.md)
|
641
|
+
- [Yarn](./docs/yarn.md)
|
642
|
+
- [Misc](./docs/misc.md)
|
643
|
+
- [Deployment](./docs/deployment.md)
|
644
|
+
- [Docker](./docs/docker.md)
|
645
|
+
- [Using in Rails engines](./docs/engines.md)
|
646
|
+
- [Webpacker on Cloud9](./docs/cloud9.md)
|
647
|
+
- [Testing](./docs/testing.md)
|
648
|
+
- [Troubleshooting](./docs/troubleshooting.md)
|
649
|
+
- [v3 to v4 Upgrade Guide](./docs/v4-upgrade.md)
|
543
650
|
|
544
651
|
|
545
652
|
## Contributing
|
data/docs/css.md
CHANGED
@@ -3,6 +3,18 @@
|
|
3
3
|
|
4
4
|
Webpacker supports importing CSS, Sass and SCSS files directly into your JavaScript files.
|
5
5
|
|
6
|
+
Importing and loading styles is a two step process:
|
7
|
+
|
8
|
+
1. You need to tell webpack which file(s) it has to compile and know how to load
|
9
|
+
|
10
|
+
When you do `import '../scss/application.scss'`, you're telling webpack to include `application.scss` in the build. This does not mean it's going to be compiled into your javascript, only that webpack now compiles and knows how to load this file. (How that file compilation is handled is depending on how your loaders (`css-loader`, `sass-loader`, `file-loader`, etc.) are configured.)
|
11
|
+
|
12
|
+
2. You need to load those files in your views
|
13
|
+
|
14
|
+
In order to have styles load in production, you need to include `stylesheet_pack_tag` with the same name as the javascript file that imports the styles.
|
15
|
+
|
16
|
+
When you do `<%= stylesheet_pack_tag 'application' %>`, that's a run-time inclusion from Rails, where Rails gets the correct "asset path" to that file from webpack.
|
17
|
+
|
6
18
|
|
7
19
|
## Import global styles into your JS app
|
8
20
|
|
data/docs/deployment.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Deployment
|
2
2
|
|
3
3
|
|
4
|
-
Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which gets run whenever you run `assets:precompile`.
|
4
|
+
Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which gets run whenever you run `assets:precompile`.
|
5
5
|
If you are not using Sprockets `webpacker:compile` is automatically aliased to `assets:precompile`. Remember to set NODE_ENV environment variable to production during deployment or when running the rake task.
|
6
6
|
|
7
7
|
The `javascript_pack_tag` and `stylesheet_pack_tag` helper method will automatically insert the correct HTML tag for compiled pack. Just like the asset pipeline does it.
|
@@ -20,30 +20,39 @@ By default the output will look like this in different environments:
|
|
20
20
|
|
21
21
|
## Heroku
|
22
22
|
|
23
|
-
|
24
|
-
Webpacker so all you would need to do:
|
23
|
+
In order for your Webpacker app to run on Heroku, you'll need to do a bit of configuration before hand.
|
25
24
|
|
26
|
-
```
|
27
|
-
heroku create
|
25
|
+
```
|
26
|
+
heroku create my-webpacker-heroku-app
|
28
27
|
heroku addons:create heroku-postgresql:hobby-dev
|
28
|
+
heroku buildpacks:add heroku/nodejs
|
29
|
+
heroku buildpacks:add heroku/ruby
|
29
30
|
git push heroku master
|
30
31
|
```
|
31
32
|
|
33
|
+
We're essentially doing the following here:
|
34
|
+
|
35
|
+
* Creating an app on Heroku
|
36
|
+
* Creating a Postgres database for the app (this is assuming that you're using Heroku Postgres for your app)
|
37
|
+
* Adding the Heroku NodeJS and Ruby buildpacks for your app. This allows the `npm` or `yarn` executables to properly function when compiling your app - as well as Ruby.
|
38
|
+
* Pushing our code to Heroku and kicking off the deployment
|
39
|
+
|
32
40
|
|
33
41
|
## Nginx
|
34
42
|
|
35
43
|
Webpacker doesn't serve anything in production. You’re expected to configure your web server to serve files in public/ directly.
|
36
44
|
|
37
|
-
Some servers support sending precompressed versions of files
|
45
|
+
Some servers support sending precompressed versions of files when they're available. For example, nginx offers a `gzip_static` directive that serves files with the `.gz` extension to supported clients. With an optional module, nginx can also serve Brotli compressed files with the `.br` extension (see below for installation and configuration instructions).
|
38
46
|
|
39
47
|
Here's a sample nginx site config for a Rails app using Webpacker:
|
40
48
|
|
41
49
|
```nginx
|
42
50
|
upstream app {
|
43
|
-
#
|
51
|
+
# server unix:///path/to/app/tmp/puma.sock;
|
44
52
|
}
|
45
53
|
|
46
54
|
server {
|
55
|
+
listen 80;
|
47
56
|
server_name www.example.com;
|
48
57
|
root /path/to/app/public;
|
49
58
|
|
@@ -61,13 +70,34 @@ server {
|
|
61
70
|
try_files $uri @app;
|
62
71
|
}
|
63
72
|
|
64
|
-
location
|
73
|
+
location = /favicon.ico { access_log off; log_not_found off; }
|
74
|
+
location = /robots.txt { access_log off; log_not_found off; }
|
75
|
+
|
76
|
+
location ~ /\.(?!well-known).* {
|
77
|
+
deny all;
|
78
|
+
}
|
79
|
+
|
80
|
+
location ~ ^/(assets|packs)/ {
|
65
81
|
gzip_static on;
|
82
|
+
brotli_static on; # Optional, see below
|
66
83
|
expires max;
|
84
|
+
add_header Cache-Control public;
|
67
85
|
}
|
68
86
|
}
|
69
87
|
```
|
70
88
|
|
89
|
+
### Installing the ngx_brotli module
|
90
|
+
|
91
|
+
If you want to serve Brotli compressed files with nginx, you will need to install the `nginx_brotli` module. Installation instructions from source can be found in the official [google/ngx_brotli](https://github.com/google/ngx_brotli) git repository. Alternatively, depending on your platform, the module might be available via a pre-compiled package.
|
92
|
+
|
93
|
+
Once installed, you need to load the module. As we want to serve the pre-compressed files, we only need the static module. Add the following line to your `nginx.conf` file and reload nginx:
|
94
|
+
|
95
|
+
```
|
96
|
+
load_module modules/ngx_http_brotli_static_module.so;
|
97
|
+
```
|
98
|
+
|
99
|
+
Now, you can set `brotli_static on;` in your nginx site config, as per the config in the last section above.
|
100
|
+
|
71
101
|
## CDN
|
72
102
|
|
73
103
|
Webpacker out-of-the-box provides CDN support using your Rails app `config.action_controller.asset_host` setting. If you already have [CDN](http://guides.rubyonrails.org/asset_pipeline.html#cdns) added in your Rails app
|
@@ -98,4 +128,3 @@ namespace :deploy do
|
|
98
128
|
end
|
99
129
|
end
|
100
130
|
```
|
101
|
-
|