Skip to content

Commit 4940956

Browse files
committed
add a section about npm when using phx.gen.release --docker
Fixes #5976.
1 parent d87d36b commit 4940956

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

guides/asset_management.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ If you want to import JavaScript dependencies, you have at least three options t
4646
be used by Hex packages, so if you intend to publish your project to Hex,
4747
consider vendoring the files instead.
4848

49+
Note that if you use third party JS package managers, you might need to adjust your deployment steps
50+
to properly include the packages. If you're using `mix phx.gen.release --docker`, have a look at the
51+
[documentation](Mix.Tasks.Phx.Gen.Release.html#module-docker) for further details.
52+
4953
## Images, fonts, and external files
5054

5155
If you reference an external file in your CSS or JavaScript files, `esbuild` will attempt to validate and manage them, unless told otherwise.

lib/mix/tasks/phx.gen.release.ex

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,38 @@ defmodule Mix.Tasks.Phx.Gen.Release do
3131
3232
For extended release configuration, the `mix release.init` task can be used
3333
in addition to this task. See the `Mix.Release` docs for more details.
34+
35+
If you are using third party JS package managers like `npm` or `yarn`, you will
36+
need to update the generated Dockerfile with an extra step to fetch those packages.
37+
This might look like this:
38+
39+
```dockerfile
40+
...
41+
ARG RUNNER_IMAGE="debian:..."
42+
43+
FROM node:20 as node
44+
COPY assets assets
45+
RUN cd assets && npm install
46+
47+
FROM ${BUILDER_IMAGE} as builder
48+
49+
...
50+
51+
COPY assets assets
52+
COPY --from=node assets/node_modules assets/node_modules
53+
...
54+
```
55+
56+
If you are using esbuild through Node.js or other JavaScript build tools, the approach
57+
above can also be modified to invoke those in the node stage, for example:
58+
59+
```dockerfile
60+
FROM node:20 as node
61+
COPY assets assets
62+
RUN cd assets && npm install && node build.js --deploy
63+
```
64+
65+
Note that you may need to adjust the `assets.deploy` task to not invoke Node.js again.
3466
"""
3567

3668
use Mix.Task

0 commit comments

Comments
 (0)