@zohodesk/client_build_tool
Version:
A CLI tool to build web applications and client libraries
56 lines (45 loc) • 2.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.optimizationConfig = optimizationConfig;
var _terserWebpackPlugin = _interopRequireDefault(require("terser-webpack-plugin"));
var _nameTemplates = require("./common/nameTemplates");
var _hashUtils = require("./custom_plugins/I18nSplitPlugin/utils/hashUtils");
var _configCSSMinifierPlugin = require("./pluginConfigs/configCSSMinifierPlugin");
var _splitChunksConfig = require("./splitChunksConfig");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function optimizationConfig(options) {
const {
changeRuntimeChunkChar
} = options;
const {
chunkSplitEnable
} = options.i18nChunkSplit;
const i18nChunkFilename = (0, _nameTemplates.nameTemplates)('i18njs', 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;
const excludeList = options.optimization.jsExcludePath;
return {
splitChunks: (0, _splitChunksConfig.splitChunksConfig)(options),
minimizer: [// For webpack@5 you can use the `...` syntax to extend existing minimizers (i.e. `terser-webpack-plugin`), uncomment the next line
// '...',
excludeList !== '' ? new _terserWebpackPlugin.default({
exclude: excludeList,
extractComments: false // Do not extract comments to .LICENSE.txt files
}) : new _terserWebpackPlugin.default({
extractComments: false // Do not extract comments to .LICENSE.txt files
}), (0, _configCSSMinifierPlugin.configCSSMinifierPlugin)(options)].filter(Boolean),
moduleIds: 'named',
runtimeChunk: {
name: entrypoint => `runtime${char}${entrypoint.name}${suffix}`
}
};
}