const MiniCSSExtractPlugin = require('../compiled/mini-css-extract-plugin');
module.exports = async function addMiniCSSExtractPlugin(opts) {
  const { config, userConfig, useHash } = opts;
  const hash = useHash ? '.[contenthash:8]' : '';
  if (!userConfig.styleLoader) {
    config.plugin('mini-css-extract-plugin').use(MiniCSSExtractPlugin, [
      {
        filename: `[name]${hash}.css`,
        chunkFilename: `[name]${hash}.chunk.css`,
        ignoreOrder: true,
      },
    ]);
  }
}