webpacker 3.0.2 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintignore +1 -0
  3. data/.travis.yml +10 -0
  4. data/CHANGELOG.md +110 -0
  5. data/Gemfile.lock +69 -67
  6. data/MIT-LICENSE +1 -1
  7. data/README.md +86 -30
  8. data/docs/assets.md +4 -4
  9. data/docs/cloud9.md +310 -0
  10. data/docs/css.md +32 -3
  11. data/docs/deployment.md +42 -4
  12. data/docs/docker.md +49 -0
  13. data/docs/env.md +5 -5
  14. data/docs/folder-structure.md +2 -2
  15. data/docs/testing.md +14 -34
  16. data/docs/troubleshooting.md +40 -4
  17. data/docs/typescript.md +2 -2
  18. data/docs/webpack-dev-server.md +21 -4
  19. data/docs/webpack.md +103 -25
  20. data/gemfiles/Gemfile-rails-edge +13 -0
  21. data/gemfiles/Gemfile-rails.4.2.x +10 -0
  22. data/gemfiles/Gemfile-rails.5.0.x +10 -0
  23. data/gemfiles/Gemfile-rails.5.1.x +10 -0
  24. data/lib/install/angular.rb +5 -5
  25. data/lib/install/config/webpacker.yml +7 -0
  26. data/lib/install/elm.rb +7 -7
  27. data/lib/install/examples/vue/hello_vue.js +30 -4
  28. data/lib/install/react.rb +5 -5
  29. data/lib/install/template.rb +19 -9
  30. data/lib/install/vue.rb +4 -4
  31. data/lib/tasks/installers.rake +2 -2
  32. data/lib/tasks/webpacker.rake +7 -6
  33. data/lib/tasks/webpacker/check_binstubs.rake +3 -3
  34. data/lib/tasks/webpacker/compile.rake +15 -8
  35. data/lib/tasks/webpacker/install.rake +4 -4
  36. data/lib/tasks/webpacker/verify_install.rake +1 -1
  37. data/lib/webpacker/compiler.rb +6 -6
  38. data/lib/webpacker/dev_server.rb +2 -2
  39. data/lib/webpacker/dev_server_proxy.rb +2 -1
  40. data/lib/webpacker/dev_server_runner.rb +4 -4
  41. data/lib/webpacker/helper.rb +3 -3
  42. data/lib/webpacker/manifest.rb +2 -2
  43. data/lib/webpacker/railtie.rb +41 -2
  44. data/lib/webpacker/runner.rb +1 -1
  45. data/lib/webpacker/version.rb +1 -1
  46. data/package.json +29 -21
  47. data/package/asset_host.js +4 -5
  48. data/package/config.js +7 -1
  49. data/package/config_types/__tests__/config_list.js +123 -0
  50. data/package/config_types/__tests__/config_object.js +43 -0
  51. data/package/config_types/config_list.js +83 -0
  52. data/package/config_types/config_object.js +55 -0
  53. data/package/config_types/index.js +7 -0
  54. data/package/environment.js +64 -40
  55. data/package/environments/development.js +31 -34
  56. data/package/environments/production.js +14 -11
  57. data/package/index.js +7 -2
  58. data/package/{loaders → rules}/babel.js +6 -4
  59. data/package/{loaders → rules}/coffee.js +3 -1
  60. data/package/rules/css.js +39 -0
  61. data/package/rules/elm.js +23 -0
  62. data/package/rules/erb.js +11 -0
  63. data/package/{loaders → rules}/file.js +1 -1
  64. data/package/rules/index.js +23 -0
  65. data/package/rules/sass.js +15 -0
  66. data/package/{loaders → rules}/typescript.js +3 -1
  67. data/package/rules/url.js +13 -0
  68. data/package/rules/vue.js +13 -0
  69. data/package/utils/__tests__/deep_assign.js +11 -0
  70. data/package/utils/__tests__/deep_merge.js +10 -0
  71. data/package/utils/__tests__/objectify.js +9 -0
  72. data/package/utils/deep_assign.js +22 -0
  73. data/package/utils/deep_merge.js +23 -0
  74. data/package/utils/helpers.js +32 -0
  75. data/package/utils/objectify.js +4 -0
  76. data/test/command_test.rb +1 -1
  77. data/test/compiler_test.rb +5 -1
  78. data/test/configuration_test.rb +1 -1
  79. data/test/dev_server_test.rb +1 -1
  80. data/test/helper_test.rb +15 -10
  81. data/test/manifest_test.rb +1 -1
  82. data/test/rake_tasks_test.rb +29 -0
  83. data/test/test_app/Rakefile +3 -0
  84. data/test/test_app/config/application.rb +11 -0
  85. data/test/test_app/config/environment.rb +4 -0
  86. data/test/{webpacker_test_helper.rb → test_helper.rb} +3 -14
  87. data/webpacker.gemspec +1 -1
  88. data/yarn.lock +1552 -829
  89. metadata +43 -16
  90. data/package/loaders/elm.js +0 -19
  91. data/package/loaders/erb.js +0 -9
  92. data/package/loaders/style.js +0 -31
  93. data/package/loaders/vue.js +0 -12
  94. data/test/test_app/config/secrets.yml +0 -5
