"use strict";

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

var _nameTemplates = require("./common/nameTemplates");

var _hashUtils = require("./custom_plugins/I18nSplitPlugin/utils/hashUtils");

var _splitChunksConfig = require("./splitChunksConfig");

function optimizationConfig(options) {
  const {
    changeRuntimeChunkChar
  } = options;
  const {
    chunkSplitEnable
  } = options.i18nChunkSplit;
  const i18nChunkFilename = (0, _nameTemplates.nameTemplates)('i18nchunkjs', options);
  const chunkFilenameHasContentHash = (0, _hashUtils.hasContentHash)(i18nChunkFilename);
  /**
   * NOTE: we only need multiple runtime files when we use contentHash 
   * other wise we don't need multiple runtime files based locale
   * that's why  we added chunkSplitEnable && chunkFilenameHasContentHash logic 
   */

  const suffix = // chunkSplitEnable ? '_[locale]' : '';
  chunkSplitEnable && chunkFilenameHasContentHash ? '_[locale]' : '';
  const char = changeRuntimeChunkChar ? '-' : '~';
  return {
    splitChunks: (0, _splitChunksConfig.splitChunksConfig)(options),
    moduleIds: 'named',
    runtimeChunk: {
      name: entrypoint => `runtime${char}${entrypoint.name}${suffix}`
    }
  };
}