-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Support Vanilla JS CSS Modules / CSS import attributes #17700
Comments
Start a new pull request in StackBlitz Codeflow. |
It appears that Vite deliberately strips the import attribute syntax: vite/packages/vite/src/node/plugins/importAnalysis.ts Lines 494 to 497 in 3af02bd
Worth noting that import attributes are supported by TypeScript along with native support in Chrome. It would be great it The workaround right now:
Some prior comments on the topic: |
As a first step toward solving this issue, I think it might be nice to have an option to disable the current CSS runtime behavior entirely. In other words, This would fit the usecase of the LWC framework – in LWC, importing a CSS file returns a function: import stylesheet from './styles.css' // imports a function that returns a string Currently, this functionality doesn't work in Vite even with our Rollup plugin ( Unfortunately, the Potentially, our Rollup plugin could apply these transformations itself (to the |
Discussion: #18534 |
Description
It seems that Vite does not support imports of CSS Style Sheets in ES modules with or without import attributes like
import styles from './styles.css'
orimport styles from './styles.css' with { type: 'css' }
.A workaround seems to be the
?inline
query parameter likeimport styles from './styles.css?inline'
.I see that import attributes are at state 3 still, but constructable stylesheets aren't and ES-Modules are both in base-line now.
So i'd like the (configurable) support to import CSS as
CSSStyleSheet
.Suggested solution
A configurable option to handle imports of *.css as CSS Modules /
CSSStyleSheet
.Alternative
No response
Additional context
Why don't you just use the
?inline
-query?We're targeting browsers with native CSS Module import support, like Chrome, for internal enterprise web apps.
Third parties now want to start using our custom elements which make use of those imports.
Since they do not have access to the source and we cannot add
?inline
to all imports, the potential users are limited to use the bundled version, which hinders them to extend und bundle custom-element on their behalf.See the reproducer on stackblitz which illustrates the issue, when running
npm run build
Validations
The text was updated successfully, but these errors were encountered: