-
Notifications
You must be signed in to change notification settings - Fork 5.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 CSS Modules #11961
Comments
CSSStyleSheet and friends sound like out of scope for deno perhaps better suited to a third-party module, but having low level access to CSS modules in deno would be useful. I can imagine a use case to only need:
When the same JS modules are used both for server side rendering as well as client side browser code, this would enable server applications to somehow collect the CSS modules used and present them to the client as a traditional, pre-baked CSS file when SSR is being used. Frameworks or server apps would be free to implement this kind of functionality however they best see fit, but I can imagine it being desireable for many to have CSS dependencies managed alongside JS. |
For anyone else who is confused like I was: the CSS Modules feature talked about here (sometimes disambiguated as "CSS Module Scripts") is unrelated to the popular CSS Modules feature ( The CSS Module Script standard isn't used by any popular framework to my knowledge, implementing it in Deno would not help projects that want to use CSS Modules, and it doesn't seem to be built for server-side rendering. WICG/webcomponents#759 (comment)
Not that I'm against this being implemented in Deno just because it's not CSS Modules -- it wouldn't get in the way of them -- but I just want to emphasize that it's unclear how it would be used and who would benefit if it was implemented in Deno specifically. Implementing this would require implementing |
I think #13898 explains how |
+1 |
I’m using Deno as a test runner for code that normally runs in the browser. So Deno simply not throwing when it encounters a css import assertion would already be enough for that specific use case. But I realize throwing is probably preferable rather than to have it fail silently with undefined behavior. |
On a separate note, I'm having trouble type checking code for browsers that have CSS imports. Currently, I create // mod.ts
// @deno-types="./stylesheet.d.ts"
import css from "./style.css";
console.log(css); // stylesheet.d.ts
/// <reference lib="dom" />
declare const stylesheet: CSSStyleSheet;
export default stylesheet; With this method, type checking works as expected in the editor, but an error occurs in the > deno check ./mod.ts
error: The import assertion type of "css" is unsupported.
at file:///C:/Users/ It may take some time to implement the |
@dsherret it looks like a |
Fun related spec issue: https://gist.github.com/peetklecha/a55532165dbd4905aa91bbe59e8b1001 TL;DR: Import assertions will be going back to stage 2 and the syntax will likely change. |
As a workaround, I ended up adding an entry to Deno's import map. All my css imports were already contained in a single module. So now the import map maps this module to a dummy module that exports empty objects instead: // styles.js
// @ts-ignore
import mySheet from "./mySheet.css" assert {type: "css"};
export {mySheet}; // denoStyles.js
export const mySheet = {}; importmap.json
The browser doesn't have this entry in its import map, so it loads |
Any update on this? |
Chromium is shipping CSS Modules unflagged in v93: https://chromestatus.com/feature/5948572598009856
We should consider how this applies to Deno.
The relevant commit to the HTML Living Spec: whatwg/html@3d45584
The biggest challenge is that a constructed
CSSStyleSheet
object is returned on the import which then is inserted into the DOM. Deno doesn't have a DOM or theCSSStyleSheet
object, nor is it clear what expectations would be for users and varies greatly from what a front-end bundler would consider a "CSS module".Personal opinion is that everything is very vague that it really is unimplementable. (Plus we are also blocked on having import assertions, which are still not supported by tsc)
The text was updated successfully, but these errors were encountered: