5 ms·
CSS modules with TypeScript solves the first three items pretty neatly. You write CSS that lives alongside tour component, then import the file into your compon
by dimal 5y ago
CSS modules with TypeScript solves the first three items pretty neatly. You write CSS that lives alongside tour component, then import the file into your component and apply the classname to your elements. It compiles to unique classnames that cannot conflict with any others. And with TS, you’ll get a compile error if you use a class that doesn’t exist. The last point is possible either with CSS vars or Sass vars. calc() can handle some pretty complicated math. You can also do plenty of math in Sass.
- daigoba66 5y agoAre there any good examples or tutorials for using CSS modules and TypeScript as you described?
- dimal 5y agoI don't know of any full tutorials that cover both, but this is an ok rundown on how to use them in JS: https://css-tricks.com/css-modules-part-1-need/ https://css-tricks.com/css-modules-part-1-need/ This is the webpack loader that generates type def files: https://github.com/seek-oss/css-modules-typescript-loader https://github.com/seek-oss/css-modules-typescript-loader
- Keats 5y agoI wrote https://www.vincentprouillet.com/blog/using-sass-modules-typescript/ https://www.vincentprouillet.com/blog/using-sass-modules-typ... and a commit example: https://github.com/Keats/webpack-react-typescript/commit/9786130bf283d47af1d1945ac66679a0529254c4 https://github.com/Keats/webpack-react-typescript/commit/978...