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

How to know where an asset came from? #5046

Closed
4 tasks done
tanekim88 opened this issue Sep 23, 2021 · 2 comments
Closed
4 tasks done

How to know where an asset came from? #5046

tanekim88 opened this issue Sep 23, 2021 · 2 comments

Comments

@tanekim88
Copy link

tanekim88 commented Sep 23, 2021

Clear and concise description of the problem

Suppose I have two files with same name in folder A and A/B.
A/a.scss
A/B/a.scss

If I pass these two files directly as input, total four files are generated, a.123c4.js, a.df343.css, a.35353.js, and a.dfsdf.css.
Suppose I created a custom plugin, then in generateBundle menthod,
image
The bundle is an object with fileName key and either an asset or chunk object as value.
An asset object structure looks like this
image
Looking at this structure, suppose I am looking at an asset with a fileName 'assets/a.df343.css' and name : 'a.css'. How do I know from which of the two files a.123c4.js and a.35353.js the css file is related to?

Suggested solution

It would be awesome if there is a field like filePath: 'A/B/a.scss' in the asset structure in generateBundle method so that I can at least know this asset came from this file. Currently, there is only name field, which would only show 'a.scss', and I have no idea which of A/a.scss or B/a.scss it came from

Alternative

No response

Additional context

No response

Validations

@rynpsc
Copy link

rynpsc commented Sep 29, 2021

Might be somewhat relevant to #2375 (comment). It would appear that for CSS/SCSS/Less Vite isn't exposing the orginal src path for anything that compiles to CSS?

@bluwy
Copy link
Member

bluwy commented Mar 20, 2022

This isn't really something Vite can apply. generateBundle is a Rollup hook and assets are emitted via the standard this.emitFile method. So unless Rollup exposes the filePath option, it isn't something Vite can do so. With that said, it'll be helpful to justify what your usecase is and perhaps it can be solved in a different way. But I'm closing this as it should be a Rollup feature request.

@bluwy bluwy closed this as completed Mar 20, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Apr 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants