GithubHelp home page GithubHelp logo

Comments (18)

geelen avatar geelen commented on April 20, 2024 12

I actually suggest a different approach β€” removing :local from css-loader altogether. I've started a discussion (webpack-contrib/css-loader#308) over there but I don't expect it to be resolved fast enough for the needs of this project, so I think this linting rule is a good solution in the interim.

Interestingly, the whole concept of importing something from a CSS file is what I was hoping to achieve by proposing ICSS as a standard format β€” a minimal extension of CSS that allowed passing symbols around. This is what css-loader actually supports, everything related to :local is actually just a series of PostCSS transforms compiling to ICSS. And so the concept of import styles from "./styles.css" was always intended to be more widely-applicable β€” not specific to Webpack, CSS Modules, or anything. It just turned out to only be really used by CSS Modules.

So I'd love to think that any future bundler of CSS would permit some form of exporting from CSS to JS and so this kind of syntax will become more standard, but I admit that's well and truly beyond the scope of this issue :)

For what it's worth, if this project did decide to "support" CSS Modules, I think the best way would be if all files ending in *.module.css were loaded with CSS Modules like Gatsby does β€” I think that's the closest thing we could get to having both no configuration and totally explicit behaviour. But I get that it's not on the roadmap for the moment.

from create-react-app.

KyleAMathews avatar KyleAMathews commented on April 20, 2024 8

In Gatsby we added CSS Modules support only for css files with names *.module.css per @andreypopp's suggestion which seems safe enough. I don't have good enough pulse on where CSS Modules are in adoption life cycle but this might be a good compromise as CSS Modules are one of the most useful things to come along in the CSS world in a long time.

from create-react-app.

gaearon avatar gaearon commented on April 20, 2024 2

At a later point, we sure can. For now let's keep it as simple as possible.

from create-react-app.

giuseppeg avatar giuseppeg commented on April 20, 2024 2

CSJS is a good alternative to CSS Modules although I like the fact that you are not trying to enforce any CSS [in JS] methodology πŸ™

from create-react-app.

gaearon avatar gaearon commented on April 20, 2024 1

We can reconsider this in a few months. But it's good to warn until/unless we commit to supporting them.

from create-react-app.

mxstbr avatar mxstbr commented on April 20, 2024 1

Both Aphrodite and Radium are fine, since they don't use any webpack-specific features, which is what we want to avoid.

If we ever switch away from webpack and people are using CSS modules they won't have any chance to update because it won't work!

from create-react-app.

casesandberg avatar casesandberg commented on April 20, 2024

I got this 🐈

from create-react-app.

hzoo avatar hzoo commented on April 20, 2024

@casesandberg I would use astexplorer to check the ast of the 2 forms

from create-react-app.

casesandberg avatar casesandberg commented on April 20, 2024

@gaearon Should this be in a eslint-plugin-create-react-app module or just as a rule in config/rules?

from create-react-app.

gaearon avatar gaearon commented on April 20, 2024

I'm not sure how to structure rules in eslint so whatever is simpler ;-)

from create-react-app.

casesandberg avatar casesandberg commented on April 20, 2024

I'm not really sure either-- if there is a possibility we will have more of these in the future we should probably bundle them all together in one plugin.

from create-react-app.

jaredpalmer avatar jaredpalmer commented on April 20, 2024

@gaearon is the plan to write linters against Aphrodite and Radium too? Or is CSS-in-JS okay to use?

from create-react-app.

jaredpalmer avatar jaredpalmer commented on April 20, 2024

@mxstbr just wanted to doublecheck

from create-react-app.

gaearon avatar gaearon commented on April 20, 2024

Meh, probably not worth it.

from create-react-app.

thien-do avatar thien-do commented on April 20, 2024

Hi, I don't know if anyone care about this anymore, but today I saw one of my teammate use CSS Modules in CRA without :local by this way:

import styles from '!style!css?modules!./background.css';

is this something "no configuration and explicit behaviour" (an alternative to the .module.css approach)?

from create-react-app.

outdooricon avatar outdooricon commented on April 20, 2024

Yes, CSS Modules now exposes locally by default and globally by explicit declaration (:global)

from create-react-app.

gaearon avatar gaearon commented on April 20, 2024

today I saw one of my teammate use CSS Modules in CRA without :local by this way

Please tell them it is entirely unsupported and we reserve the right to break this in any release.

We don’t officially support Webpack loader syntax in import statements. If you can't find something in CRA docs then it's not supported.

from create-react-app.

jfmengels avatar jfmengels commented on April 20, 2024

@gaearon There is an eslint-plugin-import rule forbidding Webpack syntax in the path (it basically warns if there is a ! in the path).

I have noticed you disabled the whole plugin because of its compatibility with eslint-loader, but you could probably still use rules like these, that do not attempt to load/read other files. (I'm happy to make you a list of rules that should be fine and useful if you want)

from create-react-app.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.