Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression (beta 51) - Manifest entries for SVG assets lack information to resolve the file #1765

Closed
ElMassimo opened this issue Jan 28, 2021 · 7 comments

Comments

@ElMassimo
Copy link
Contributor

ElMassimo commented Jan 28, 2021

Description 📖

When adding a non-JS and non-CSS entrypoint, such as an .svg, in the manifest entry:

  • A fingerprinted version of the file is added correctly to the output dir, but
  • file points to an empty JS chunk, and it can't be used to resolve the file

Background 📜

Prior to beta 51 file had the resolved path to the fingerprinted file.

Reproduction 🐞

The issue can be replicated in this simple application, by going to the directory and running pnpm install and pnpm build.

Look for logo.svg in the public/vite/manifest.json file.

Logs 📜

Manifest entry:

  "logo.svg": {
    "file": "assets/logo.f1745d22.js",
    "src": "logo.svg",
    "isEntry": true
  },

But the fingerprinted file is actually assets/logo.41cff365.svg, which is not in the manifest, but is in the output dir.

@ElMassimo ElMassimo changed the title Manifest entries for SVG assets lack information to resolve the file Regression (beta 51) - Manifest entries for SVG assets lack information to resolve the file Jan 28, 2021
@ElMassimo
Copy link
Contributor Author

ElMassimo commented Jan 28, 2021

Experimented with the manifest generation to re-enable support for non-JS entrypoints in #1774.

@yyx990803
Copy link
Member

Can you explain why would you use asset as entry points in the first place?

@ElMassimo
Copy link
Contributor Author

ElMassimo commented Jan 28, 2021

To take advantage of the fingerprinting performed by Rollup for assets that are linked externally (instead of imported).

Example, where logo.svg and styles.css are entrypoints and their URL is rendered in HTML directly.

It enables Vite to be used in hybrid apps (HTML is rendered server-side), and cases where no JS is required, but still provide an excellent dev experience when authoring CSS, or allow caching "forever" thanks to asset fingerprinting.

Without this, every backend needs to provide an alternate assets pipeline, which tend to lag behind in terms of the features or devx they provide.


Is there a different way to fingerprint a non-imported asset?

@yyx990803
Copy link
Member

Actually I'm not sure why this has to be done through Vite. Since you have to manually specify them as entries, it means they are not used in Vite's module graph (i.e. never imported by any of the js files) - why can't you just hash them yourself?

@ElMassimo
Copy link
Contributor Author

ElMassimo commented Jan 28, 2021

That might make sense when it's just fingerprinting, but CSS benefits from HMR and Vite plugins (and transformations, and in the future source maps).

Referencing assets from HTML is very similar to the behavior here; this provides a way to obtain the same when not using HTML as the entry point.

I understand that this is not the main approach intended for Vite, but it would indeed be useful and would open up the tooling ecosystem for other purposes.

@yyx990803
Copy link
Member

The thing is Vite actually is supposed to automatically eliminate empty CSS chunks.

I think your use case can be better achieved with a custom generateBundle hook that has access to the entire chunk/module graph instead of relying on Vite's manifest (which isn't really designed for this use case).

@ElMassimo
Copy link
Contributor Author

Thanks for pointing me in the direction of generateBundle, worked like a charm 👍

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants