Skip to content

Switching an existing Phoenix app from Brunch to Webpack

by Atul Bhosale

Phoenix version 1.4 onwards will be using webpack as a module bundler for javascript. This blog post is about the steps which I followed to switch from brunch to webpack in an existing Phoenix project.

Clone Phoenix

Since Phoenix 1.4 is unreleased as of when this blog is published, we will generate a new project using Phoenix source installer. Clone Phoenix and run -

bash

cd phoenix/installer
mix phx.new dev_app --dev

Run npm install in dev_app/assets folder.

Copy this assets folder to the existing Phoenix project folder which we want to switch from brunch to webpack.

Delete brunch config

Delete brunch-config.js, package-lock.json & node_modules folder. Copy required dependencies from existing package.json to package.json file in assets folder except for brunch related dependencies like brunch, babel-brunch etc. Delete package.json from the root folder.

Run npm install after adding the dependencies to the new package.json file.

Copy js & css files from static folder

Copy js & css files from web/static folder to assets/js & assets/css folder & delete web/static folder.

Delete default styles used for starter applications

Delete assets/css/phoenix.css & its entry from assets/css/app.css

Update npm watch script

Update npm watch script in assets/package.json to --

json

"watch": "webpack --mode development --watch-stdin"

Using --watch-stdin option exits the nodejs process when stdin(standard input) is closed.

Update webpack watcher config

Update webpack watcher config in config/dev.exs to --

watchers: [node: ["node_modules/webpack/bin/webpack.js", "--mode", "development", "--watch-stdin",
  cd: Path.expand("../assets", __DIR__)]]

Add to .gitignore

Add node_modules under assets to .gitignore

/assets/node_modules

Update babel presets

Update babel presets which are required in the project.

{
  "presets": [
    "env",
  ]
}

Start Phoenix and check webpack

Start Phoenix with -

iex -S mix phx.server

and check if webpack has built the js bundle.

Here is the reference PR and discussion.

More articles

  • Building our own infra using our office hardware

    How we turned a Mac mini and a stack of MacBooks into a self-hosted k3s cluster, moved our apps off a managed platform, and run it all over Tailscale.

    Read more →
  • What Is an AI Harness?

    A harness is the code that sits around an LLM and lets it actually do things: read files, run commands, search the web. The model writes text. The harness turns that text into actions, and the results back into text.

    Read more →

Your competitors are already using AI. The question is how fast you want to unlock the value.

  • Don't know where to start?

    AI is everywhere but it's unclear which investments will actually move your metrics and which are expensive experiments.

  • Your data isn't ready

    Most AI projects fail at the data layer. Pipelines, quality, access all need work before LLMs can deliver value.

  • Internal teams are stretched

    Your engineers are shipping product. They don't have capacity to also become AI specialists with production-grade experience.

  • Legacy systems block everything

    Aging, undocumented codebases make AI integration slow, risky, and expensive. They need to move first.

Don't worry. We've got you covered.

Start with the audit.

Book a free discovery call