Original guide for Phoenix 0.12 here: http://manukall.de/2015/05/01/automatically-building-your-phoenix-assets-with-webpack/
The default tool provided in Phoenix (brunch) is pretty annoying to work with and the npm module integration is a pain. (e.g. import React from 'react'
does not do what you expect, import 'react/lib/update'
will just totally break on its path finding system, it uses a vendor
directory by default instead of pulling down packages from npm, etc.)
Because I already use Webpack for many things and it's very good software that lets me truly pull down and use npm modules for my projects, I opted to generate my project with the no brunch flag (--no-brunch
).
There are a few things to be aware of:
- You need to provide your own
package.json
(runnpm init
after you generate) - You need to install
webpack
and a loader for ES6/JSX (like babel), so you'll need to runnpm i -S webpack
and such. - You need to provide webpack configuration (see: webpack.config.js)
- Your entry and output should probably match the convention:
[...]
entry: './web/static/js/app.js',
output: {
path: './priv/static/js',
filename: 'app.js'
},
[...]
- You need to hook up watchers to your dev task, like so:
watchers: [{Path.expand("node_modules/webpack/bin/webpack.js"), ["-wd"]}]
- Then run
iex -S mix phoenix.server
as usual and have fun!
To start your Phoenix app:
- Install dependencies with
mix deps.get
- Create and migrate your database with
mix ecto.create && mix ecto.migrate
- Start Phoenix endpoint with
mix phoenix.server
Now you can visit localhost:4000
from your browser.
Ready to run in production? Please check our deployment guides.
- Official website: http://www.phoenixframework.org/
- Guides: http://phoenixframework.org/docs/overview
- Docs: http://hexdocs.pm/phoenix
- Mailing list: http://groups.google.com/group/phoenix-talk
- Source: https://github.com/phoenixframework/phoenix