data/docs/assets.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
  Static assets like images and fonts support is enabled out-of-box
5
- and you can link them into your javascript app code and have them
5
+ and you can link them into your JavaScript app code and have them
6
6
  compiled automatically.
7
7
 
8
8
 
@@ -34,15 +34,15 @@ import '../styles'
34
34
  ```
35
35
 
36
36
 
37
- ## Import from sprockets using helpers
37
+ ## Import from Sprockets using helpers
38
38
 
39
- It's possible to link to assets that have been precompiled by sprockets. Add the `.erb` extension to your javascript file, then you can use Sprockets' asset helpers:
39
+ It's possible to link to assets that have been precompiled by Sprockets. Add the `.erb` extension to your JavaScript file, then you can use Sprockets' asset helpers:
40
40
 
41
41
  ```erb
42
42
  <%# app/javascript/my_pack/example.js.erb %>
43
43
 
44
44
  <% helpers = ActionController::Base.helpers %>
45
- var railsImagePath = "<%= helpers.image_path('rails.png') %>"
45
+ const railsImagePath = "<%= helpers.image_path('rails.png') %>"
46
46
  ```
47
47
 
48
48
  This is enabled by the `rails-erb-loader` loader rule in `config/webpack/loaders/erb.js`.
data/docs/cloud9.md ADDED
@@ -0,0 +1,310 @@
1
+ # Webpack dev server and Rails on Cloud9
2
+
3
+ **Please note that this article is particularly relevant when
4
+ migrating the [`webpacker`] gem from v3.0.1 to v3.0.2, as described in
5
+ the [below](#binstub-versions).**
6
+
7
+ [**`[Go to tl;dr]`**](#tldr)
8
+
9
+ ## Contents
10
+
11
+ - [Context](#context)
12
+ - [Binstub versions](#binstub-versions)
13
+ - [Quick solution](#quick-solution)
14
+ - [Flexible solution](#flexible-solution)
15
+ - [Sources](#sources)
16
+ - [Versions](#versions)
17
+ - [tl;dr](#tldr)
18
+
19
+ ## Context
20
+
21
+ This article describes how to properly configure
22
+ [`webpack-dev-server`] with [`webpacker`] gem on a [Cloud9] workspace.
23
+ After a preliminary remark about the proper binstub version of the
24
+ `./bin/webpack-dev-server` script, this article presents two ways to
25
+ tackle the task: a simple and [quick solution](#quick-solution), which
26
+ is sufficient if we work alone on a project, and a slightly more
27
+ involved but [flexible approach](#flexible-solution), that can be
28
+ useful when several people might work in the same codebase.
29
+
30
+ [Cloud9]: https://c9.io
31
+ [`webpack-dev-server`]: https://github.com/webpack/webpack-dev-server
32
+ [`webpacker`]: https://github.com/rails/webpacker
33
+
34
+ ## Binstub versions
35
+
36
+ A lot of the confusion about the [`webpack-dev-server`] options and
37
+ why they might not be properly taken into account, might be due to an
38
+ outdated version of the `./bin/webpack-dev-server` script. The script
39
+ created by the `rails webpacker:install` task of the [`webpacker`] gem
40
+ v3.0.1 ([source][v3.0.1/lib/install/bin/webpack-dev-server.tt]) is not
41
+ compatible with how v3.0.2 (sic) of the gem handles the
42
+ [`webpack-dev-server`] option flags (see full list of
43
+ [versions](#versions) below), which logically expects the
44
+ corresponding [binstub version][#833] of the script
45
+ ([source][v3.0.2/exe/webpack-dev-server]). So please make sure that
46
+ you are using the [correct binstub][v3.0.2/exe/webpack-dev-server]
47
+ (the same applies to [`./bin/webpack`][v3.0.2/exe/webpack]). To be
48
+ fair, the [changelog of v3.0.2] properly mentions the change:
49
+
50
+ > - Added: Binstubs [#833]
51
+ > - (...)
52
+ > - Removed: Inline CLI args for dev server binstub, use env variables
53
+ instead
54
+
55
+ [changelog of v3.0.2]: https://github.com/rails/webpacker/blob/v3.0.2/CHANGELOG.md#302---2017-10-04
56
+ [v3.0.1/lib/install/bin/webpack-dev-server.tt]: https://github.com/rails/webpacker/blob/v3.0.1/lib/install/bin/webpack-dev-server.tt
57
+ [v3.0.2/exe/webpack-dev-server]: https://github.com/rails/webpacker/blob/v3.0.2/exe/webpack-dev-server
58
+ [v3.0.2/exe/webpack]: https://github.com/rails/webpacker/blob/v3.0.2/exe/webpack
59
+ [#833]: https://github.com/rails/webpacker/pull/833/files
60
+
61
+ ## Quick solution
62
+
63
+ If you are working alone, the easiest way to fix the configuration of
64
+ the [`webpack-dev-server`] is to modify the `development.dev_server`
65
+ entry of the `config/webpacker.yml` file.
66
+
67
+ ### `config/webpacker.yml` file
68
+
69
+ The `development.dev_server` entry of the `config/webpacker.yml` file
70
+ has to be changed from the following default values:
71
+
72
+ ```yaml
73
+ dev_server:
74
+ https: false
75
+ host: localhost
76
+ port: 3035
77
+ public: localhost:3035
78
+ hmr: false
79
+ # Inline should be set to true if using HMR
80
+ inline: true
81
+ overlay: true
82
+ disable_host_check: true
83
+ use_local_ip: false
84
+ ```
85
+
86
+ into the these custom configuration:
87
+
88
+ ```yaml
89
+ dev_server:
90
+ https: true
91
+ host: localhost
92
+ port: 8082
93
+ public: your-workspace-name-yourusername.c9users.io:8082
94
+ hmr: false
95
+ inline: false
96
+ overlay: true
97
+ disable_host_check: true
98
+ use_local_ip: false
99
+ ```
100
+
101
+ You can obtain the value `your-workspace-name-yourusername.c9users.io`
102
+ for your [Cloud9] workspace with `echo ${C9_HOSTNAME}`.
103
+
104
+ There are four main differences with the approaches found in the
105
+ mentioned [sources](#sources):
106
+
107
+ - Some solutions suggested to set the [`host`][devserver-host] option
108
+ to `your-workspace-name-yourusername.c9users.io`, which required to
109
+ add a line to the `/etc/hosts` file by running `echo "0.0.0.0
110
+ ${C9_HOSTNAME}" | sudo tee -a /etc/hosts`. This was only necessary
111
+ due to restrictions in previous versions of [`webpacker`] and how
112
+ the value of the [`public`][devserver-public] setting was
113
+ calculated. Currently it is [no longer necessary][pr-comment-hosts]
114
+ to modify the `/etc/hosts` file because the [`host`][devserver-host]
115
+ setting can be kept as `localhost`.
116
+
117
+ [pr-comment-hosts]: https://github.com/rails/webpacker/pull/1033#pullrequestreview-78992024
118
+
119
+ - Some solutions stressed the need to set the
120
+ [`https`][devserver-https] option to `false` but this failed with
121
+ `net::ERR_ABORTED` in the browser console and raised the following
122
+ exception in the server when the client tried to get the
123
+ JavaScript sources:
124
+
125
+ ```
126
+ #<OpenSSL::SSL::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=unknown state>
127
+ ```
128
+
129
+ Setting `https: true` removes the issue.
130
+
131
+ - By leaving the [`inline`][devserver-inline] option to the default
132
+ `false` value, the live compilation still works but the browser
133
+ console constantly reports the following error:
134
+
135
+ ```
136
+ Failed to load https://your-workspace-name-yourusername.c9users.io:8082/sockjs-node/info?t=1511016561187: No 'Access-Control-Allow-Origin' header is present on the requested resource.
137
+ Origin 'https://your-workspace-name-yourusername.c9users.io' is therefore not allowed access. The response had HTTP status code 503.
138
+ ```
139
+
140
+ Setting `inline: false` removes the issue.
141
+
142
+
143
+ - None of the solutions suggested to set the
144
+ [`public`][devserver-public] option in the `config/webpacker.yml`
145
+ file and some suggested to pass it to the `webpack-dev-server`
146
+ command line. By setting it in the configuration file we don't need
147
+ to care about it in the terminal.
148
+
149
+ [devserver-host]: https://webpack.js.org/configuration/dev-server/#devserver-host
150
+ [devserver-https]: https://webpack.js.org/configuration/dev-server/#devserver-https
151
+ [devserver-inline]: https://webpack.js.org/configuration/dev-server/#devserver-inline
152
+ [devserver-public]: https://webpack.js.org/configuration/dev-server/#devserver-public
153
+
154
+ With this configuration, running as usual `./bin/webpack-dev-server`
155
+ in one terminal and `./bin/rails s -b $IP -p $PORT` in another should
156
+ work.
157
+
158
+ ## Flexible solution
159
+
160
+ The previous solution is useful and fast to implement, but if you are
161
+ working with other people on the same repo it can be tricky to
162
+ maintain the proper configuration in the `config/webpacker.yml` file.
163
+ Moreover, the hostname of your [Cloud9] workspace is hardcoded, so
164
+ that the configuration is not portable.
165
+
166
+ A hint about another way to configure the `webpack-dev-server` can be
167
+ found in the [README of this repo][`webpacker` documentation]:
168
+
169
+ > You can use environment variables as options supported by
170
+ > webpack-dev-server in the form `WEBPACKER_DEV_SERVER_<OPTION>`.
171
+ > Please note that these environment variables will always take
172
+ > precedence over the ones already set in the configuration file.
173
+
174
+ Note that when the configuration of the [`webpack-dev-server`] is
175
+ tweaked with ENV variables, those same values _have to be passed_ to
176
+ the `rails server` process as well in order to let it use the _same_
177
+ configuration.
178
+
179
+ Taking that into account, a flexible solution can be implemented using
180
+ [`foreman`] with the following `Procfile.dev`:
181
+
182
+ [`foreman`]: https://github.com/ddollar/foreman
183
+
184
+ ```Procfile
185
+ web: ./bin/rails server -b ${RAILS_SERVER_BINDING:-localhost} -p ${RAILS_SERVER_PORT:-3000}
186
+ webpacker: ./bin/webpack-dev-server
187
+ ```
188
+
189
+ and this `bin/start` script:
190
+
191
+ ```bash
192
+ #!/bin/bash
193
+
194
+ # Immediately exit script on first error
195
+ set -e -o pipefail
196
+
197
+ APP_ROOT_FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
198
+ cd "${APP_ROOT_FOLDER}"
199
+
200
+ if [ -n "${C9_USER}" ]; then
201
+ # We are in a Cloud9 machine
202
+
203
+ # Make sure that Postgres is running
204
+ sudo service postgresql status || sudo service postgresql start
205
+
206
+ # Adapt the configuration of the webpack-dev-server
207
+ export APP_DOMAIN="${C9_HOSTNAME}"
208
+ export RAILS_SERVER_BINDING='0.0.0.0'
209
+ export RAILS_SERVER_PORT='8080'
210
+ export WEBPACKER_DEV_SERVER_PORT='8082'
211
+ export WEBPACKER_DEV_SERVER_HTTPS='true'
212
+ export WEBPACKER_DEV_SERVER_HOST="localhost"
213
+ export WEBPACKER_DEV_SERVER_PUBLIC="${C9_HOSTNAME}:${WEBPACKER_DEV_SERVER_PORT}"
214
+ export WEBPACKER_DEV_SERVER_HMR='false'
215
+ export WEBPACKER_DEV_SERVER_INLINE='false'
216
+ export WEBPACKER_DEV_SERVER_OVERLAY='true'
217
+ export WEBPACKER_DEV_SERVER_DISABLE_HOST_CHECK='true'
218
+ export WEBPACKER_DEV_SERVER_USE_LOCAL_IP='false'
219
+ fi
220
+
221
+ foreman start -f Procfile.dev
222
+ ```
223
+
224
+ With these two scripts in place, the application can always be started
225
+ by running `bin/start`, in both [Cloud9] and other systems. The
226
+ trick is that by exporting the `WEBPACKER_DEV_SERVER_*` variables
227
+ before calling `foreman start`, we make sure that those values are
228
+ available to both `webpack-dev-server` and `rails server` processes.
229
+
230
+ ## Sources
231
+
232
+ - ["Webpack dev server and Rails on Cloud9"][original-article] (the
233
+ original source for the present article, inspired by this
234
+ [comment][original-comment])
235
+ - ["Making Webpacker run on Cloud 9"] (GitHub issue)
236
+ - ["Anyone here got webpack-dev-server to work on Cloud 9?"] (GitHub issue)
237
+ - [`webpacker` documentation]
238
+ - [`webpacker/dev_server.rb` code]
239
+ - [`webpack-dev-server` documentation]
240
+ - ["Using Rails With Webpack in Cloud 9"] (blog article)
241
+
242
+ [original-article]: http://rbf.io/en/blog/2017/11/18/webpack-dev-server-and-rails-on-cloud9/
243
+ [original-comment]: https://github.com/rails/webpacker/issues/176#issuecomment-345532309
244
+ ["Making Webpacker run on Cloud 9"]: https://github.com/rails/webpacker/issues/176
245
+ ["Anyone here got webpack-dev-server to work on Cloud 9?"]: https://github.com/webpack/webpack-dev-server/issues/230
246
+ [`webpacker` documentation]: https://github.com/rails/webpacker/tree/v3.0.2#development
247
+ [`webpacker/dev_server.rb` code]: https://github.com/rails/webpacker/blob/v3.0.2/lib/webpacker/dev_server.rb#L55
248
+ [`webpack-dev-server` documentation]: https://webpack.js.org/configuration/dev-server/
249
+ ["Using Rails With Webpack in Cloud 9"]: http://aalvarez.me/blog/posts/using-rails-with-webpack-in-cloud-9.html
250
+
251
+ ## Versions
252
+
253
+ Since things in this ecosystem move fast, it's important to mention the
254
+ versions of the world for which this documentation is relevant:
255
+
256
+ ```shell
257
+ $ egrep '^ ?(ruby|webpacker|rails) ' Gemfile.lock
258
+ rails (5.1.4)
259
+ webpacker (3.0.2)
260
+ ruby 2.4.2p198
261
+
262
+ $ yarn versions
263
+ yarn versions v1.1.0
264
+ { http_parser: '2.7.0',
265
+ node: '8.5.0',
266
+ v8: '6.0.287.53',
267
+ uv: '1.14.1',
268
+ zlib: '1.2.11',
269
+ ares: '1.10.1-DEV',
270
+ modules: '57',
271
+ nghttp2: '1.25.0',
272
+ openssl: '1.0.2l',
273
+ icu: '59.1',
274
+ unicode: '9.0',
275
+ cldr: '31.0.1',
276
+ tz: '2017b' }
277
+
278
+ $ cat /etc/os-release | head -6
279
+ NAME="Ubuntu"
280
+ VERSION="14.04.5 LTS, Trusty Tahr"
281
+ ID=ubuntu
282
+ ID_LIKE=debian
283
+ PRETTY_NAME="Ubuntu 14.04.5 LTS"
284
+ VERSION_ID="14.04"
285
+ ```
286
+
287
+ Everything was tested using Chrome Version 62.
288
+
289
+ ## tl;dr
290
+
291
+ 1. Make sure that you are running the [proper binstub
292
+ version](#binstub-versions) of `./bin/webpack-dev-server`.
293
+
294
+ 1. Change the `development.dev_server` entry `config/webpacker.yml` file into:
295
+
296
+ ```yaml
297
+ dev_server:
298
+ https: true
299
+ host: localhost
300
+ port: 8082
301
+ public: your-workspace-name-yourusername.c9users.io:8082
302
+ hmr: false
303
+ inline: false
304
+ overlay: true
305
+ disable_host_check: true
306
+ use_local_ip: false
307
+ ```
308
+
309
+ 1. Now running as usual `./bin/webpack-dev-server` in one terminal and
310
+ `./bin/rails s -b $IP -p $PORT` in another should work as expected.
data/docs/css.md CHANGED
@@ -1,7 +1,7 @@
1
- # CSS, SASS and SCSS
1
+ # CSS, Sass and SCSS
2
2
 
3
3
 
4
- Webpacker supports importing css, sass and scss files directly into your javascript files.
4
+ Webpacker supports importing CSS, Sass and SCSS files directly into your JavaScript files.
5
5
 
6
6
 
7
7
  ## Import styles into your JS app
@@ -45,7 +45,7 @@ a separate `[pack_name].css` bundle so that in your view you can use the
45
45
 
46
46
  ## Add bootstrap
47
47
 
48
- You can use yarn to add bootstrap or any other modules available on npm:
48
+ You can use Yarn to add bootstrap or any other modules available on npm:
49
49
 
50
50
  ```bash
51
51
  yarn add bootstrap
@@ -80,3 +80,32 @@ plugins:
80
80
  postcss-smart-import: {}
81
81
  postcss-cssnext: {}
82
82
  ```
83
+
84
+ ## Using CSS with [vue-loader](https://github.com/vuejs/vue-loader)
85
+
86
+ Vue templates require loading the stylesheet in your application in
87
+ order for CSS to work. This is in addition to loading the JavaScript
88
+ file for the entry point. Loading the stylesheet will also load the
89
+ CSS for any nested components.
90
+
91
+ ```erb
92
+ <%= stylesheet_pack_tag 'hello_vue' %>
93
+ <%= javascript_pack_tag 'hello_vue' %>
94
+ ```
95
+
96
+ ## Resolve url loader
97
+
98
+ Since `Sass/libsass` does not provide url rewriting, all linked assets must be relative to the output. Add the missing url rewriting using the resolve-url-loader. Place it directly after the sass-loader in the loader chain.
99
+
100
+
101
+ ```bash
102
+ yarn add resolve-url-loader
103
+ ```
104
+
105
+ ```js
106
+ // webpack/environment.js
107
+ const { environment } = require('@rails/webpacker')
108
+
109
+ const sassLoader = environment.loaders.get('sass')
110
+ sassLoader.use.push({ loader: 'resolve-url-loader' })
111
+ ```
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`. If you are not using sprockets you
4
+ 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 you
5
5
  can manually trigger `bundle exec rails webpacker:compile` during your app deploy.
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,7 +20,7 @@ By default the output will look like this in different environments:
20
20
 
21
21
  ## Heroku
22
22
 
23
- Heroku installs yarn and node by default if you deploy a rails app with
23
+ Heroku installs Yarn and node by default if you deploy a Rails app with
24
24
  Webpacker so all you would need to do:
25
25
 
26
26
  ```bash
@@ -30,7 +30,45 @@ git push heroku master
30
30
  ```
31
31
 
32
32
 
33
+ ## Nginx
34
+
35
+ Webpacker doesn't serve anything in production. You’re expected to configure your web server to serve files in public/ directly.
36
+
37
+ Some servers support sending precompressed versions of files with the `.gz` extension when they're available. For example, nginx offers a `gzip_static` directive.
38
+
39
+ Here's a sample nginx site config for a Rails app using Webpacker:
40
+
41
+ ```nginx
42
+ upstream app {
43
+ # ...
44
+ }
45
+
46
+ server {
47
+ server_name www.example.com;
48
+ root /path/to/app/public;
49
+
50
+ location @app {
51
+ proxy_pass http://app;
52
+ proxy_redirect off;
53
+
54
+ proxy_set_header Host $host;
55
+ proxy_set_header X-Real-IP $remote_addr;
56
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
57
+ proxy_set_header X-Forwarded-Proto $scheme;
58
+ }
59
+
60
+ location / {
61
+ try_files $uri @app;
62
+ }
63
+
64
+ location ^~ /packs/ {
65
+ gzip_static on;
66
+ expires max;
67
+ }
68
+ }
69
+ ```
70
+
33
71
  ## CDN
34
72
 
35
- 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
36
- you don't need to do anything extra for webpacker, it just works.
73
+ 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
74
+ you don't need to do anything extra for Webpacker, it just works.