docs/deployment.md in webpacker-6.0.0.beta.7 vs docs/deployment.md in webpacker-6.0.0.pre.1
- old
+ new
@@ -1,29 +1,30 @@
# Deployment
+
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`. Remember to set `NODE_ENV` environment variable to production during deployment or when running the rake task.
+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.
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.
By default the output will look like this in different environments:
```html
-<!-- In development mode with webpack-dev-server -->
-<script src="http://localhost:8080/calendar-0bd141f6d9360cf4a7f5.js"></script>
-<link rel="stylesheet" media="screen" href="http://localhost:8080/calendar-dc02976b5f94b507e3b6.css">
-
-<!-- In production or development mode -->
-<script src="/packs/js/calendar-0bd141f6d9360cf4a7f5.js"></script>
-<link rel="stylesheet" media="screen" href="/packs/css/calendar-dc02976b5f94b507e3b6.css">
+ <!-- In development mode with webpack-dev-server -->
+ <script src="http://localhost:8080/calendar-0bd141f6d9360cf4a7f5.js"></script>
+ <link rel="stylesheet" media="screen" href="http://localhost:8080/calendar-dc02976b5f94b507e3b6.css">
+ <!-- In production or development mode -->
+ <script src="/packs/js/calendar-0bd141f6d9360cf4a7f5.js"></script>
+ <link rel="stylesheet" media="screen" href="/packs/css/calendar-dc02976b5f94b507e3b6.css">
```
+
## Heroku
In order for your Webpacker app to run on Heroku, you'll need to do a bit of configuration before hand.
-```bash
+```
heroku create my-webpacker-heroku-app
heroku addons:create heroku-postgresql:hobby-dev
heroku buildpacks:add heroku/nodejs
heroku buildpacks:add heroku/ruby
git push heroku master
@@ -34,10 +35,11 @@
* Creating an app on Heroku
* Creating a Postgres database for the app (this is assuming that you're using Heroku Postgres for your app)
* 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.
* Pushing our code to Heroku and kicking off the deployment
+
## Nginx
Webpacker doesn't serve anything in production. You’re expected to configure your web server to serve files in public/ directly.
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).
@@ -124,5 +126,23 @@
end
end
end
end
```
+
+If you use [nvm](https://github.com/nvm-sh/nvm) to manage node versions for your deployment user, use the below snippet instead:
+
+```ruby
+before "deploy:assets:precompile", "deploy:yarn_install"
+namespace :deploy do
+ desc "Run rake yarn install"
+ task :yarn_install do
+ on roles(:web) do
+ within release_path do
+ execute("source ~/.nvm/nvm.sh && cd #{release_path} && yarn install --silent --no-progress --no-audit --no-optional")
+ end
+ end
+ end
+end
+```
+The `source ~/.nvm/nvm.sh` is required because [nvm is not automatically loaded in non-interactive shells](https://github.com/nvm-sh/nvm/issues/1718).
+