Assets from Server-Only Marko Components Are Dropped
Problem
When importing assets (e.g. images via vite-imagetools) inside Marko components used only in the server build, those assets are not emitted to dist/public/assets.
Even though emitFile() is called (confirmed via logging), the assets are silently dropped unless the component explicity become a client-component.
Debugging
Reproduced on: https://github.com/AndresBarreto-code/marko-with-vite-imagetools
npm install
npm run build
OR
npm install
npm run preview
You will see no serve-image is being built in dist/public/assets.
Why It Matters
- Assets used in SSR components vanish from production builds
- Devs are forced to restructure components or fake client usage
- It breaks expected behavior when using Vite plugins like vite-imagetools
Proposed Fix
Update @marko/run to retain assets from the SSR build:
- During SSR build, track emitted assets via emitFile()
- In client build, re-emit those assets to ensure they're preserved
@AndresBarreto-code thanks for the callout.
For some context, the way that assets like this are propagated to the client build is through (essentially) a special compiler option regexp
Anything that matches that regexp imported from a marko file will automatically be carried over to the client compilation. (The server compilation is typically configured to avoid emitting any assets to avoid duplicate work).
That said I think we could update the regexp to ignore the search params.
Hey @DylanPiercey I was going to look back at this, but it seems it was already fixed. Could you please confirm with me? If so, thank you very much.
@AndresBarreto-code yes this is fixed, but I forgot to close this issue!
The actual issue was that the client asset propagation regex was not accounting for assets with query params in them (like with vite imagetools).
@DylanPiercey thank you very much! Curious to learn more about Marko, was this https://github.com/marko-js/run/pull/117 the fix? It does not sound like 🤔 otherwise, this one https://github.com/marko-js/run/pull/129?
@AndresBarreto-code what I said was the fix was wrong 🤦. I think this is what was the fix https://github.com/marko-js/vite/pull/162