This repository was archived by the owner on Jan 26, 2019. It is now read-only.
Add CSS Modules support to webpack config #180
Closed
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
CSS modules in TypeScript work as follows:
import styles
const style = require('./Home.module.css')
use in JSX
<div className={style.App}/>
This is not a breaking change, as it prefixes classes only for CSS files that follow file naming convention of
*.module.css
Actual config taken from https://github.com/ro-savage/react-scripts-cssmodules so it has actually been tested elsewhere as well. To test my change, just create react app with this fork, and try to use CSS Modules syntax. If styling is applied, then it works.
We could have a more typescript-like css import support, but that would require adding an extra package https://github.com/Jimdo/typings-for-css-modules-loader .. I figured, let's get an easy barebones support merged first.
I published this version on NPM already as https://www.npmjs.com/package/react-scripts-ts-cm
I also have a working example app created with it here: https://github.com/tomaash/react-scripts-ts-cm-test