Skip to content

Add support for postcss-nested plugin #95

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

Closed
wants to merge 3 commits into from
Closed

Add support for postcss-nested plugin #95

wants to merge 3 commits into from

Conversation

mvsmal
Copy link
Contributor

@mvsmal mvsmal commented Jun 4, 2017

Currently if .scss file contains nested classes, postcss doesn't generate them, so they could not be resolved. To fix that we need one more plugin in requireCssModule.js file.

@gajus
Copy link
Owner

gajus commented Jun 4, 2017

@mvsmal Please add a test demonstrating the use case.

@gajus
Copy link
Owner

gajus commented Jun 5, 2017

So this is a specific plugin that you'd like to add to the processing chain, not a generic use case.

I am not going to merge this (as this would require merging a plugin for every other use case). Instead, need to look into how to make the plugin chain configurable.

Furthermore, the reason this particular setup will work for most of the users is because it is not uncommon to run SASS before postcss. By the time CSS reaches postcss, it is already flat.

@mvsmal
Copy link
Contributor Author

mvsmal commented Jun 5, 2017

It is not a specific plugin. Nested classes are one of the key features of SASS, and LESS too. Only with this plugin you can say that you support SASS (with postcss, of course). Otherwise you cannot use .scss files directly.

As for flat CSS, could you provide an example of config?

@gajus
Copy link
Owner

gajus commented Jun 5, 2017

It is not a specific plugin. Nested classes are one of the key features of SASS, and LESS too. Only with this plugin you can say that you support SASS (with postcss, of course).

"postcss" is not designed as a replacement for SASS. You can use (and should) use these together.

This is my webpack setup in the project I am working on ATM,

{
  include: path.resolve(__dirname, '../app'),
  loader: 'babel-loader',
  options: {
    babelrc: false,
    extends: path.resolve(__dirname, '../app/webpack.production.babelrc'),
    plugins: [
      [
        'react-css-modules',
        {
          context: common.context,
          filetypes: {
            '.scss': 'postcss-scss'
          },
          generateScopedName: '[name]___[local]___[hash:base64:5]',
          webpackHotModuleReloading: false
        }
      ]
    ]
  },
  test: /\.js$/
},
{
  test: /\.scss$/,
  use: extractStyles.extract({
    use: [
      {
        loader: 'css-loader',
        options: {
          camelCase: true,
          importLoaders: 1,
          localIdentName: '[name]___[local]___[hash:base64:5]',
          minimize: true,
          modules: true
        }
      },
      'resolve-url-loader',
      {
        loader: 'postcss-loader',
        options: {
          plugins: () => {
            return [
              require('postcss-svg')({
                dirs: [
                  path.resolve(__dirname, '../app/styles/icons')
                ]
              }),
              require('autoprefixer')
            ];
          }
        }
      },
      'sass-loader'
    ]
  })
},

Anything thats not postcss-modules-* plugin is out of scope for this project, but it can be supported using a configuration.

@mvsmal
Copy link
Contributor Author

mvsmal commented Jun 5, 2017

With your config, if you have nested classes in .scss files, styleName won't be able to resolve the subclasses. It just doesn't make sense to use SASS with this plugin then. It would be limited SASS.

@gajus gajus added the question label Jun 5, 2017
@gajus
Copy link
Owner

gajus commented Jun 5, 2017

With your config, if you have nested classes in .scss files, styleName won't be able to resolve the subclasses.

On a second thought, you are right. It shouldn't work in this case.

But it does work.. I will need to look into what I am doing different.

@kkwiatkowski
Copy link

kkwiatkowski commented Jul 12, 2017

Any update on this? This is really something critical since it's preventing SASS users from using this plugin and this PR looks like solution for given problem.

EDIT:
I see that similar PR is already merged that allows us to add additional plugins (it's #100), so question is no longer valid.

@seeruk
Copy link

seeruk commented Aug 24, 2017

This does indeed work, but isn't the only reason that this works because coincidentally the postcss-nested syntax for nesting is the same as SCSS's? What if SCSS add some new bit of syntax in the future or something, does it mean we're just limited to whatever PostCSS can "emulate" for us?

Is there no way we could have actual SCSS work with this plugin? It seems like that would require having the SCSS be compiled beforehand though, is that right?

Given that editor support for PostCSS seems to be improving, I'm beginning to wonder if just ditching SCSS for a set of PostCSS plugins that achieve similar functionality would be a good idea. But I worry about the potential implications of doing that (i.e. is editor support really any good? will I be missing out on being able to use existing SCSS libraries? etc.).

Edit: #90 also touches on another issue with SCSS, and it does seem that it is because the SCSS would need to be compiled to CSS first.

@gajus gajus closed this Apr 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants