"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.configHtmlWebpackPlugins = configHtmlWebpackPlugins;

var _path = _interopRequireDefault(require("path"));

var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));

var _htmlWebpackInjectAttributesPlugin = _interopRequireDefault(require("html-webpack-inject-attributes-plugin"));

var _common = require("../common");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const defaultHTMLMiniFyOption = {
  collapseWhitespace: true,
  minifyCSS: true,
  minifyJS: true,
  keepClosingSlash: true,
  removeComments: false,
  removeRedundantAttributes: true,
  removeScriptTypeAttributes: true,
  removeStyleLinkTypeAttributes: true,
  useShortDoctype: true
};

function configHtmlWebpackPlugins(plugins, {
  enableChunkHash = false,
  folder,
  inject,
  crossorigin,
  hasEFC,
  minify: minifyHtmlOptions = false
}) {
  const optionsHtmlWebpack = {
    chunksSortMode: 'none',
    filename: enableChunkHash ? 'index.[templatehash:20].html' : 'index.html',
    template: _path.default.join(process.cwd(), folder, 'index.html'),
    minify: minifyHtmlOptions === true ? defaultHTMLMiniFyOption : minifyHtmlOptions === null ? false : minifyHtmlOptions,
    // : typeof minifyHtmlOptions === 'object'
    // ? minifyHtmlOptions
    // : minifyHtmlOptions,,
    templateParameters: _common.templateParameters,
    scriptLoading: 'defer',
    inject: inject
  };

  if (hasEFC) {
    optionsHtmlWebpack.excludeChunks = ['efc', 'widget'];
  }

  plugins.push(new _htmlWebpackPlugin.default(optionsHtmlWebpack));
  crossorigin && plugins.push(new _htmlWebpackInjectAttributesPlugin.default({
    crossorigin: 'anonymous'
  }));
}