postcss / postcss-nested

PostCSS plugin to unwrap nested rules like how Sass does it.
MIT License
1.15k stars 66 forks source link

Can I nest into a :global? #66

Closed a-x- closed 7 years ago

a-x- commented 7 years ago

I want to put styles into a :global like this:

:global {
  .smtg {}
}
ai commented 7 years ago

Interesting case. I understand that it will be useful. But I afraid of non-standard syntax. What is CSSWG will announce :global pseudo (not function).

I see two options. Add extra option. Or create postcss-global-nested plugin. I think new plugin is better, because I little busy with my new open source in next month.

In this plugin you can take care only about :global. Other nesting will be fixed by postcss-nested (you will use them both).

I think it will be 7 lines plugin:

module.exports = postcss.plugin("postcss-global-nested", () => {
  return root => {
    root.walkRules(rule => {
      rule.selector = rule.selector.replace(/:global\s+([\w\W]+)/, ":global($1)")
    }
  }
}

I will add your plugin to postcss-nested docs. What do you think about it?

a-x- commented 7 years ago

Hey, @ai, such plugin is the good solution even it's not spoiling standard-based postcss-nested plugin as you mentioned here.

R u want to create it yourself in a week or you'll be awaiting a PR?

ai commented 7 years ago

@a-x- you can create it :)