|
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.
|
@@ -34,15 +34,15 @@ We're essentially doing the following here:
|
34 | 34 |
|
35 | 35 | * Creating an app on Heroku
|
36 | 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. |
| 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 | 38 | * Pushing our code to Heroku and kicking off the deployment
|
39 | 39 |
|
40 | 40 |
|
41 | 41 | ## Nginx
|
42 | 42 |
|
43 | 43 | Webpacker doesn't serve anything in production. You’re expected to configure your web server to serve files in public/ directly.
|
44 | 44 |
|
45 |
| -Some servers support sending precompressed versions of files with the `.gz` extension when they're available. For example, nginx offers a `gzip_static` directive. |
| 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). |
46 | 46 |
|
47 | 47 | Here's a sample nginx site config for a Rails app using Webpacker:
|
48 | 48 |
|
@@ -71,11 +71,24 @@ server {
|
71 | 71 |
|
72 | 72 | location ^~ /packs/ {
|
73 | 73 | gzip_static on;
|
| 74 | + brotli_static on; # Optional, see below |
74 | 75 | expires max;
|
75 | 76 | }
|
76 | 77 | }
|
77 | 78 | ```
|
78 | 79 |
|
| 80 | +### Installing the ngx_brotli module |
| 81 | + |
| 82 | +If you wanna serve Brotli compressed files with nginx, you 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) repository. Alternatively, depending on your platform, the module might be available via a pre-compiled package. |
| 83 | + |
| 84 | +Once installed, you need to load the module. As we wanna serve pre-compressed files, we only need the static module. Add the following line to your `nginx.conf` file and reload nginx: |
| 85 | + |
| 86 | +``` |
| 87 | +load_module modules/ngx_http_brotli_static_module.so; |
| 88 | +``` |
| 89 | + |
| 90 | +Now you can set `brotli_static on;` in your nginx site config, per the config in the last section above. |
| 91 | + |
79 | 92 | ## CDN
|
80 | 93 |
|
81 | 94 | 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
|
@@ -106,4 +119,3 @@ namespace :deploy do
|
106 | 119 | end
|
107 | 120 | end
|
108 | 121 | ```
|
109 |
| - |
|
0 commit comments