I am using CSS modules with webpack css-loader, then I bundle them with mini-css-extract-plugin. Here is how my config looks like:
{
    test: /\.css$/,
    use: [
      MiniCssExtractPlugin.loader,
      {
        loader: "css-loader",
        options: {
          modules: true,
          localIdentName: "[name]-[local]_[hash:base64:5]",
          imports: true,
          importLoaders: 1
        }
      },
      "postcss-loader"
    ]
  }
For some reason (see comments section) I would really like to apply postcss-loader not to every individual .css file, but to the whole bundle. How can I achieve that?
It's not required but I do highly recommend the autoprefixer plugin. The loaders allow you to import the specified file types.
PostCSS-loader is a WP-Loader so you can process CSS with PostCSS inside Webpack. i.e. It loads PostCSS into Webpack.
For Webpack v4, you have to install postcss-loader v4. Then add the plugin to your webpack config. For example: In the following configuration the plugin postcss-preset-env is used, which is not installed by default.
Setup PostCSS Through NPM scripts in the package. Like for example: -o public/main. css . We can configure our command to run in PostCSS CLI with different options to get our desired result. Now to run the command above, we type npm run <command name> in our terminal.
Thank you all for trying to resolve my problem. After all I've found the solution. I do not use postcss-loader any more, but instead I use OptimizeCssAssetsPlugin like this:
new OptimizeCssAssetsPlugin({
  cssProcessor: postcss([CSSMQPacker]),
}),
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With