Skip to content

Bundle app.js as ESM module for new projects#6548

Open
rhcarvalho wants to merge 1 commit into
phoenixframework:mainfrom
rhcarvalho:installer-esbuild-esm
Open

Bundle app.js as ESM module for new projects#6548
rhcarvalho wants to merge 1 commit into
phoenixframework:mainfrom
rhcarvalho:installer-esbuild-esm

Conversation

@rhcarvalho

Copy link
Copy Markdown
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.

@SteffenDE SteffenDE left a comment

Copy link
Copy Markdown
Member

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

Comment thread guides/asset_management.md Outdated
@josevalim

Copy link
Copy Markdown
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
@rhcarvalho rhcarvalho force-pushed the installer-esbuild-esm branch from ab50fef to 11f0e8a Compare June 15, 2026 12:06
@rhcarvalho

Copy link
Copy Markdown
Contributor Author

Rebased to pickup template file renames (to *.eex). No conflicts and no changes from the original patch.

(Reminder this is marked for 1.9, not now)

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.
@rhcarvalho rhcarvalho force-pushed the installer-esbuild-esm branch from 11f0e8a to 3da64a9 Compare June 15, 2026 15:44
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