Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request feature: Add option to compile only top-level selectors in css-modules mode #423

Closed
mizchi opened this issue Feb 18, 2017 · 1 comment

Comments

@mizchi
Copy link

mizchi commented Feb 18, 2017

I use [postcss-nesting:https://github.com/jonathantneal/postcss-nesting] plugni ( implementation of CSS Nesting Module Level 3 ) and css-loader v0.26.1.

MyCode

.Hello {
  & .title {
    color: #00f;
  }
}

Compiled with css-loader?modules

._1yKwJThgxBsO6G-dlD__k6 {
}
._1yKwJThgxBsO6G-dlD__k6 ._2jGR-DRZ3K4plA7FSjgwvJ {
  color: #00f
}

All selector are flattened so I have to write like this.

import React from 'react'
import styles from './styles.css'
export default function Hello () {
  return <div className={styles.Hello}>
    <div className={styles.title}>Hello</div>
  </div>
}

But I want to write like next one.

  return <div className={styles.Hello}>
    <div className="title">Hello</div>
  </div>

So my expected behaviour is

._1yKwJThgxBsO6G-dlD__k6 {
}
._1yKwJThgxBsO6G-dlD__k6 .title {
  color: #00f
}

or styles.Hello.title (it will be hacky implementation of getter by Reflect)

To keep css moduleness, I think it's enough to convert top-level selectors and easy for css animation.

How do you think? (or already has other way of this?)

@mizchi mizchi changed the title Request feature: Add option to compile only top-level selector in css-modules mode Request feature: Add option to compile only top-level selectors in css-modules mode Feb 18, 2017
@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Mar 21, 2017

@mizchi This isn't possible with css-loader in it's current state and I think this would need some work require @css-modules instead of css-loader and the plugins there 😛 . Also wouldn't work in that way atm

<div className={styles.Hello}>
  <div className="title">Hello</div>
</div>

needs to be, because you still need the [hash] from styles.Hello as prefix for "title"

<div className={styles.Hello}>
  <div className={styles.Hello + " title"}>Hello</div>
</div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants