mitnik
Page-Specific JavaScript with LiveView and esbuild Phoenix 1.6.0
Hello everyone,
Can someone help how to do Page-Specific JavaScript with LiveView and esbuild
I have found directions for the old webpack way of packing .. but non for the new 1.6 release with esbuild
Thanks! ![]()
p.s. a side question - can we also take advantage from the esbuild splitting
Marked As Solved
mitnik
finally solved it
non of the above will work if you don’t do the following:
from esbuild
Note that when code splitting is disabled (i.e. the default behavior), an
import('path')expression behaves similar toPromise.resolve(require('path'))and still bundles the imported file into the entry point bundle. No additional chunks are generated in this case.
so you must first configure the esbuild inside config.exs like so:
~w(js/app.js css/quill.css --chunk-names=chunks/[name]-[hash] --bundle --outdir=../priv/static/assets --splitting --format=esm --target=es2016),
then in your template you must change the app.js type like so (type=“module” otherwise you will get errors that you can’t use imports outside a module …):
<script defer phx-track-static type="module" src={Routes.static_path(@conn, "/assets/js/app.js")}></script>
now the code will load from the generated chunks

![]()
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex











