Nitive / postcss-extract

PostCSS plugin to extract css inside @at-rules into separate files
MIT License
1 stars 1 forks source link

Doesn't work with SASS, the output file is empty #136

Closed seregap closed 7 years ago

seregap commented 7 years ago

Hello

The output file appears empty

the webpack.config.js fragment is as follows:

module : {
        loaders : [{
            test   : /\.scss$/,
            loader : (ExtractTextPlugin.extract('style', 'css!postcss!sass', {  }))
    }]
    },
postcss: [
      require('postcss-extract')({
               extract: {
                 'important': path.join(__dirname, './test.css')
            }
      }),
]
Nitive commented 7 years ago

Could you please show sass file content? Just confugure webpack and everything works fine

Nitive commented 7 years ago

I added examples, check out examples/ folder

seregap commented 7 years ago

sure, here you go

entry app.js

'use strict';
var core = require('core.scss');

core.scss

@import 'modules/buttons';

buttons.scss

.button-group {
    width: 100%;
    display: table;
    table-layout: fixed;
    border-bottom: 1px solid $greyBorders;
    border-radius: 5px;
    overflow: hidden;
    .button {
        display: block;
        border-radius: 0;
        white-space: nowrap;
    }
    &__item {
        display: table-cell;
    }
    @important {
        display: inline-block;
    }
}  
seregap commented 7 years ago

@Nitive did you try it with sass-loader?

Nitive commented 7 years ago

@seregap Sass process & with at rules not correctly SassMeister screenshot

You can use extra braces

@important {
  & {
    display: inline-block;
  }
}
seregap commented 7 years ago

@Nitive it won't be processed by postcss-extract anyway, as the @rule shuld be inside selector but not outside. This is a default behaviour for @rules in any CSS preprocessor including SASS (@rule bubbles up to the css root). It would be great to have an option to change the plugin logic if needed for such cases.

your code snippet above can be even simplyfied to be as follows, but it won't help

input sass:

.button-group {
  @important {
      display: inline-block;
  }
}

output css:

@important {
  .button-group {
    display: inline-block;
  }
}

required by postcss-extract input css:

.button-group {
  @important {
    display: inline-block;
  }
}
Nitive commented 7 years ago

@seregap at rule outside selector will work fine, check out this test

Nitive commented 7 years ago

Added example in README in #141

seregap commented 7 years ago

@Nitive seems it somehow breaks inside my code. Many thanks