Skip to content

Conversation

@rhcarvalho
Copy link
Contributor

Related to phoenixframework/phoenix_live_view#4062 (comment).

Update the mix phx.new installer to configure esbuild to output ESM modules by default in new Phoenix projects.

ESM modules enable tree shaking, code splitting, and enforce JavaScript strict mode, which can be beneficial for reducing bundle sizes, and catching common coding errors earlier.

In the JavaScript ecosystem, modern bundlers like Vite output ESM modules by default.

If a developer discovers later that they strictly need to support a non-module environment (like a third-party embed), it is trivial to go back to an IIFE output target.

Update the `mix phx.new` installer to configure `esbuild` to output ESM
modules by default in new Phoenix projects.

ESM modules enable tree shaking, code splitting, and enforce JavaScript
strict mode, which can be beneficial for reducing bundle sizes, and
catching common coding errors earlier.

In the JavaScript ecosystem, modern bundlers like Vite output ESM
modules by default.

If a developer discovers later that they strictly need to support a
non-module environment (like a third-party embed), it is trivial to go
back to an IIFE output target.
Copy link
Contributor

@SteffenDE SteffenDE left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to go ahead with this one. The only concern I have is doing it in a patch release, as the documentation may then throw people off if they generated their app prior to this change and they just copy the code from the docs. So maybe we wait for 1.9? 🤔

cc @josevalim @chrismccord


```elixir
args: ~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/* --public-path=/assets/ --loader:.woff=copy --loader:.ttf=copy --loader:.eot=copy --loader:.woff2=copy),
args: ~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/* --public-path=/assets/ --loader:.woff=copy --loader:.ttf=copy --loader:.eot=copy --loader:.woff2=copy),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we update those flags as well?

@josevalim
Copy link
Member

Yes, this should hold for a v1.9 release. We either keep it open or we branch from v1.8 from main and merge it.

@SteffenDE SteffenDE added this to the v1.9 milestone Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants