Skip to content

rewrite asset urls in template to use vite asset hashes #114

@dominikg

Description

@dominikg

Describe the problem

when using <img src="./foo.jpg"> in svelte component template, the image has to be put in publicDir and isn't hashed by vites asset pipeline.

see this discussion in svelte discord: https://discord.com/channels/457912077277855764/819723698415599626/868424304042319892

Describe the proposed solution

build a preprocessor to do the following:

  1. extract possible asset urls
  2. filter extracted with vites asset_include
  3. rewrite url
    a) figure out vite hash of the asset and put hashed url in src
    b) add import x from "<url>" and rewrite src to <img src={x}> ( see https://github.com/bluwy/svelte-preprocess-import-assets)

add an option to inject that preprocessor within vite-plugin-svelte (like the others it's already doing)

Note: 3b would have the advantage that we don't need to figure out asset hashes as vite is going to rewrite the import down the road.

Alternatives considered

Importance

nice to have

Additional Considerations (see Discussion)

  • Interoperability with vite-plugins like vite-plugin-image and svelte-preprocessors
  • Configurability (ability to include/exclude assets from being processed)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions