-
Notifications
You must be signed in to change notification settings - Fork 491
CSS Module (again) ? #375
Comments
I'm just in the process of breaking the fork link, at that point i'm happy to get this enabled! #227 |
This isn't yet in CRA proper. It is part of CRA v2.0 beta. |
@wmonk is it enabled now? I tried a few days ago and could not get it to work. |
any update??? :) |
In my opinion it would be best to wait for CRA 2 (or publish a prerelease based on CRA 2's prerelease now) to avoid conflicts with CRA in the future. |
Hi there, it's working.
:local(.class) {} /* for local scope */
.myGlobalClassName {} /* for global scope */
// …
import * as styles from './styles.css';
// …
<div className={styles.class} /> Btw, ofc don't forget about declarations for
|
@r3nya for the declare module '.css' code, how do you get around the Typescript error 'Invalid module name in augmentation, module '.css' cannot be found.' ? Also, where do you place this declaration? |
Hm … @raptoria I created special folder my custom definitions – "compilerOptions": {
// code …
},
"filesGlob": [
"node_modules/**/*.d.ts",
"definitions/*.d.ts"
],
"exclude": [
// code…
] And it's working 🤔 |
@r3nya does cra-ts generate your CSS definitions for you (*.d.ts) or are you doing this yourself? Before I started using cra-ts, I used to setup my own pre-build command that generated all the *.d.ts. Now that I'm using cra-ts, I'm confused as to where/if this is still happening. |
@raptoria let me create some demo for you… |
@raptoria please take a look – https://github.com/r3nya/css-modules-and-cra-ts/
|
thanks a lot for your example, it's extremely helpful. So now when I add a new local css class, I have to do npm run css-types to re-generate the *.css.d.ts I guess the only thing that's different is the local/global stuff seems to be inverted. It used to be that a class, eg. .header {} would be locally scoped (I can access via styles.header) and to use the global scope I'd do :global(.header) and access using className='header'. Now declaring a class in CSS is automatically global and I have to use the local scope to make it local. Is this specific to cra-ts? |
Thanks for creating those demos, it's very useful! In my opinion, I'd be interested to see if one of the "typescript module generator loaders" work, and see if we can wrap This is one that worked almost completely for me, but the typescript definitions it spat out were not correct (though I may have configured it incorrectly?): https://www.npmjs.com/package/typings-for-css-modules-loader If we can't get that to work, maybe my Google-fu isn't working and there is an alternative? |
This is the setting for the css-loader from webpack. Anyway, after #409 we can use typical solutions -> https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-a-css-modules-stylesheet 😉 |
Coming here just to say that I'd recommend not adding "typed-css-modules-loader" or other css typing system step to be default to react-app-ts project creation. I've tried this route before and found it better to treat CSS imports as just type |
@jadbox I think it's definitely important to test using typed module loader wrappers for Typed CSS modules would allow your team to be confident that the classes you're specifying in your component are correct, and that when changing CSS, you can be more certain you're not breaking your component's design. This is a big plus for TS for me. On the other hand, I think an important part of this issue would be determine if the tooling is there yet, and if not, is there a way this functionality can be provided while providing a fallback when things get out of hand (like |
I know this have been discussed before in #180, but is there any rationale behind the fact that this typescript fork doesn't (yet) support CSS modules ? This have been merged a long time ago on facebook/create-react-app#2285.
The text was updated successfully, but these errors were encountered: