-
Notifications
You must be signed in to change notification settings - Fork 292
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
Multiple CSS files have the same name when using the Vite plugin with a scoped package #631
Comments
@graup pointed out in a conversation we had on discord that "virtual" modules should not be necessary for this case:
So I had a go at removing them, this is very rough around the edges and may re-introduce past bugs (e.g the This seems like the right direction to me, as Vite will see the CSS file properly, and it will have a proper file system path for generating the name. Curious on your thoughts here @mattcompiles? |
I have thought about this in the past as well. VE CSS is derived from a real file, however it is not derived from an AST transform or compilation process. Meaning it can't be sensibly mapped with a source map. Therefore I believe they do need to represented as virtual files. However feel free to correct me if I'm wrong and there is a way to do this I'm not aware of. Either way though I think issue can be resolved even with virtual files. We might just need to update the file scope serialization. |
I see why sourcemaps wouldn't be possible, but is there any benefit of using virtual files over an "actual" path without sourcemaps? |
Reading through both the Vite and Rollup docs some more I guess it prevents other plugins from processing the import. Although that seems to be a feature of A few potential options:
Curious on your thoughts here @mattcompiles. Happy to take a swing at implementing an approach, just not sure which direction to go. |
Would this issue be resolved if we just make the file path be the last thing in the filescope string instead? I don't remember any specific reason it was last. e.g. export function stringifyFileScope({
packageName,
filePath,
}: FileScope): string {
return packageName ? `${packageName}$$$${filePath}` : filePath;
} If so, happy to accept a PR. 😄 |
Yes I believe that would be a slight improvement and fix this particular issue. |
That would definitely fix this issue yes. It still doesn't feel like the right solution to me though, because we are relying on the fact that Vite uses |
Referring back to @AndrewLeedham 's comment, how about something like this? (Untested poc: remove prefix and change serialization to As far as I can tell the packageName is only there for the hot reload and injectStyles, right? |
The package name is in the filescope as the filename is relative to that package. If you're using a package that contains VE files then all the file paths coming from that package will be relative to their package.json. What we need to be careful of here is allowing two separate files from having the same ID. This solution is probably ok from that regard. One thing I'm not clear on though is how this solution is more ideal than what I suggested? Could someone just explain why this creates a better build output? |
The main advantage is that having the generated css files as proper (non-virtual) modules, with usable names and paths, works better with |
This issue, along with a few others have lead me to doing a decent refactor of file scopes across the board. Hoping this PR will make everyone happy. #647 |
Describe the bug
If the package name includes a scope e.g
@vanilla-extract/example
the outputted CSS files will all have the namesexample.vanilla.css
,example.vanilla2.css
,example.vanilla3.css
etc. This seems to be because the sanitise file scope function adds the package name and when a scope is used it includes a/
so it considers the last part as the file name. I would expect the file name to be included in the asset name, which it is when not using a scope.Link to reproduction
https://stackblitz.com/edit/vitejs-vite-gfnuxw?file=vite.config.ts
npm run build
in the above and it outputs:package.json->name
. It outputs the following:System Info
Output of
npx envinfo --system --npmPackages @vanilla-extract/css,@vanilla-extract/webpack-plugin,@vanilla-extract/esbuild-plugin,@vanilla-extract/vite-plugin,@vanilla-extract/sprinkles,webpack,esbuild,vite --binaries --browsers
:Related
The text was updated successfully, but these errors were encountered: