Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
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
tomaash wants to merge0 commits intowmonk:masterfromtomaash:master

Conversation

@tomaash
Copy link

@tomaashtomaash commentedOct 31, 2017
edited
Loading

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 fromhttps://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 packagehttps://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 ashttps://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

@tomaash
Copy link
Author

Actually, this is being tentatively added tocreate-react-app itself, so I guess we can just wait when it lands there:facebook/create-react-app#2285

@Jack-Works
Copy link

Maybe we can make it further, seehttps://github.com/Quramy/typed-css-modules

@christikaes
Copy link

christikaes commentedNov 18, 2017
edited
Loading

We should definitely addhttps://github.com/Jimdo/typings-for-css-modules-loader once we have css-modules. It's a drop in replacement for css-loader and generate TypeScript typings for CSS modules on the fly.

In the mean time I've created a fork of this that has the CSS Modules support + typings for css modules (Types for CSS are awesome!)https://www.npmjs.com/package/react-scripts-ts-css

tomaash reacted with heart emoji

@tomaash
Copy link
Author

Closed in favor of:#197

@tomaash
Copy link
Author

@christinakayastha Your PR lacks the support for compiling only.module.css files with css-modules. I fixed that in#197

@christikaes
Copy link

Nice! Good call (:

@tomaash
Copy link
Author

Still, your fork is much more complete. If you adopted this.module recognition from my patch, I'd use it.

@tomaash
Copy link
Author

Actually, there are multiple problems with the typings. They make css cross-dependent with typescript compilation, with leads to multiple issues (errors when you ignore d.ts to have hot reload) and also the need to keep the generated d.ts in the repo, as theyarn build does not pick them up the first time. I reverted to just using this vscode extension:https://marketplace.visualstudio.com/items?itemName=clinyong.vscode-css-modules

@christikaes
Copy link

Oh cool I didn't know about that extension.

Yea after using it for a bit, I don't like having to keep the .d.ts files. (when you use sass you have: .scss -> .css -> .css.d.ts which is a bit much...)

@tomaash
Copy link
Author

@christinakayastha I also discovered a more elegant way of making changes to create-react-app setup - using monkey patching :)
I usereact-app-rewired and now my addons to react-scripts webpack are in aplugin. Much better!

Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@tomaash@Jack-Works@christikaes

[8]ページ先頭

©2009-2025 Movatter.jp