-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Description
Describe the bug
I'm trying to get Vite working with vanilla-extract. VE uses a custom file extension of .css.ts
to identify files that use styling code. Unfortunately, this is causing some issues when esbuild scans the code for deps. Inside the esbuildScanPlugin
it marks all .css
requests as external without doing a proper Vite resolve on it. This can be seen here:
vite/packages/vite/src/node/optimizer/scan.ts
Line 334 in 4d72b40
filter: /\.(css|less|sass|scss|styl|stylus|pcss|postcss|json)$/ |
This means that all deps within a .css.ts
file get ignored by the scan. This could be fixed by running a full resolve on the file but I can see that that was opted out of for perf reasons. There are a few ways I can think of to resolve the issue (unless someone has a better idea):
- Option 1: Do a full Vite resolve on file requests ending in
.css
. I assume this would have a small perf cost in projects with lots of CSS files, however not doing a proper resolve is a dangerous optimisation as shown here because we don't really know the file is a CSS file, just that the import request ended in.css
. - Option 2: Add some config to generate a better matching regex in the
esbuildScanPlugin
. E.g. Addingresolve.customExtensions: ['.css.ts']
would allow Vite to know that it's not safe to assume.css
requests don't need to be resolved. We could use the existingresolve.extensions
but not sure if that would clash with other behaviour. While this config may be confusing for most users the@vanilla-extract/vite-plugin
could be in charge of setting it consumers implicitly.
There's other config that could be exposed but the above was the nicest option I thought of. Happy to discuss other ideas though.
Lastly, I'm happy to do the work for this if we can agree on the approach. This is a blocker for my work on vanilla-extract and some other open source projects I'm currently working on.
Reproduction
I didn't add a reproduction due to the context supplied. I can add if it helps understanding on the issue though.
System Info
System:
OS: macOS 11.5.2
CPU: (8) x64 Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
Memory: 244.00 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 12.18.2 - ~/.volta/tools/image/node/12.18.2/bin/node
Yarn: 1.22.10 - ~/.volta/tools/image/yarn/1.22.10/bin/yarn
npm: 6.14.5 - ~/.volta/tools/image/node/12.18.2/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Browsers:
Chrome: 94.0.4606.61
Firefox: 83.0
Safari: 14.1.2
Packages:
vite: 2.5.1
Used Package Manager
yarn
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.