Bundle app.js as ESM module for new projects#6548
Open
rhcarvalho wants to merge 1 commit intophoenixframework:mainfrom
Open
Bundle app.js as ESM module for new projects#6548rhcarvalho wants to merge 1 commit intophoenixframework:mainfrom
rhcarvalho wants to merge 1 commit intophoenixframework:mainfrom
Conversation
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
approved these changes
Dec 8, 2025
Contributor
SteffenDE
left a comment
There was a problem hiding this comment.
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? 🤔
|
|
||
| ```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), |
Contributor
There was a problem hiding this comment.
should we update those flags as well?
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to phoenixframework/phoenix_live_view#4062 (comment).
Update the
mix phx.newinstaller to configureesbuildto 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.