We have been looking at it. Just a quick note – I understand that you are currently frustrated that something is causing you problems, but your tone to multiple people trying to help you out is off-putting. It it difficult to find motivation to approach this issue after reading the thread
Please keep that in mind when asking for help and replying to others providing help.
That said, we have a solution that will fit your use case. Before we get there, one other note, for you and future readers: generally the reason that assets like images get duplicated is for the purpose of cache busting, as in the process by which we can tell client browsers to cache assets that rarely change for long periods of time and still allow those assets to be refreshed in a timely manner when they may change. Usually this is done by appending a hash of the file contents to the filename. This necessarily creates (at least) a duplication of your cached-busted (i.e. digested) assets.
So the behaviour you are seeing is esbuild trying to help you out by cache-busting your assets. However it sounds like you may not want that, so here is how you disable it in esbuild.
In your config/config.exs
, find the esbuild
configuration. It should look something like this:
config :esbuild,
version: "0.12.18",
default: [
args:
~w(js/app.js --bundle --target=es2016 --outdir=../priv/static/assets),
cd: Path.expand("../assets", __DIR__),
env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
]
append the external
option to the list of args
, so it looks like this:
args:
~w(js/app.js --bundle --target=es2016 --outdir=../priv/static/assets --external:/images/*)
Now, when you reference your image paths in css, do so with absolute paths just like you would in the browser:
background-image: url("/images/phoenix.png");
and that’s it.
Now let’s say you do want cache-busting. Phoenix has you covered. Run mix assets.deploy
, which is an alias in the generated mix.exs
from the Phoenix installer. It runs the phx.digest
command which will handle cache-busting for all of your assets in priv/static
. To remove the digested assets, you can run mix phx.digest.clean --all
.
Let us know how it goes!