import ExtractCssChunks from 'extract-css-chunks-webpack-plugin'

export default ({ includePaths = [], ...rest }) => ({
  webpack: (config, { stage }) => {
    let loaders = []

    const sassLoaderPath = require.resolve('sass-loader')

    const sassLoader = {
      loader: sassLoaderPath,
      options: { includePaths: ['src/', ...includePaths], ...rest },
    }
    const styleLoader = { loader: 'style-loader' }
    const cssLoader = {
      loader: 'css-loader',
      options: {
        importLoaders: 1,
        minimize: stage === 'prod',
        sourceMap: false,
      },
    }

    if (stage === 'dev') {
      // Dev
      loaders = [styleLoader, cssLoader, sassLoader]
    } else if (stage === 'node') {
      // Node
      // Don't extract css to file during node build process
      loaders = [cssLoader, sassLoader]
    } else {
      // Prod
      loaders = [ExtractCssChunks.loader, cssLoader, sassLoader]
    }

    config.module.rules[0].oneOf.unshift({
      test: /\.s(a|c)ss$/,
      use: loaders,
    })

    return config
  },
})

@@ -57,16 +57,45 @@
 -plugin'
+%0Aimport semver from 'semver';
 %0A%0Aexport
@@ -539,44 +539,8 @@
  1,%0A
-        minimize: stage === 'prod',%0A
     
@@ -833,16 +833,16 @@
  else %7B%0A
-
       //
@@ -847,16 +847,394 @@
 // Prod%0A
+%0A      // for legacy css-loader version (%3C2.0) we need to add %22minimize%22 to minify css code%0A      // for %3E2.0 it is handled with https://github.com/NMFR/optimize-css-assets-webpack-plugin%0A      const cssLoaderVersion = require('css-loader/package.json').version;%0A      if (semver.satisfies(cssLoaderVersion, '%3C2') === true) %7B%0A        cssLoader.options.minimize = true;%0A      %7D%0A%0A
       lo

fix css-loader 2.0 version breaks (removed minimize option) (#884)