CSS Modules with TypeScript: css-modules-typescript-loader
See original GitHub issueTypeScript users are flying blind when they import a CSS module. For example, if they type styles.foo
they have no idea if .foo
actually exists in the CSS module without manually checking the file.
This is not a great TypeScript experience.
I propose adding the css-modules-typescript-loader
(or something similar) to emit type declarations for CSS modules on the fly.
It could be as simple as this:
const loaders = [
require.resolve('style-loader'),
...(useTypeScript && cssOptions.modules
? require.resolve('css-modules-typescript-loader')
: []
),
What do you think?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:9
- Comments:53 (23 by maintainers)
Top Results From Across the Web
css-modules-typescript-loader - npm
Webpack loader to create TypeScript declarations for CSS Modules. Latest version: 4.0.1, last published: 2 years ago.
Read more >How to use CSS Modules with TypeScript and webpack
Using CSS Modules with TypeScript is not as obvious as with JavaScript. ... a drop-in replacement for css-loader that generates typings for CSS...
Read more >seek-oss/css-modules-typescript-loader - GitHub
Webpack loader to create TypeScript declarations for CSS Modules. Emits TypeScript declaration files matching your CSS Modules in the same location as your ......
Read more >How to import CSS modules with Typescript, React and ...
Typescript compiler will understand that css import will be module with properties ... Loader will generate Css modules typings file ( component.css.d.ts ) ......
Read more >Increasing the Value of CSS Modules with Typescript
1. Create a New Project · 2. Rename CSS Files · 3. Import CSS Modules · 4. Add Typescript Plugin · 5. Use...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I put down quick gist for anyone reading this issue, if they desperately need this feature without ejecting 😃
https://gist.github.com/Hotell/01035a3ec202245d6b97937444140877
I can send PR to update docs if you’re willing to accept this 😃
thanks!
Hi @jedmao and @Timer, I’ve completed the plugin and wanted to get your thoughts on it. I need to:
You can find it here: https://www.npmjs.com/package/typescript-plugin-css-modules
This weekend I’ll create a PR for
create-react-app
with this included.