UNPKG

@zohodesk/client_build_tool

Version:

A CLI tool to build web applications and client libraries

43 lines (38 loc) 1.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.templateFileName = templateFileName; var _webpack = require("webpack"); var _templateHashHelpers = require("./templateHashHelpers"); function templateFileName({ compilation, dynamicFilename, localeVarName, chunks, contentHashes }) { const MODULE_TYPE = 'text/mini-i18n'; const { mapExpr, mapExprWithLength } = (0, _templateHashHelpers.templateHashHelpers)(chunks); // "i18n-chunk/[locale]/[name].[chunkhash].js" const i18nURLPathTemplate = compilation.getPath(JSON.stringify(dynamicFilename).replace(/\[locale\]/gi, '"+ locale +"'), { hash: `" + ${_webpack.RuntimeGlobals.getFullHash}() + "`, hashWithLength: length => `" + ${_webpack.RuntimeGlobals.getFullHash}().slice(0, ${length}) + "`, chunk: { id: '" + chunkId + "', hash: mapExpr(c => c.renderedHash), hashWithLength: mapExprWithLength(c => c.renderedHash), name: mapExpr(c => c.name || c.id), contentHash: { [MODULE_TYPE]: mapExpr(c => contentHashes[c.id]) }, contentHashWithLength: { [MODULE_TYPE]: mapExprWithLength(c => contentHashes[c.id]) } }, contentHashType: MODULE_TYPE }); return _webpack.Template.asString([`${_webpack.RuntimeGlobals.require}.miniI18nF = function(chunkId){var locale = (${localeVarName});return (${i18nURLPathTemplate})}`]); }