import postCSSModulesValues from 'postcss-modules-values'
import ExtractTextPlugin from 'extract-text-webpack-plugin'

export default {
  name: 'css-modules',
  configure ({ pages = [], buildTarget }) {
    const extractCSS = new ExtractTextPlugin('[name]-[hash]-[ext].css')
    const enabled = pages.length > 0 && buildTarget === 'production'

    // importLoaders: use the following postcss-loader in @import statements
    // modules: enable css-mobules
    const baseLoader = 'css-loader?modules&sourceMap&importLoaders=1&localIdentName=[name]-[hash]!postcss-loader'

    return {
      postcss: [
        // allow importing values (variables) between css modules
        // see: https://github.com/css-modules/postcss-modules-values#usage
        postCSSModulesValues
      ],

      module: {
        loaders: [
          {
            test: /\.css$/,
            loader: enabled ? extractCSS.extract(baseLoader) : `style!${baseLoader}`
          }
        ]
      },

      plugins: enabled ? [extractCSS] : []
    }
  }
}

import postCSSModulesValues from 'postcss-modules-values'
import ExtractTextPlugin from 'extract-text-webpack-plugin'

export default {
  name: 'css-modules',
  configure ({ pages = [], buildTarget }) {
    const extractCSS = new ExtractTextPlugin('[name]-[hash].css')
    const enabled = pages.length > 0 && buildTarget === 'production'
    const localIdentName = enabled ? '[hash]' : '[path][local]'

    // importLoaders: use the following postcss-loader in @import statements
    // modules: enable css-modules
    const loaders = [
      `css?modules&sourceMap&importLoaders=1&localIdentName=${localIdentName}`,
      'postcss-loader'
    ]

    return {
      postcss: [
        // allow importing values (variables) between css modules
        // see: https://github.com/css-modules/postcss-modules-values#usage
        postCSSModulesValues
      ],

      module: {
        loaders: [
          {
            test: /\.css$/,
            loader: enabled ? extractCSS.extract(...loaders) : ['style', ...loaders].join('!')
          }
        ]
      },

      plugins: enabled ? [extractCSS] : []
    }
  }
}

Refactor code to match sass preset
Refactor code to match sass preset
