@zohodesk/react-cli 1.1.29-exp.1 → 1.1.29-exp.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/babel/babel-option-utils/babel-preset-react-option.js +0 -3
- package/lib/babel/cmjs-plugins-presets.js +1 -8
- package/lib/babel/es-plugins-presets.js +1 -8
- package/lib/common/buildEs.js +1 -0
- package/lib/common/getEntries.js +2 -13
- package/lib/common/getPublicPathConfig.js +0 -6
- package/lib/common/index.js +1 -6
- package/lib/common/runPreProcess.js +6 -15
- package/lib/common/splitChunks.js +2 -21
- package/lib/common/sslcertUpdater.js +7 -18
- package/lib/common/templateParameters.js +0 -2
- package/lib/common/testPattern.js +10 -21
- package/lib/common/valueReplacer.js +1 -16
- package/lib/configs/jest.config.js +1 -10
- package/lib/configs/libAlias.js +8 -14
- package/lib/configs/resolvers.js +4 -14
- package/lib/configs/webpack.component.umd.config.js +1 -6
- package/lib/configs/webpack.css.umd.config.js +6 -14
- package/lib/configs/webpack.dev.config.js +1 -14
- package/lib/configs/webpack.docs.config.js +1 -9
- package/lib/configs/webpack.impact.config.js +1 -8
- package/lib/configs/webpack.prod.config.js +4 -17
- package/lib/constants.js +9 -18
- package/lib/deprecationLogger.js +0 -7
- package/lib/hooks/docsProptypeHook.js +4 -8
- package/lib/jest/commitedFilesResult.js +4 -46
- package/lib/jest/coverageCollector.js +1 -12
- package/lib/jest/jsonMaker.js +0 -6
- package/lib/jest/preProcessors/cssPreprocessor.js +1 -9
- package/lib/jest/preProcessors/jsPreprocessor.js +1 -6
- package/lib/jest/preProcessors/otherFilesPreprocessor.js +1 -4
- package/lib/jest/result.js +1 -23
- package/lib/jest/run.js +7 -18
- package/lib/jest/setup.js +8 -60
- package/lib/loaderUtils/configsAssetsLoaders.js +2 -12
- package/lib/loaderUtils/getCSSLoaders.js +10 -22
- package/lib/loaderUtils/getDevJsLoaders.js +4 -13
- package/lib/loaderUtils/index.js +1 -4
- package/lib/loaderUtils/tests/windowsModification.test.js +0 -1
- package/lib/loaderUtils/windowsModification.js +2 -3
- package/lib/loaders/__test__/markdownLoader.spec.js +0 -1
- package/lib/loaders/composeLoader.js +13 -37
- package/lib/loaders/docsLoader.js +1 -12
- package/lib/loaders/docsPropsLoader.js +4 -8
- package/lib/loaders/enhancedReactLiveConverter.js +2 -23
- package/lib/loaders/fileBountryLoader.js +1 -3
- package/lib/loaders/fileLoader.js +12 -23
- package/lib/loaders/markdownLoader.js +14 -19
- package/lib/loaders/reactLiveConvertor.js +5 -15
- package/lib/loaders/scriptInstrumentLoader.js +7 -16
- package/lib/loaders/selectorMappingLoader.js +7 -26
- package/lib/loaders/workerLoader.js +9 -24
- package/lib/logger.js +0 -4
- package/lib/middlewares/HMRMiddleware.js +13 -27
- package/lib/middlewares/SSTMiddleware.js +1 -5
- package/lib/pluginUtils/configHtmlWebpackPlugins.js +1 -24
- package/lib/pluginUtils/getDevPlugins.js +9 -42
- package/lib/pluginUtils/getDocsPlugins.js +3 -13
- package/lib/pluginUtils/getLibraryImactPlugins.js +5 -6
- package/lib/pluginUtils/getLibraryPlugins.js +2 -8
- package/lib/pluginUtils/getProdPlugins.js +8 -47
- package/lib/pluginUtils/getServerPlugins.js +2 -8
- package/lib/pluginUtils/getUMDCSSPlugins.js +2 -10
- package/lib/pluginUtils/getUMDComponentPlugins.js +2 -10
- package/lib/pluginUtils/index.js +1 -9
- package/lib/plugins/CdnChangePlugin.js +2 -18
- package/lib/plugins/CleanupStatsPlugin.js +0 -5
- package/lib/plugins/CssOrderControlPlugin.js +3 -6
- package/lib/plugins/CustomAttributePlugin.js +14 -19
- package/lib/plugins/CustomScriptLoadingStrategyPlugin.js +3 -23
- package/lib/plugins/EFCPlugin.js +20 -34
- package/lib/plugins/EFCTemplatePlugin.js +19 -30
- package/lib/plugins/EfcResourceCleanupPlugin.js +0 -3
- package/lib/plugins/EventsHandlingPlugin.js +2 -4
- package/lib/plugins/I18NInjectIntoIndexPlugin.js +11 -37
- package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +10 -15
- package/lib/plugins/I18nSplitPlugin/I18nDependency.js +4 -10
- package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +12 -25
- package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +55 -133
- package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +12 -23
- package/lib/plugins/I18nSplitPlugin/index.js +13 -24
- package/lib/plugins/I18nSplitPlugin/utils/applyMetaManifest.js +64 -58
- package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +2 -12
- package/lib/plugins/I18nSplitPlugin/utils/createMetaManifest.js +10 -29
- package/lib/plugins/I18nSplitPlugin/utils/createRegularManifest.js +8 -19
- package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +0 -1
- package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +0 -5
- package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +1 -8
- package/lib/plugins/I18nSplitPlugin/utils/index.js +0 -4
- package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +0 -20
- package/lib/plugins/I18nSplitPlugin/utils/unicodeConversion.js +0 -1
- package/lib/plugins/ManifestPlugin.js +1 -18
- package/lib/plugins/MinifyPlugin.js +1 -10
- package/lib/plugins/ModuleStatsPlugin.js +1 -24
- package/lib/plugins/OptimizeJSPlugin.js +2 -10
- package/lib/plugins/PublicPathCallbackPlugin.js +1 -12
- package/lib/plugins/PublicPathChangePlugin.js +6 -39
- package/lib/plugins/ReportGeneratePlugin.js +5 -32
- package/lib/plugins/RequireVariablePublicPlugin.js +1 -8
- package/lib/plugins/ResourceHintsPlugin.js +4 -13
- package/lib/plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +12 -17
- package/lib/plugins/RtlSplitPlugin/RtlCssPlugin.js +10 -17
- package/lib/plugins/RtlSplitPlugin/replaceCssDirTemplate.js +2 -5
- package/lib/plugins/ScriptInstrumentPlugin.js +1 -8
- package/lib/plugins/SelectorPlugin.js +6 -32
- package/lib/plugins/ServiceWorkerPlugin.js +5 -22
- package/lib/plugins/ShadowDOMSupportPlugin.js +4 -41
- package/lib/plugins/SourceMapHookPlugin.js +2 -12
- package/lib/plugins/StatsPlugin.js +0 -14
- package/lib/plugins/TPHashMappingPlugin.js +3 -18
- package/lib/plugins/UnusedFilesFindPlugin.js +4 -39
- package/lib/plugins/VariableConversionCollector.js +15 -42
- package/lib/plugins/index.js +1 -20
- package/lib/plugins/libraryImpactPlugin.js +1 -33
- package/lib/plugins/newi18nsplitplugin/18nPlugin1.js +306 -0
- package/lib/plugins/newi18nsplitplugin/18nPlugin2.js +363 -0
- package/lib/plugins/newi18nsplitplugin/18nPlugin3.js +694 -0
- package/lib/plugins/newi18nsplitplugin/18nPlugin_hashed.js +1258 -0
- package/lib/plugins/newi18nsplitplugin/18nPlugin_working.js +542 -0
- package/lib/plugins/newi18nsplitplugin/18nplugin.js +974 -0
- package/lib/plugins/newi18nsplitplugin/ChunkManager.js +131 -0
- package/lib/plugins/newi18nsplitplugin/GenerateModuleIdToKeysMapPlugin.js +59 -0
- package/lib/plugins/newi18nsplitplugin/I18nDiffPlugin.js +262 -0
- package/lib/plugins/newi18nsplitplugin/I18nDownloadLogic.js +166 -0
- package/lib/plugins/newi18nsplitplugin/I18nPropertiesPlugin.js +111 -0
- package/lib/plugins/newi18nsplitplugin/KeyCollector.js +163 -0
- package/lib/plugins/newi18nsplitplugin/ManifestGenerator.js +88 -0
- package/lib/plugins/newi18nsplitplugin/UnicodeConversionPlugin.js +101 -0
- package/lib/plugins/newi18nsplitplugin/constants.js +162 -0
- package/lib/plugins/newi18nsplitplugin/utils/I18nKeyHasher.js +78 -0
- package/lib/plugins/newi18nsplitplugin/utils/getJsResourceKeys.js +22 -0
- package/lib/plugins/newi18nsplitplugin/utils/i18nChunkUtils.js +18 -0
- package/lib/plugins/newi18nsplitplugin/utils/manifestGenerator.js +580 -0
- package/lib/plugins/newi18nsplitplugin/utils/propertiesUtils.js +54 -0
- package/lib/plugins/utils/classHandling.js +0 -6
- package/lib/plugins/utils/fileHandling.js +6 -15
- package/lib/plugins/utils/tests/fileHandling.test.js +0 -4
- package/lib/plugins/variableConvertorUtils.js +14 -29
- package/lib/plugins/webpackwatchrunplugin.js +0 -5
- package/lib/postcss-plugins/EmptyPlugin.js +3 -4
- package/lib/postcss-plugins/ExcludePlugin.js +1 -5
- package/lib/postcss-plugins/IncludePlugin.js +1 -5
- package/lib/postcss-plugins/RTLSplitPlugin.js +14 -27
- package/lib/postcss-plugins/SelectorReplace.js +1 -16
- package/lib/postcss-plugins/ValueReplacer.js +7 -6
- package/lib/postcss-plugins/__test__/hoverActivePlugin.spec.js +0 -3
- package/lib/postcss-plugins/__test__/selectorReplace.test.js +6 -3
- package/lib/postcss-plugins/__test__/valueReplacer.spec.js +2 -5
- package/lib/postcss-plugins/hoverActivePlugin.js +31 -67
- package/lib/postcss-plugins/variableModificationPlugin/ErrorHandler.js +0 -7
- package/lib/postcss-plugins/variableModificationPlugin/index.js +28 -49
- package/lib/schemas/index.js +3 -9
- package/lib/servers/clusterHubServer.js +1 -11
- package/lib/servers/devBuild.js +14 -26
- package/lib/servers/docsServer.js +1 -3
- package/lib/servers/docsServerCore.js +1 -22
- package/lib/servers/getCliPath.js +0 -9
- package/lib/servers/helpServer.js +1 -6
- package/lib/servers/httpsOptions.js +2 -8
- package/lib/servers/impactServer.js +3 -35
- package/lib/servers/mockserver.js +1 -10
- package/lib/servers/nowatchserver.js +12 -37
- package/lib/servers/requireLocalOrGlobal.js +6 -17
- package/lib/servers/scrServer.js +14 -21
- package/lib/servers/server.js +6 -36
- package/lib/servers/ssServer.js +1 -17
- package/lib/templates/CoverageScriptTemplate.js +0 -14
- package/lib/templates/WMSTemplate.js +7 -13
- package/lib/templates/linterConstant.js +2 -4
- package/lib/utils/babelPresets.js +3 -7
- package/lib/utils/clean.js +3 -9
- package/lib/utils/copy.js +1 -7
- package/lib/utils/copyTimezones.js +1 -9
- package/lib/utils/createEventStream.js +1 -6
- package/lib/utils/cssClassNameGenerate.js +10 -30
- package/lib/utils/cssURLReplacer.js +1 -22
- package/lib/utils/dependencyPostPublish.js +1 -10
- package/lib/utils/deprecationSupport.js +7 -32
- package/lib/utils/fileUtils.js +1 -28
- package/lib/utils/folderIterator.js +2 -13
- package/lib/utils/getComponents.js +0 -21
- package/lib/utils/getCurrentBranch.js +0 -5
- package/lib/utils/getDependenciesImpactList.js +1 -22
- package/lib/utils/getFileType.js +2 -10
- package/lib/utils/getHash.js +1 -8
- package/lib/utils/getIp.js +0 -2
- package/lib/utils/getOptions.js +16 -53
- package/lib/utils/getServerURL.js +1 -10
- package/lib/utils/index.js +4 -51
- package/lib/utils/init.js +0 -1
- package/lib/utils/initPreCommitHook.js +7 -30
- package/lib/utils/jsonHelper.js +3 -22
- package/lib/utils/libraryImpactConfig.js +2 -5
- package/lib/utils/lint/addScripts.js +2 -5
- package/lib/utils/lint/checkExistingConfig.js +3 -12
- package/lib/utils/lint/copyConfigs.js +0 -3
- package/lib/utils/lint/index.js +0 -9
- package/lib/utils/lint/lintScripts.js +0 -1
- package/lib/utils/lint/lintSetup.js +3 -4
- package/lib/utils/lint/lintStagedPreCommitHook.js +0 -1
- package/lib/utils/lint/question.js +0 -7
- package/lib/utils/lintReporter.js +0 -20
- package/lib/utils/log.js +0 -1
- package/lib/utils/mailSender.js +1 -8
- package/lib/utils/object-manipulation.js +1 -17
- package/lib/utils/pullOrigin.js +0 -4
- package/lib/utils/reinstallDependencies.js +1 -29
- package/lib/utils/removeAttributes.js +1 -8
- package/lib/utils/repoClone.js +3 -28
- package/lib/utils/request.js +0 -12
- package/lib/utils/rtl.js +5 -17
- package/lib/utils/selectorReplacer.js +10 -16
- package/lib/utils/setEnvVariables.js +0 -2
- package/lib/utils/ssTestHack.js +1 -11
- package/lib/utils/switchBranch.js +0 -5
- package/lib/utils/typeCheck.js +0 -1
- package/lib/utils/urlConcat.js +0 -4
- package/lib/utils/useExitCleanup.js +9 -10
- package/lib/utils/variableConverter.js +22 -31
- package/{npm-shrinkwrap.json → package-lock.json} +2098 -1999
- package/package.json +1 -1
@@ -0,0 +1,22 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
// utils/getJsResourceKeys.js
|
4
|
+
const fs = require('fs');
|
5
|
+
const readline = require('readline');
|
6
|
+
function getJsResourceKeys(filePath) {
|
7
|
+
const keys = new Set();
|
8
|
+
const fileContent = fs.readFileSync(filePath, 'utf8');
|
9
|
+
const lines = fileContent.split(/\r?\n/);
|
10
|
+
for (const line of lines) {
|
11
|
+
const trimmedLine = line.trim();
|
12
|
+
if (trimmedLine && !trimmedLine.startsWith('#')) {
|
13
|
+
const equalIndex = trimmedLine.indexOf('=');
|
14
|
+
if (equalIndex > 0) {
|
15
|
+
const key = trimmedLine.slice(0, equalIndex).trim();
|
16
|
+
keys.add(key);
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
return keys;
|
21
|
+
}
|
22
|
+
module.exports = getJsResourceKeys;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
// i18nChunkUtils.js
|
4
|
+
const crypto = require('crypto');
|
5
|
+
function hashKey(key) {
|
6
|
+
return crypto.createHash('md5').update(key).digest('hex');
|
7
|
+
}
|
8
|
+
function getChunkIdForKey(key) {
|
9
|
+
const hash = hashKey(key);
|
10
|
+
const numChunks = 100;
|
11
|
+
const numericHash = parseInt(hash.substring(0, 8), 16);
|
12
|
+
const chunkId = numericHash % numChunks;
|
13
|
+
return `chunk-${chunkId}`;
|
14
|
+
}
|
15
|
+
module.exports = {
|
16
|
+
hashKey,
|
17
|
+
getChunkIdForKey
|
18
|
+
};
|
@@ -0,0 +1,580 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
// // // // // const crypto = require('crypto');
|
4
|
+
// // // // // const { RawSource } = require('webpack-sources');
|
5
|
+
// // // // // function getChunkIdForKey(key, NUMBER_OF_CHUNKS) {
|
6
|
+
// // // // // const hash = crypto.createHash('md5');
|
7
|
+
// // // // // hash.update(key);
|
8
|
+
// // // // // const digest = hash.digest('hex');
|
9
|
+
// // // // // const numericHash = parseInt(digest.substr(0, 8), 16);
|
10
|
+
// // // // // return numericHash % NUMBER_OF_CHUNKS;
|
11
|
+
// // // // // }
|
12
|
+
// // // // // function generateManifests(options) {
|
13
|
+
// // // // // const {
|
14
|
+
// // // // // compilation,
|
15
|
+
// // // // // allI18nKeys,
|
16
|
+
// // // // // moduleToKeysMap,
|
17
|
+
// // // // // keyToModulesMap,
|
18
|
+
// // // // // moduleChunkIdToModulesMap,
|
19
|
+
// // // // // entryPointKeys,
|
20
|
+
// // // // // NUMBER_OF_CHUNKS,
|
21
|
+
// // // // // } = options;
|
22
|
+
// // // // // const metadataManifest = {
|
23
|
+
// // // // // keyToModulesMap: {},
|
24
|
+
// // // // // keyToChunkIdMap: {},
|
25
|
+
// // // // // moduleToKeysMap: {},
|
26
|
+
// // // // // };
|
27
|
+
// // // // // const runtimeManifest = {
|
28
|
+
// // // // // moduleToI18nChunkMap: {},
|
29
|
+
// // // // // locales: {},
|
30
|
+
// // // // // };
|
31
|
+
// // // // // const keyToI18nChunkIdMap = {};
|
32
|
+
// // // // // // Get the list of locales
|
33
|
+
// // // // // const locales = Object.keys(allI18nKeys);
|
34
|
+
// // // // // // Map from i18nChunkId to keys
|
35
|
+
// // // // // const i18nChunkIdToKeysMap = {};
|
36
|
+
// // // // // // Initialize the chunks
|
37
|
+
// // // // // for (let i = 0; i < NUMBER_OF_CHUNKS; i++) {
|
38
|
+
// // // // // i18nChunkIdToKeysMap[i] = [];
|
39
|
+
// // // // // }
|
40
|
+
// // // // // // Collect all keys from the i18n files
|
41
|
+
// // // // // const allKeys = Object.keys(keyToModulesMap);
|
42
|
+
// // // // // // Assign keys to chunks using hash-based mapping
|
43
|
+
// // // // // for (const key of allKeys) {
|
44
|
+
// // // // // const chunkId = getChunkIdForKey(key, NUMBER_OF_CHUNKS);
|
45
|
+
// // // // // i18nChunkIdToKeysMap[chunkId].push(key);
|
46
|
+
// // // // // // Map key to chunk ID
|
47
|
+
// // // // // keyToI18nChunkIdMap[key] = chunkId;
|
48
|
+
// // // // // // Populate metadata manifest
|
49
|
+
// // // // // metadataManifest.keyToChunkIdMap[key] = chunkId;
|
50
|
+
// // // // // metadataManifest.keyToModulesMap[key] = Array.from(keyToModulesMap[key]);
|
51
|
+
// // // // // }
|
52
|
+
// // // // // // Populate moduleToKeysMap in metadata manifest
|
53
|
+
// // // // // for (const [moduleResource, keys] of moduleToKeysMap.entries()) {
|
54
|
+
// // // // // metadataManifest.moduleToKeysMap[moduleResource] = keys;
|
55
|
+
// // // // // }
|
56
|
+
// // // // // // Now, generate the i18n chunks for each locale
|
57
|
+
// // // // // for (const locale of locales) {
|
58
|
+
// // // // // runtimeManifest.locales[locale] = runtimeManifest.locales[locale] || {};
|
59
|
+
// // // // // for (let i = 0; i < NUMBER_OF_CHUNKS; i++) {
|
60
|
+
// // // // // const keys = i18nChunkIdToKeysMap[i];
|
61
|
+
// // // // // const i18nData = {};
|
62
|
+
// // // // // for (const key of keys) {
|
63
|
+
// // // // // const value = allI18nKeys[locale][key];
|
64
|
+
// // // // // if (value !== undefined) {
|
65
|
+
// // // // // i18nData[key] = value;
|
66
|
+
// // // // // }
|
67
|
+
// // // // // }
|
68
|
+
// // // // // if (Object.keys(i18nData).length > 0) {
|
69
|
+
// // // // // const moduleSource = `window.loadI18nChunk(${JSON.stringify(i18nData)});`;
|
70
|
+
// // // // // const filename = `i18n-chunks/${locale}/chunk-${i}.js`;
|
71
|
+
// // // // // compilation.emitAsset(filename, new RawSource(moduleSource));
|
72
|
+
// // // // // runtimeManifest.locales[locale][i] = filename;
|
73
|
+
// // // // // console.log(`Emitted i18n chunk: ${filename}`);
|
74
|
+
// // // // // }
|
75
|
+
// // // // // }
|
76
|
+
// // // // // }
|
77
|
+
// // // // // // Now, create moduleToI18nChunkMap for runtime manifest
|
78
|
+
// // // // // for (const [moduleChunkId, moduleResources] of Object.entries(moduleChunkIdToModulesMap)) {
|
79
|
+
// // // // // const requiredI18nChunkIds = new Set();
|
80
|
+
// // // // // for (const moduleResource of moduleResources) {
|
81
|
+
// // // // // const keys = moduleToKeysMap.get(moduleResource);
|
82
|
+
// // // // // if (keys) {
|
83
|
+
// // // // // for (const key of keys) {
|
84
|
+
// // // // // const i18nChunkId = keyToI18nChunkIdMap[key];
|
85
|
+
// // // // // if (i18nChunkId !== undefined) {
|
86
|
+
// // // // // requiredI18nChunkIds.add(i18nChunkId);
|
87
|
+
// // // // // }
|
88
|
+
// // // // // }
|
89
|
+
// // // // // }
|
90
|
+
// // // // // }
|
91
|
+
// // // // // if (requiredI18nChunkIds.size > 0) {
|
92
|
+
// // // // // runtimeManifest.moduleToI18nChunkMap[moduleChunkId] = Array.from(requiredI18nChunkIds);
|
93
|
+
// // // // // } else {
|
94
|
+
// // // // // // console.log(`No required i18n chunks for module chunk ID ${moduleChunkId}`);
|
95
|
+
// // // // // }
|
96
|
+
// // // // // }
|
97
|
+
// // // // // // Emit the metadata manifest
|
98
|
+
// // // // // const metadataManifestSource = new RawSource(
|
99
|
+
// // // // // `window.i18n = window.i18n || {}; window.i18n.metadataManifest = ${JSON.stringify(metadataManifest, null, 2)};`
|
100
|
+
// // // // // );
|
101
|
+
// // // // // const metadataManifestFilename = 'i18n-chunks/metadataManifest.js';
|
102
|
+
// // // // // compilation.emitAsset(metadataManifestFilename, metadataManifestSource);
|
103
|
+
// // // // // console.log(`Emitted metadata manifest: ${metadataManifestFilename}`);
|
104
|
+
// // // // // // Emit the runtime manifest
|
105
|
+
// // // // // const runtimeManifestSource = new RawSource(
|
106
|
+
// // // // // `window.i18n = window.i18n || {}; window.i18n.runtimeManifest = ${JSON.stringify(runtimeManifest, null, 2)};`
|
107
|
+
// // // // // );
|
108
|
+
// // // // // const runtimeManifestFilename = 'i18n-chunks/runtimeManifest.js';
|
109
|
+
// // // // // compilation.emitAsset(runtimeManifestFilename, runtimeManifestSource);
|
110
|
+
// // // // // console.log(`Emitted runtime manifest: ${runtimeManifestFilename}`);
|
111
|
+
// // // // // }
|
112
|
+
// // // // // module.exports = { generateManifests };
|
113
|
+
// // // // const { RawSource } = require('webpack-sources');
|
114
|
+
// // // // function generateManifests(options) {
|
115
|
+
// // // // const {
|
116
|
+
// // // // compilation,
|
117
|
+
// // // // allI18nKeys,
|
118
|
+
// // // // moduleToKeysMap,
|
119
|
+
// // // // keyToModulesMap,
|
120
|
+
// // // // moduleChunkIdToModulesMap,
|
121
|
+
// // // // keyToI18nChunkIdMap, // Receive the map from I18nPlugin
|
122
|
+
// // // // } = options;
|
123
|
+
// // // // // // Inside generateManifests
|
124
|
+
// // // // // console.log('keyToI18nChunkIdMap:', keyToI18nChunkIdMap);
|
125
|
+
// // // // // console.log('moduleChunkIdToModulesMap:', moduleChunkIdToModulesMap);
|
126
|
+
// // // // // console.log('moduleToKeysMap:', moduleToKeysMap);
|
127
|
+
// // // // // console.log('runtimeManifest.moduleToI18nChunkMap:', runtimeManifest.moduleToI18nChunkMap);
|
128
|
+
// // // // const metadataManifest = {
|
129
|
+
// // // // keyToModulesMap: {},
|
130
|
+
// // // // keyToChunkIdMap: {},
|
131
|
+
// // // // moduleToKeysMap: {},
|
132
|
+
// // // // };
|
133
|
+
// // // // const runtimeManifest = {
|
134
|
+
// // // // moduleToI18nChunkMap: {},
|
135
|
+
// // // // locales: {},
|
136
|
+
// // // // };
|
137
|
+
// // // // // Use the keyToI18nChunkIdMap provided
|
138
|
+
// // // // // Populate metadataManifest.keyToChunkIdMap and keyToModulesMap
|
139
|
+
// // // // for (const [key, modulesSet] of keyToModulesMap.entries()) {
|
140
|
+
// // // // const chunkId = keyToI18nChunkIdMap[key];
|
141
|
+
// // // // metadataManifest.keyToChunkIdMap[key] = chunkId;
|
142
|
+
// // // // metadataManifest.keyToModulesMap[key] = Array.from(modulesSet);
|
143
|
+
// // // // }
|
144
|
+
// // // // // Populate moduleToKeysMap in metadata manifest
|
145
|
+
// // // // for (const [moduleResource, keys] of moduleToKeysMap.entries()) {
|
146
|
+
// // // // metadataManifest.moduleToKeysMap[moduleResource] = keys;
|
147
|
+
// // // // }
|
148
|
+
// // // // // Now, create moduleToI18nChunkMap for runtime manifest
|
149
|
+
// // // // for (const [moduleChunkId, moduleResources] of Object.entries(moduleChunkIdToModulesMap)) {
|
150
|
+
// // // // const requiredI18nChunkIds = new Set();
|
151
|
+
// // // // for (const moduleResource of moduleResources) {
|
152
|
+
// // // // const keys = moduleToKeysMap.get(moduleResource);
|
153
|
+
// // // // if (keys) {
|
154
|
+
// // // // for (const key of keys) {
|
155
|
+
// // // // const i18nChunkId = keyToI18nChunkIdMap[key];
|
156
|
+
// // // // if (i18nChunkId !== undefined) {
|
157
|
+
// // // // requiredI18nChunkIds.add(i18nChunkId);
|
158
|
+
// // // // }
|
159
|
+
// // // // }
|
160
|
+
// // // // }
|
161
|
+
// // // // }
|
162
|
+
// // // // if (requiredI18nChunkIds.size > 0) {
|
163
|
+
// // // // runtimeManifest.moduleToI18nChunkMap[moduleChunkId] = Array.from(requiredI18nChunkIds);
|
164
|
+
// // // // } else {
|
165
|
+
// // // // console.log(`No required i18n chunks for module chunk ID ${moduleChunkId}`);
|
166
|
+
// // // // }
|
167
|
+
// // // // }
|
168
|
+
// // // // // Emit the metadata manifest
|
169
|
+
// // // // const metadataManifestSource = new RawSource(
|
170
|
+
// // // // `window.i18n = window.i18n || {}; window.i18n.metadataManifest = ${JSON.stringify(metadataManifest, null, 2)};`
|
171
|
+
// // // // );
|
172
|
+
// // // // const metadataManifestFilename = 'i18n-chunks/metadataManifest.js';
|
173
|
+
// // // // compilation.emitAsset(metadataManifestFilename, metadataManifestSource);
|
174
|
+
// // // // console.log(`Emitted metadata manifest: ${metadataManifestFilename}`);
|
175
|
+
// // // // // Emit the runtime manifest
|
176
|
+
// // // // const runtimeManifestSource = new RawSource(
|
177
|
+
// // // // `window.i18n = window.i18n || {}; window.i18n.runtimeManifest = ${JSON.stringify(runtimeManifest, null, 2)};`
|
178
|
+
// // // // );
|
179
|
+
// // // // const runtimeManifestFilename = 'i18n-chunks/runtimeManifest.js';
|
180
|
+
// // // // compilation.emitAsset(runtimeManifestFilename, runtimeManifestSource);
|
181
|
+
// // // // console.log(`Emitted runtime manifest: ${runtimeManifestFilename}`);
|
182
|
+
// // // // }
|
183
|
+
// // // // module.exports = { generateManifests };
|
184
|
+
// // // const { RawSource } = require('webpack-sources');
|
185
|
+
// // // function generateManifests({
|
186
|
+
// // // compilation,
|
187
|
+
// // // allI18nKeys,
|
188
|
+
// // // moduleToKeysMap,
|
189
|
+
// // // keyToModulesMap,
|
190
|
+
// // // moduleChunkIdToModulesMap,
|
191
|
+
// // // jsResourceI18nKeys,
|
192
|
+
// // // }) {
|
193
|
+
// // // const manifest = {
|
194
|
+
// // // moduleToI18nChunkMap: {},
|
195
|
+
// // // locales: {},
|
196
|
+
// // // debugInfo: {},
|
197
|
+
// // // };
|
198
|
+
// // // const locales = Object.keys(allI18nKeys);
|
199
|
+
// // // let i18nChunkIdCounter = 0;
|
200
|
+
// // // const sectionToI18nChunkIdMap = {};
|
201
|
+
// // // const keyToI18nChunkIdMap = {};
|
202
|
+
// // // // Collect all keys to be included (only those in jsResourceI18nKeys)
|
203
|
+
// // // const allKeysToInclude = new Set(Object.keys(jsResourceI18nKeys));
|
204
|
+
// // // // Build chunks up to 100KB
|
205
|
+
// // // const chunks = [];
|
206
|
+
// // // let currentChunk = {
|
207
|
+
// // // sections: [],
|
208
|
+
// // // size: 0,
|
209
|
+
// // // id: i18nChunkIdCounter++,
|
210
|
+
// // // };
|
211
|
+
// // // // Assuming all locales have the same sections as the first locale
|
212
|
+
// // // const firstLocale = locales[0];
|
213
|
+
// // // const sections = Object.keys(allI18nKeys[firstLocale]);
|
214
|
+
// // // for (const sectionName of sections) {
|
215
|
+
// // // // Filter keys in the section based on jsResourceI18nKeys
|
216
|
+
// // // const sectionKeys = Object.keys(allI18nKeys[firstLocale][sectionName] || {});
|
217
|
+
// // // const filteredKeys = sectionKeys.filter((key) =>
|
218
|
+
// // // allKeysToInclude.has(key)
|
219
|
+
// // // );
|
220
|
+
// // // if (filteredKeys.length === 0) {
|
221
|
+
// // // continue; // Skip sections with no relevant keys
|
222
|
+
// // // }
|
223
|
+
// // // // Estimate the size of the section
|
224
|
+
// // // const sectionData = {};
|
225
|
+
// // // for (const key of filteredKeys) {
|
226
|
+
// // // sectionData[key] = allI18nKeys[firstLocale][sectionName][key];
|
227
|
+
// // // }
|
228
|
+
// // // const sectionSize = Buffer.byteLength(
|
229
|
+
// // // JSON.stringify(sectionData),
|
230
|
+
// // // 'utf8'
|
231
|
+
// // // );
|
232
|
+
// // // if (currentChunk.size + sectionSize > 100 * 1024) {
|
233
|
+
// // // // Start a new chunk
|
234
|
+
// // // chunks.push(currentChunk);
|
235
|
+
// // // currentChunk = {
|
236
|
+
// // // sections: [],
|
237
|
+
// // // size: 0,
|
238
|
+
// // // id: i18nChunkIdCounter++,
|
239
|
+
// // // };
|
240
|
+
// // // }
|
241
|
+
// // // currentChunk.sections.push(sectionName);
|
242
|
+
// // // currentChunk.size += sectionSize;
|
243
|
+
// // // // Map section to chunk id
|
244
|
+
// // // sectionToI18nChunkIdMap[sectionName] = currentChunk.id;
|
245
|
+
// // // }
|
246
|
+
// // // // Add the last chunk
|
247
|
+
// // // if (currentChunk.sections.length > 0) {
|
248
|
+
// // // chunks.push(currentChunk);
|
249
|
+
// // // }
|
250
|
+
// // // // Map keys to i18nChunkIds
|
251
|
+
// // // for (const sectionName of sections) {
|
252
|
+
// // // if (!sectionToI18nChunkIdMap.hasOwnProperty(sectionName)) {
|
253
|
+
// // // continue; // Skip sections not included
|
254
|
+
// // // }
|
255
|
+
// // // const i18nChunkId = sectionToI18nChunkIdMap[sectionName];
|
256
|
+
// // // const keys = Object.keys(allI18nKeys[firstLocale][sectionName] || {});
|
257
|
+
// // // const filteredKeys = keys.filter((key) => allKeysToInclude.has(key));
|
258
|
+
// // // for (const key of filteredKeys) {
|
259
|
+
// // // keyToI18nChunkIdMap[key] = i18nChunkId;
|
260
|
+
// // // }
|
261
|
+
// // // }
|
262
|
+
// // // // Generate the i18n chunk files for each locale and chunk
|
263
|
+
// // // for (const locale of locales) {
|
264
|
+
// // // manifest.locales[locale] = manifest.locales[locale] || {};
|
265
|
+
// // // manifest.debugInfo[locale] = {};
|
266
|
+
// // // for (const chunk of chunks) {
|
267
|
+
// // // const i18nData = {};
|
268
|
+
// // // for (const sectionName of chunk.sections) {
|
269
|
+
// // // const sectionKeys = allI18nKeys[locale][sectionName] || {};
|
270
|
+
// // // for (const key of Object.keys(sectionKeys)) {
|
271
|
+
// // // if (allKeysToInclude.has(key)) {
|
272
|
+
// // // i18nData[key] = sectionKeys[key];
|
273
|
+
// // // }
|
274
|
+
// // // }
|
275
|
+
// // // }
|
276
|
+
// // // const numKeys = Object.keys(i18nData).length;
|
277
|
+
// // // if (numKeys > 0) {
|
278
|
+
// // // const moduleSource = `window.loadI18nChunk(${JSON.stringify(
|
279
|
+
// // // i18nData,
|
280
|
+
// // // null,
|
281
|
+
// // // 2
|
282
|
+
// // // )});`;
|
283
|
+
// // // const filename = `i18n-chunks/${locale}/chunk-${chunk.id}.js`;
|
284
|
+
// // // compilation.emitAsset(filename, new RawSource(moduleSource));
|
285
|
+
// // // manifest.locales[locale][chunk.id] = filename;
|
286
|
+
// // // manifest.debugInfo[locale][chunk.id] = {
|
287
|
+
// // // numKeys,
|
288
|
+
// // // };
|
289
|
+
// // // } else {
|
290
|
+
// // // // Even if there are no keys, we might want to create an empty chunk for consistency
|
291
|
+
// // // const moduleSource = `window.loadI18nChunk({});`;
|
292
|
+
// // // const filename = `i18n-chunks/${locale}/chunk-${chunk.id}.js`;
|
293
|
+
// // // compilation.emitAsset(filename, new RawSource(moduleSource));
|
294
|
+
// // // manifest.locales[locale][chunk.id] = filename;
|
295
|
+
// // // manifest.debugInfo[locale][chunk.id] = {
|
296
|
+
// // // numKeys: 0,
|
297
|
+
// // // };
|
298
|
+
// // // }
|
299
|
+
// // // }
|
300
|
+
// // // }
|
301
|
+
// // // // Create moduleToI18nChunkMap
|
302
|
+
// // // for (const [moduleChunkId, moduleResources] of Object.entries(
|
303
|
+
// // // moduleChunkIdToModulesMap
|
304
|
+
// // // )) {
|
305
|
+
// // // const requiredI18nChunkIds = new Set();
|
306
|
+
// // // for (const moduleResource of moduleResources) {
|
307
|
+
// // // const keys = moduleToKeysMap.get(moduleResource);
|
308
|
+
// // // if (keys) {
|
309
|
+
// // // for (const key of keys) {
|
310
|
+
// // // const i18nChunkId = keyToI18nChunkIdMap[key];
|
311
|
+
// // // if (i18nChunkId !== undefined) {
|
312
|
+
// // // requiredI18nChunkIds.add(i18nChunkId);
|
313
|
+
// // // }
|
314
|
+
// // // }
|
315
|
+
// // // }
|
316
|
+
// // // }
|
317
|
+
// // // if (requiredI18nChunkIds.size > 0) {
|
318
|
+
// // // manifest.moduleToI18nChunkMap[moduleChunkId] = Array.from(
|
319
|
+
// // // requiredI18nChunkIds
|
320
|
+
// // // );
|
321
|
+
// // // } else {
|
322
|
+
// // // console.log(
|
323
|
+
// // // `No required i18n chunks for module chunk ID ${moduleChunkId}`
|
324
|
+
// // // );
|
325
|
+
// // // }
|
326
|
+
// // // }
|
327
|
+
// // // // Emit the manifest file
|
328
|
+
// // // const manifestSource = new RawSource(
|
329
|
+
// // // `window.i18n = window.i18n || {}; window.i18n.manifest = ${JSON.stringify(
|
330
|
+
// // // manifest,
|
331
|
+
// // // null,
|
332
|
+
// // // 2
|
333
|
+
// // // )};`
|
334
|
+
// // // );
|
335
|
+
// // // const manifestFilename = 'i18n-chunks/manifest.js';
|
336
|
+
// // // compilation.emitAsset(manifestFilename, manifestSource);
|
337
|
+
// // // console.log(`Emitted i18n manifest: ${manifestFilename}`);
|
338
|
+
// // // }
|
339
|
+
// // // module.exports = {
|
340
|
+
// // // generateManifests,
|
341
|
+
// // // };
|
342
|
+
// // const { RawSource } = require('webpack-sources');
|
343
|
+
// // function generateManifests({
|
344
|
+
// // compilation,
|
345
|
+
// // allI18nKeys,
|
346
|
+
// // moduleToKeysMap,
|
347
|
+
// // chunkToModulesMap,
|
348
|
+
// // jsResourceI18nKeys,
|
349
|
+
// // }) {
|
350
|
+
// // const manifest = {
|
351
|
+
// // chunkToI18nMap: {},
|
352
|
+
// // locales: {},
|
353
|
+
// // };
|
354
|
+
// // const locales = Object.keys(allI18nKeys);
|
355
|
+
// // // For each chunk, collect all i18n keys used by its modules
|
356
|
+
// // for (const [chunkId, moduleResources] of chunkToModulesMap.entries()) {
|
357
|
+
// // const chunkI18nKeys = new Set();
|
358
|
+
// // for (const moduleResource of moduleResources) {
|
359
|
+
// // const keys = moduleToKeysMap.get(moduleResource);
|
360
|
+
// // if (keys) {
|
361
|
+
// // keys.forEach((key) => {
|
362
|
+
// // if (jsResourceI18nKeys.hasOwnProperty(key)) {
|
363
|
+
// // chunkI18nKeys.add(key);
|
364
|
+
// // }
|
365
|
+
// // });
|
366
|
+
// // }
|
367
|
+
// // }
|
368
|
+
// // // Generate i18n files per chunk and locale
|
369
|
+
// // for (const locale of locales) {
|
370
|
+
// // const i18nData = {};
|
371
|
+
// // const localeData = allI18nKeys[locale];
|
372
|
+
// // for (const key of chunkI18nKeys) {
|
373
|
+
// // // Find the key in the locale data
|
374
|
+
// // let found = false;
|
375
|
+
// // for (const section of Object.values(localeData)) {
|
376
|
+
// // if (section.hasOwnProperty(key)) {
|
377
|
+
// // i18nData[key] = section[key];
|
378
|
+
// // found = true;
|
379
|
+
// // break;
|
380
|
+
// // }
|
381
|
+
// // }
|
382
|
+
// // if (!found) {
|
383
|
+
// // console.warn(`Key "${key}" not found in locale "${locale}"`);
|
384
|
+
// // }
|
385
|
+
// // }
|
386
|
+
// // // Create the i18n chunk file
|
387
|
+
// // const moduleSource = `window.loadI18nChunk(${JSON.stringify(
|
388
|
+
// // i18nData,
|
389
|
+
// // null,
|
390
|
+
// // 2
|
391
|
+
// // )});`;
|
392
|
+
// // const filename = `i18n-chunks/${locale}/chunk-${chunkId}.js`;
|
393
|
+
// // compilation.emitAsset(filename, new RawSource(moduleSource));
|
394
|
+
// // // Update the manifest
|
395
|
+
// // if (!manifest.locales[locale]) {
|
396
|
+
// // manifest.locales[locale] = {};
|
397
|
+
// // }
|
398
|
+
// // if (!manifest.locales[locale][chunkId]) {
|
399
|
+
// // manifest.locales[locale][chunkId] = filename;
|
400
|
+
// // }
|
401
|
+
// // }
|
402
|
+
// // // Update the manifest for the chunk
|
403
|
+
// // manifest.chunkToI18nMap[chunkId] = chunkId;
|
404
|
+
// // }
|
405
|
+
// // // Emit the manifest file
|
406
|
+
// // const manifestSource = new RawSource(
|
407
|
+
// // `window.i18n = window.i18n || {}; window.i18n.manifest = ${JSON.stringify(
|
408
|
+
// // manifest,
|
409
|
+
// // null,
|
410
|
+
// // 2
|
411
|
+
// // )};`
|
412
|
+
// // );
|
413
|
+
// // const manifestFilename = 'i18n-chunks/manifest.js';
|
414
|
+
// // compilation.emitAsset(manifestFilename, manifestSource);
|
415
|
+
// // console.log(`Emitted i18n manifest: ${manifestFilename}`);
|
416
|
+
// // }
|
417
|
+
// // module.exports = {
|
418
|
+
// // generateManifests,
|
419
|
+
// // };
|
420
|
+
// const { RawSource } = require('webpack-sources');
|
421
|
+
// function generateManifests({
|
422
|
+
// compilation,
|
423
|
+
// allI18nKeys,
|
424
|
+
// moduleToKeysMap,
|
425
|
+
// cacheGroupToModulesMap,
|
426
|
+
// jsResourceI18nKeys,
|
427
|
+
// }) {
|
428
|
+
// const manifest = {
|
429
|
+
// cacheGroupToI18nMap: {},
|
430
|
+
// locales: {},
|
431
|
+
// };
|
432
|
+
// const locales = Object.keys(allI18nKeys);
|
433
|
+
// for (const [cacheGroupName, moduleResources] of cacheGroupToModulesMap.entries()) {
|
434
|
+
// const cacheGroupI18nKeys = new Set();
|
435
|
+
// for (const moduleResource of moduleResources) {
|
436
|
+
// const keys = moduleToKeysMap.get(moduleResource);
|
437
|
+
// if (keys) {
|
438
|
+
// keys.forEach((key) => {
|
439
|
+
// if (jsResourceI18nKeys.hasOwnProperty(key)) {
|
440
|
+
// cacheGroupI18nKeys.add(key);
|
441
|
+
// }
|
442
|
+
// });
|
443
|
+
// }
|
444
|
+
// }
|
445
|
+
// // Generate i18n files per cache group and locale
|
446
|
+
// for (const locale of locales) {
|
447
|
+
// const i18nData = {};
|
448
|
+
// const localeData = allI18nKeys[locale];
|
449
|
+
// for (const key of cacheGroupI18nKeys) {
|
450
|
+
// // Find the key in the locale data
|
451
|
+
// let found = false;
|
452
|
+
// for (const section of Object.values(localeData)) {
|
453
|
+
// if (section.hasOwnProperty(key)) {
|
454
|
+
// i18nData[key] = section[key];
|
455
|
+
// found = true;
|
456
|
+
// break;
|
457
|
+
// }
|
458
|
+
// }
|
459
|
+
// if (!found) {
|
460
|
+
// console.warn(`Key "${key}" not found in locale "${locale}"`);
|
461
|
+
// }
|
462
|
+
// }
|
463
|
+
// // Create the i18n chunk file
|
464
|
+
// const moduleSource = `window.loadI18nChunk(${JSON.stringify(
|
465
|
+
// i18nData,
|
466
|
+
// null,
|
467
|
+
// 2
|
468
|
+
// )});`;
|
469
|
+
// const filename = `i18n-chunks/${locale}/${cacheGroupName}.js`;
|
470
|
+
// compilation.emitAsset(filename, new RawSource(moduleSource));
|
471
|
+
// // Update the manifest
|
472
|
+
// if (!manifest.locales[locale]) {
|
473
|
+
// manifest.locales[locale] = {};
|
474
|
+
// }
|
475
|
+
// manifest.locales[locale][cacheGroupName] = filename;
|
476
|
+
// }
|
477
|
+
// // Update the manifest for the cache group
|
478
|
+
// manifest.cacheGroupToI18nMap[cacheGroupName] = cacheGroupName;
|
479
|
+
// }
|
480
|
+
// // Emit the manifest file
|
481
|
+
// const manifestSource = new RawSource(
|
482
|
+
// `window.i18n = window.i18n || {}; window.i18n.manifest = ${JSON.stringify(
|
483
|
+
// manifest,
|
484
|
+
// null,
|
485
|
+
// 2
|
486
|
+
// )};`
|
487
|
+
// );
|
488
|
+
// const manifestFilename = 'i18n-chunks/manifest.js';
|
489
|
+
// compilation.emitAsset(manifestFilename, manifestSource);
|
490
|
+
// console.log(`Emitted i18n manifest: ${manifestFilename}`);
|
491
|
+
// }
|
492
|
+
// module.exports = {
|
493
|
+
// generateManifests,
|
494
|
+
// };
|
495
|
+
const {
|
496
|
+
RawSource
|
497
|
+
} = require('webpack-sources');
|
498
|
+
function generateManifests({
|
499
|
+
compilation,
|
500
|
+
allI18nKeys,
|
501
|
+
moduleToKeysMap,
|
502
|
+
cacheGroupToModulesMap,
|
503
|
+
jsResourceI18nKeys
|
504
|
+
}) {
|
505
|
+
const manifest = {
|
506
|
+
cacheGroupToI18nMap: {},
|
507
|
+
locales: {}
|
508
|
+
};
|
509
|
+
const metaManifest = {
|
510
|
+
keyToCacheGroupMap: {}
|
511
|
+
};
|
512
|
+
const locales = Object.keys(allI18nKeys); // Map keys to cache groups
|
513
|
+
|
514
|
+
const keyToCacheGroupMap = {};
|
515
|
+
for (const [cacheGroupName, moduleResources] of cacheGroupToModulesMap.entries()) {
|
516
|
+
const cacheGroupI18nKeys = new Set();
|
517
|
+
for (const moduleResource of moduleResources) {
|
518
|
+
const keys = moduleToKeysMap.get(moduleResource);
|
519
|
+
if (keys) {
|
520
|
+
keys.forEach(key => {
|
521
|
+
if (jsResourceI18nKeys.hasOwnProperty(key)) {
|
522
|
+
cacheGroupI18nKeys.add(key); // Map key to cache group for meta manifest
|
523
|
+
|
524
|
+
if (!keyToCacheGroupMap[key]) {
|
525
|
+
keyToCacheGroupMap[key] = new Set();
|
526
|
+
}
|
527
|
+
keyToCacheGroupMap[key].add(cacheGroupName);
|
528
|
+
}
|
529
|
+
});
|
530
|
+
}
|
531
|
+
} // Generate i18n files per cache group and locale
|
532
|
+
|
533
|
+
for (const locale of locales) {
|
534
|
+
const i18nData = {};
|
535
|
+
const localeData = allI18nKeys[locale];
|
536
|
+
for (const key of cacheGroupI18nKeys) {
|
537
|
+
// Find the key in the locale data
|
538
|
+
let found = false;
|
539
|
+
for (const section of Object.values(localeData)) {
|
540
|
+
if (section.hasOwnProperty(key)) {
|
541
|
+
i18nData[key] = section[key];
|
542
|
+
found = true;
|
543
|
+
break;
|
544
|
+
}
|
545
|
+
}
|
546
|
+
if (!found) {
|
547
|
+
console.warn(`Key "${key}" not found in locale "${locale}"`);
|
548
|
+
}
|
549
|
+
} // Create the i18n chunk file
|
550
|
+
|
551
|
+
const moduleSource = `window.loadI18nChunk(${JSON.stringify(i18nData, null, 2)});`;
|
552
|
+
const filename = `i18n-chunks/${locale}/${cacheGroupName}.js`;
|
553
|
+
compilation.emitAsset(filename, new RawSource(moduleSource)); // Update the main manifest
|
554
|
+
|
555
|
+
if (!manifest.locales[locale]) {
|
556
|
+
manifest.locales[locale] = {};
|
557
|
+
}
|
558
|
+
manifest.locales[locale][cacheGroupName] = filename;
|
559
|
+
} // Update the cacheGroupToI18nMap
|
560
|
+
|
561
|
+
manifest.cacheGroupToI18nMap[cacheGroupName] = cacheGroupName;
|
562
|
+
} // Generate the meta manifest by converting Sets to Arrays
|
563
|
+
|
564
|
+
for (const [key, cacheGroupsSet] of Object.entries(keyToCacheGroupMap)) {
|
565
|
+
metaManifest.keyToCacheGroupMap[key] = Array.from(cacheGroupsSet);
|
566
|
+
} // Emit the main manifest file
|
567
|
+
|
568
|
+
const manifestSource = new RawSource(`window.i18n = window.i18n || {}; window.i18n.manifest = ${JSON.stringify(manifest, null, 2)};`);
|
569
|
+
const manifestFilename = 'i18n-chunks/manifest.js';
|
570
|
+
compilation.emitAsset(manifestFilename, manifestSource);
|
571
|
+
console.log(`Emitted i18n manifest: ${manifestFilename}`); // Emit the meta manifest file
|
572
|
+
|
573
|
+
const metaManifestSource = new RawSource(JSON.stringify(metaManifest, null, 2));
|
574
|
+
const metaManifestFilename = 'i18n-chunks/metaManifest.json';
|
575
|
+
compilation.emitAsset(metaManifestFilename, metaManifestSource);
|
576
|
+
console.log(`Emitted i18n meta manifest: ${metaManifestFilename}`);
|
577
|
+
}
|
578
|
+
module.exports = {
|
579
|
+
generateManifests
|
580
|
+
};
|