Skip to content

Commit

Permalink
Use npm to build JavaScript assets
Browse files Browse the repository at this point in the history
The npm run deploy script will build the assets based on the contents
of package.json. For older projects this will use brunch by default,
for newer projects, webpack will be used.
  • Loading branch information
Gazler committed Apr 11, 2019
1 parent b945641 commit 2c13a19
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions docs/guides/phoenix_walkthrough.md
Expand Up @@ -79,8 +79,7 @@ for building a release. Execute the following commands:
```
$ mix deps.get --only prod
$ MIX_ENV=prod mix compile
$ cd assets
$ node node_modules/brunch/bin/brunch build --production
$ npm run deploy --prefix assets
$ cd ..
$ mix phx.digest
```
Expand Down Expand Up @@ -116,7 +115,7 @@ Phoenix application.

*NOTE* The above commands can be combined into one quick command as
```
$ cd assets && ./node_modules/brunch/bin/brunch b -p && cd .. && MIX_ENV=prod mix do phx.digest, release --env=prod
$ npm run deploy --prefix assets && MIX_ENV=prod mix do phx.digest, release --env=prod
```

*NOTE*: If you run `mix release` with `MIX_ENV=dev` (the default), then you must also ensure
Expand All @@ -131,7 +130,7 @@ which is not intended to be packaged in releases. As you won't be doing code rel
If you followed the above you will have generated a working release. A few notes on some of the
above commands we used:

1. `./node_modules/brunch/bin/brunch b -p` builds your assets in
1. `npm run deploy --prefix assets` builds your assets in
production mode. More detail can be found in the
[Phoenix Static Asset Guide](http://phoenixframework.org/blog/static-assets)
1. `MIX_ENV=prod mix phx.digest` To compress and tag your assets
Expand All @@ -141,7 +140,7 @@ above commands we used:
production environment

You might wonder "why all the hassle to build a release?" A Phoenix project in `dev` mode is
supposed to be interactive with features such as live code reload and automatic `brunch` asset
supposed to be interactive with features such as live code reload and automatic `webpack` asset
recompilation and extra logging. While great for development, it comes at a performance cost
and you would not want to run a production Phoenix application in dev mode.

Expand Down Expand Up @@ -210,7 +209,7 @@ Remove the following line from our application layout.

Next we build an upgrade release with the following command:

`cd assets && ./node_modules/brunch/bin/brunch b -p && cd .. && MIX_ENV=prod mix do phx.digest, release --env=prod --upgrade`
`npm run deploy --prefix assets && cd .. && MIX_ENV=prod mix do phx.digest, release --env=prod --upgrade`

This is the same command as in version 0.0.1 with the exception of
`--upgrade`. The upgrade flag tells Distillery to build an
Expand Down Expand Up @@ -320,7 +319,7 @@ just as we did with 0.0.2. So we will generate a release, copy the
0.0.3 tarball into a new release directory under `local_deploy`, and
upgrade the application.

1. `cd assets && ./node_modules/brunch/bin/brunch b -p && cd .. && MIX_ENV=prod mix do phx.digest, release --env=prod --upgrade`
1. `npm run deploy --prefix assets && cd .. && MIX_ENV=prod mix do phx.digest, release --env=prod --upgrade`
1. `mkdir local_deploy/releases/0.0.3`
1. `cp _build/prod/rel/phoenix_distillery/releases/0.0.3/phoenix_distillery.tar.gz local_deploy/releases/0.0.3/`
1. `./local_deploy/bin/phoenix_distillery upgrade 0.0.3`
Expand Down Expand Up @@ -370,7 +369,7 @@ just as we did with 0.0.3. Generate a release, copy the 0.0.4 tarball
into a new release directory under `local_deploy`, and upgrade the
application.

1. `cd assets && ./node_modules/brunch/bin/brunch b -p && cd .. && MIX_ENV=prod mix do phx.digest, release --env=prod --upgrade`
1. `npm run deploy --prefix assets && cd .. && MIX_ENV=prod mix do phx.digest, release --env=prod --upgrade`
1. `mkdir local_deploy/releases/0.0.4`
1. `cp _build/prod/rel/phoenix_distillery/releases/0.0.4/phoenix_distillery.tar.gz local_deploy/releases/0.0.4/`
1. `./local_deploy/bin/phoenix_distillery upgrade 0.0.4`
Expand Down

0 comments on commit 2c13a19

Please sign in to comment.