text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.default = _default;
  
  var _terserWebpackPlugin = _interopRequireDefault(require("terser-webpack-plugin"));
  
  var _uglifyjsWebpackPlugin = _interopRequireDefault(require("uglifyjs-webpack-plugin"));
  
  var _lodash = require("lodash");
  
  var _terserOptions = _interopRequireDefault(require("./terserOptions"));
  
  var _uglifyOptions = _interopRequireDefault(require("./uglifyOptions"));
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
  
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  
  function mergeConfig(config, userConfig) {
    if (typeof userConfig === 'function') {
      return userConfig(config);
    } else if ((0, _lodash.isPlainObject)(userConfig)) {
      return _objectSpread({}, config, userConfig);
    } else {
      return config;
    }
  }
  
  function _default(webpackConfig, opts) {
    const disableCompress = process.env.COMPRESS === 'none';
    webpackConfig.mode('production').devtool(opts.devtool);
  
    if (disableCompress && !process.env.__FROM_UMI_TEST) {
      webpackConfig.output.pathinfo(true);
      webpackConfig.optimization.namedModules(true).namedChunks(true);
    }
  
    if (opts.hash) {
      webpackConfig.output.filename(`[name].[chunkhash:8].js`).chunkFilename(`[name].[chunkhash:8].async.js`);
    }
  
    webpackConfig.performance.hints(false);
  
    if (opts.manifest) {
      webpackConfig.plugin('manifest').use(require('webpack-manifest-plugin'), [_objectSpread({
        fileName: 'asset-manifest.json'
      }, opts.manifest)]);
    }
  
    webpackConfig.optimization // don't emit files if have error
    .noEmitOnErrors(true);
  
    if (disableCompress || process.env.__FROM_UMI_TEST) {
      webpackConfig.optimization.minimize(false);
    } else {
      webpackConfig.plugin('hash-module-ids').use(require('webpack/lib/HashedModuleIdsPlugin'));
      let minimizerName = 'uglifyjs';
      let minimizerPlugin = _uglifyjsWebpackPlugin.default;
      let minimizerOptions = [mergeConfig(_objectSpread({}, _uglifyOptions.default, {
        sourceMap: !!opts.devtool
      }), opts.uglifyJSOptions)];
  
      if (opts.minimizer === 'terserjs') {
        minimizerName = 'terserjs';
        minimizerPlugin = _terserWebpackPlugin.default;
        minimizerOptions = [mergeConfig(_objectSpread({}, _terserOptions.default, {
          sourceMap: !!opts.devtool
        }), opts.terserJSOptions)];
      }
  
      webpackConfig.optimization.minimizer(minimizerName).use(minimizerPlugin, minimizerOptions);
    }
  }