Wrap styles into a :global
like postcss-nested does it for usual selectors.
You should use :global
as rare as you can.
test.css:
:global {
.foo {}
.bar {}
}
{
loader: 'postcss-loader',
options: {
plugins: [
require('autoprefixer')({
browsers: ['last 2 version'],
}),
require('postcss-nested')({}),
require('postcss-global-nested')({}),
],
},
}
import pcss from 'postcss';
import nested from 'postcss-nested';
import globalNested from 'postcss-global-nested';
(async () => {
const css = await util.promisify(fs.readFile)('test.css', 'utf8');
const result = await pcss([nested, globalNested]).process(css);
result.css // -> ':global(.foo) {} :global(.bar) {}'
})();