From 2c13a19f3f9a6bc97941b5bb23d60a09297efc48 Mon Sep 17 00:00:00 2001 From: Gary Rennie Date: Thu, 11 Apr 2019 16:14:18 +0100 Subject: [PATCH] Use npm to build JavaScript assets 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. --- docs/guides/phoenix_walkthrough.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/docs/guides/phoenix_walkthrough.md b/docs/guides/phoenix_walkthrough.md index 6afbe676..6d6e1ea8 100644 --- a/docs/guides/phoenix_walkthrough.md +++ b/docs/guides/phoenix_walkthrough.md @@ -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 ``` @@ -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 @@ -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 @@ -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. @@ -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 @@ -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` @@ -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`