📎 Webclip
Elixir Phoenix with Typescript and React – December 2019 Edition
The article walks through creating a Phoenix umbrella app, using Postgres by default, and running it locally with Docker Compose. It then adds TypeScript support in the frontend by adjusting tsconfig and webpack, and finishes by mounting a React component on the Phoenix home page.
Reading notes#
- It assumes Elixir 1.9.4 or newer, npm, and optionally Docker for PostgreSQL.
- It installs Phoenix with Hex and phx_new, then creates an umbrella app with
mix phx.new hello_react --umbrella. - The guide explains that the umbrella structure keeps apps organized as the project grows.
- It shows alternative app generation flags for MySQL and for skipping Ecto entirely.
- It uses Docker Compose to start PostgreSQL with defaults that match the generated Phoenix app.
- It installs the frontend dependencies in
apps/hello_react_web/assetswithnpm install. - It verifies the Phoenix app by running
mix phx.serverand visitinglocalhost:4000. - It adds TypeScript packages and generates a default
tsconfig.jsonbefore changing compiler options. - It updates
webpack.config.jsto handle.tsfiles and to resolve.tsand.jsextensions. - It replaces the CSS import in
app.jswithrequireso Webpack keeps processingapp.css. - It adds a small TypeScript module that returns the greeting string used on the page.
- It installs React and ReactDOM, plus their type definitions, and reconfigures Webpack for
.jsxand.tsxfiles. - It creates a
GreeterReact component, replaces the Phoenix template section with agreetingcontainer, and renders the component into that element.
