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

Import *.css.json, additionally bundle *.css? #1017

Open
rauschma opened this issue May 16, 2024 · 0 comments
Open

Import *.css.json, additionally bundle *.css? #1017

rauschma opened this issue May 16, 2024 · 0 comments

Comments

@rauschma
Copy link

rauschma commented May 16, 2024

Describe the problem

At the moment, there is no simple way to support CSS for server-side rendering:

  • Node.js somehow has to handle the imported CSS.
  • TypeScript should complain (during editing!) if there are typos in IDs, classes, etc.

Describe the proposed solution

component.tsx
component.css.json
component.css

component.ts:

import { render } from 'preact-render-to-string';
// Node.js does not support named imports for JSON
import css from './component.css.json' with { type: 'json' };

console.log(render(
  <div id={css.warning}></div>
));

component.css.json:

{
  // "unmangled name of ID": "name in CSS bundle"
  "warning": "x1bz9l0f"
}

component.css:

#warning { /* CSS bundle: #x1bz9l0f */
  background-color: red;
}

Alternatives considered

  • vanilla-extract: Works but does not let me use CSS, only CSS encoded as TypeScript.

Importance

I cannot use modular-css without it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant