@zohodesk/client_build_tool 0.0.11-exp.15.4 → 0.0.11-exp.16.0
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/README.md +102 -0
- package/README_backup.md +100 -0
- package/docs/DYNAMIC_TEMPLATE_EXAMPLE.md +129 -0
- package/docs/I18N_SINGLE_FILE_MODE.md +126 -0
- package/example-single-file-config.js +59 -0
- package/lib/allCommandsConfigs.js +2 -7
- package/lib/commands/build/commandExecutor.js +1 -5
- package/lib/commands/build/config.js +2 -3
- package/lib/commands/build/optionsProcessor.js +2 -5
- package/lib/commands/build/preProcessor.js +0 -2
- package/lib/commands/buildEs/commandExecutor.js +0 -5
- package/lib/commands/buildEs/config.js +2 -3
- package/lib/commands/buildEs/preProcessor.js +0 -2
- package/lib/commands/buildLib/commandExecutor.js +0 -5
- package/lib/commands/buildLib/config.js +2 -3
- package/lib/commands/buildLib/preProcessor.js +0 -2
- package/lib/commands/mockserver/commandExecutor.js +2 -9
- package/lib/commands/mockserver/config.js +2 -3
- package/lib/commands/pre_process/commandExecutor.js +0 -2
- package/lib/commands/pre_process/config.js +2 -3
- package/lib/commands/start/commandExecutor.js +0 -2
- package/lib/commands/start/config.js +2 -3
- package/lib/commands/start/optionsProcessor.js +2 -4
- package/lib/commands/start/preProcessor.js +0 -2
- package/lib/commands/template/commandExecutor.js +0 -7
- package/lib/commands/template/config.js +2 -3
- package/lib/commands/version/commandExecutor.js +0 -3
- package/lib/commands/version/config.js +2 -3
- package/lib/commandsRouter.js +5 -21
- package/lib/index.js +0 -2
- package/lib/logger.js +0 -5
- package/lib/schemas/applyValuesToSchema/index.js +0 -8
- package/lib/schemas/applyValuesToSchema/isObject.js +0 -1
- package/lib/schemas/applyValuesToSchema/isValid.js +0 -2
- package/lib/schemas/cliArgsToObject.js +2 -6
- package/lib/schemas/defaultConfigValues.js +21 -12
- package/lib/schemas/defaultConfigValuesOnly.js +4 -7
- package/lib/schemas/deprecatedOptionsHandler.js +7 -16
- package/lib/schemas/getNpmVersion.js +0 -5
- package/lib/schemas/giveDefaultValue.js +0 -3
- package/lib/schemas/npmConfigToObject.js +2 -5
- package/lib/schemas/readOptions.js +10 -30
- package/lib/schemas/readOptionsForConfigFile.js +2 -12
- package/lib/shared/babel/addDefaultPlugins.js +0 -2
- package/lib/shared/babel/babelWebConfig.js +1 -10
- package/lib/shared/babel/babel_plugins/removeAttributesPlugin.js +0 -4
- package/lib/shared/babel/getBabelPlugin.js +2 -7
- package/lib/shared/babel/runBabelForJSFile.js +1 -4
- package/lib/shared/babel/runBabelForTsFile.js +1 -5
- package/lib/shared/bundler/webpack/common/decidePublicPath.js +0 -5
- package/lib/shared/bundler/webpack/common/libAlias.js +3 -3
- package/lib/shared/bundler/webpack/common/modeUtils.js +0 -5
- package/lib/shared/bundler/webpack/common/nameTemplates.js +11 -18
- package/lib/shared/bundler/webpack/common/resourceBasedPublicPath.js +2 -3
- package/lib/shared/bundler/webpack/configCustomLoaders.js +0 -1
- package/lib/shared/bundler/webpack/cssLoaders.js +0 -2
- package/lib/shared/bundler/webpack/custom_plugins/BundleIntegrityReport/index.js +1 -20
- package/lib/shared/bundler/webpack/custom_plugins/CdnChangePlugin/index.js +20 -25
- package/lib/shared/bundler/webpack/custom_plugins/CdnChangePlugin/webpackCustomJsUrlLoader.js +4 -9
- package/lib/shared/bundler/webpack/custom_plugins/CustomScriptLoadingPlugin.js +3 -23
- package/lib/shared/bundler/webpack/custom_plugins/EFCTemplatePlugin.js +8 -19
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nGroupRuntimeModule.js +2 -6
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexHtmlInjectorPlugin.js +81 -0
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin.js +135 -60
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/utils/i18nDataLoader.js +20 -26
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nFilesEmitPlugin.js +5 -26
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nKeysIdentifer.js +13 -16
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nRuntimeDealerPlugin.js +19 -53
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/LocaleChunkAssetsStore.js +2 -17
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/ModulesI18nKeysStore.js +0 -13
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/constants.js +11 -21
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/createHash.js +0 -4
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/getI18nLoadingRuntimeModule.js +4 -14
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/index.js +3 -13
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/iterateModulesInChunk.js +3 -12
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/optionsHandler.js +2 -7
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/pathCreator.js +0 -2
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/readI18nValues.js +2 -3
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/templateFileName.js +2 -4
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/templateHashHelpers.js +8 -13
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/collectI18nKeys.js +2 -14
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/getChunkModules.js +0 -1
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/hashUtils.js +1 -3
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/index.js +0 -4
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/propertiesUtils.js +5 -25
- package/lib/shared/bundler/webpack/custom_plugins/InitialHtmlPlugin.js +3 -10
- package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/addFilesNamesToManifestJson.js +1 -6
- package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/createInitialEntries.js +1 -6
- package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/createManifestJson.js +0 -6
- package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/findInitialFileNames.js +0 -1
- package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/index.js +0 -7
- package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/removeHashFromFileName.js +0 -1
- package/lib/shared/bundler/webpack/custom_plugins/ResourceHintsPlugin.js +13 -17
- package/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +6 -15
- package/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/RtlCssPlugin.js +4 -13
- package/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/replaceCssDirTemplate.js +4 -6
- package/lib/shared/bundler/webpack/custom_plugins/RuntimeResourceCleanup/index.js +0 -10
- package/lib/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/classHandling.js +0 -3
- package/lib/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/index.js +4 -20
- package/lib/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/selectorWeightPrefixAdder.js +10 -12
- package/lib/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/windowsModification.js +2 -3
- package/lib/shared/bundler/webpack/custom_plugins/ServiceWorkerPlugin.js +7 -20
- package/lib/shared/bundler/webpack/custom_plugins/ServiceWorkerPluginUtils.js +0 -1
- package/lib/shared/bundler/webpack/custom_plugins/SourceMapPlugin/index.js +7 -10
- package/lib/shared/bundler/webpack/custom_plugins/TPHashMappingPlugin/addHashToFilePath.js +1 -6
- package/lib/shared/bundler/webpack/custom_plugins/TPHashMappingPlugin/index.js +1 -16
- package/lib/shared/bundler/webpack/custom_plugins/UglifyCSSPlugin/index.js.js +4 -11
- package/lib/shared/bundler/webpack/custom_plugins/VariableConversionCollector/ErrorHandler.js +3 -10
- package/lib/shared/bundler/webpack/custom_plugins/VariableConversionCollector/index.js +27 -62
- package/lib/shared/bundler/webpack/custom_plugins/custom_attribute_plugin/index.js +3 -15
- package/lib/shared/bundler/webpack/custom_plugins/emitAsset.js +0 -1
- package/lib/shared/bundler/webpack/custom_plugins/getInitialAssetsFuncTemplate.js +2 -12
- package/lib/shared/bundler/webpack/custom_plugins/getInitialI18nAssetsArrayStr.js +2 -7
- package/lib/shared/bundler/webpack/defaultVendorPatternList.js +2 -6
- package/lib/shared/bundler/webpack/devtoolConfig.js +0 -1
- package/lib/shared/bundler/webpack/entryConfig.js +0 -4
- package/lib/shared/bundler/webpack/externals.js +0 -1
- package/lib/shared/bundler/webpack/getCSSLoaders.js +1 -6
- package/lib/shared/bundler/webpack/getFilenameFromModule.js +1 -5
- package/lib/shared/bundler/webpack/jsLoaders.js +6 -10
- package/lib/shared/bundler/webpack/loaderConfigs/assetLoaders.js +0 -2
- package/lib/shared/bundler/webpack/loaderConfigs/babelLoaderConfig.js +2 -3
- package/lib/shared/bundler/webpack/loaderConfigs/checkIsPatternsMatchFilename.js +3 -12
- package/lib/shared/bundler/webpack/loaderConfigs/configHtmlTemplateLoader.js +0 -1
- package/lib/shared/bundler/webpack/loaderConfigs/configPostCssLoader.js +2 -10
- package/lib/shared/bundler/webpack/loaderConfigs/configWebWorkerLoader.js +0 -2
- package/lib/shared/bundler/webpack/loaderConfigs/configsAssetsLoaders.js +0 -12
- package/lib/shared/bundler/webpack/loaderConfigs/cssClassNameGenerate.js +1 -15
- package/lib/shared/bundler/webpack/loaderConfigs/getCssLoaderOptions.js +1 -4
- package/lib/shared/bundler/webpack/loaderConfigs/i18nIdReplaceLoaderConfig.js +8 -16
- package/lib/shared/bundler/webpack/loaders/i18nIdReplaceLoader.js +22 -29
- package/lib/shared/bundler/webpack/loaders/miniCssFallBackLoader.js +2 -2
- package/lib/shared/bundler/webpack/loaders/workerLoader.js +8 -19
- package/lib/shared/bundler/webpack/optimizationConfig.js +5 -13
- package/lib/shared/bundler/webpack/outputConfig.js +1 -9
- package/lib/shared/bundler/webpack/pluginConfigs/configBundleAnalyzer.js +5 -9
- package/lib/shared/bundler/webpack/pluginConfigs/configBundleIntegrityReport.js +0 -5
- package/lib/shared/bundler/webpack/pluginConfigs/configCSSMinifierPlugin.js +4 -9
- package/lib/shared/bundler/webpack/pluginConfigs/configCdnChangePlugin.js +3 -8
- package/lib/shared/bundler/webpack/pluginConfigs/configCopyPublicFolders.js +1 -16
- package/lib/shared/bundler/webpack/pluginConfigs/configCustomAttributesPlugin.js +0 -4
- package/lib/shared/bundler/webpack/pluginConfigs/configCustomScriptLoadingStrategyPlugin.js +0 -16
- package/lib/shared/bundler/webpack/pluginConfigs/configEFCTemplatePlugin.js +0 -5
- package/lib/shared/bundler/webpack/pluginConfigs/configEnvVariables.js +0 -5
- package/lib/shared/bundler/webpack/pluginConfigs/configHtmlWebpackPlugin.js +2 -8
- package/lib/shared/bundler/webpack/pluginConfigs/configI18nIndexingPlugin.js +5 -9
- package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericHtmlInjector.js +19 -25
- package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericIndexPlugin.js +92 -0
- package/lib/shared/bundler/webpack/pluginConfigs/configI18nSplitPlugin.js +3 -9
- package/lib/shared/bundler/webpack/pluginConfigs/configIgnorePlugin.js +0 -2
- package/lib/shared/bundler/webpack/pluginConfigs/configManifestJsonPlugin.js +0 -7
- package/lib/shared/bundler/webpack/pluginConfigs/configMiniCSSExtractPlugin.js +3 -7
- package/lib/shared/bundler/webpack/pluginConfigs/configProgressPlugin.js +1 -5
- package/lib/shared/bundler/webpack/pluginConfigs/configResourceHintsPlugin.js +1 -4
- package/lib/shared/bundler/webpack/pluginConfigs/configRtlCssPlugin.js +0 -4
- package/lib/shared/bundler/webpack/pluginConfigs/configRuntimeResourceCleanup.js +3 -8
- package/lib/shared/bundler/webpack/pluginConfigs/configSelectorWeightPlugin.js +1 -6
- package/lib/shared/bundler/webpack/pluginConfigs/configServiceWorkerPlugin.js +3 -8
- package/lib/shared/bundler/webpack/pluginConfigs/configSourceMapPlugin.js +0 -4
- package/lib/shared/bundler/webpack/pluginConfigs/configTPHashMappingPlugin.js +1 -8
- package/lib/shared/bundler/webpack/pluginConfigs/configVariableConversionPlugin.js +1 -6
- package/lib/shared/bundler/webpack/plugins.js +3 -30
- package/lib/shared/bundler/webpack/resolvers.js +3 -17
- package/lib/shared/bundler/webpack/splitChunksConfig.js +2 -15
- package/lib/shared/bundler/webpack/statsConfig.js +2 -5
- package/lib/shared/bundler/webpack/tsLoaders.js +2 -4
- package/lib/shared/bundler/webpack/utils/index.js +1 -12
- package/lib/shared/bundler/webpack/utils/object-manipulation.js +2 -16
- package/lib/shared/bundler/webpack/utils/updateArrayWithDefault.js +0 -7
- package/lib/shared/bundler/webpack/webpackBuild.js +1 -8
- package/lib/shared/bundler/webpack/webpackConfig.js +0 -17
- package/lib/shared/commands-utils/doBasicRequirementCheck.js +0 -3
- package/lib/shared/commands-utils/getCliPath.js +5 -9
- package/lib/shared/commands-utils/index.js +0 -3
- package/lib/shared/commands-utils/log.js +0 -2
- package/lib/shared/commands-utils/readArgsFormCommandLine.js +0 -1
- package/lib/shared/commands-utils/readOptionFormCommandLine.js +0 -1
- package/lib/shared/commands-utils/spawnSyncIO.js +5 -13
- package/lib/shared/constants.js +9 -29
- package/lib/shared/fileUtils/copyFile.js +1 -8
- package/lib/shared/fileUtils/directoryIterator.js +0 -4
- package/lib/shared/fileUtils/watchRun.js +3 -24
- package/lib/shared/postcss/custom_postcss_plugins/EmptyPlugin.js +1 -6
- package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/constants.js +2 -3
- package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/handleIgnores.js +6 -13
- package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/index.js +6 -26
- package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/insertBefore.js +6 -9
- package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/isPreviouslyProcessed.js +0 -3
- package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/replaceUtils.js +2 -7
- package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/separateHoveredSelectorAndNormalSelector.js +0 -2
- package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/specialCases.js +4 -9
- package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/typeCheckUtils.js +0 -10
- package/lib/shared/postcss/custom_postcss_plugins/RTLSplitPlugin.js +16 -29
- package/lib/shared/postcss/custom_postcss_plugins/SelectorReplace.js +0 -17
- package/lib/shared/postcss/custom_postcss_plugins/ValueReplacer.js +4 -9
- package/lib/shared/postcss/custom_postcss_plugins/VariableModificationPlugin/index.js +27 -63
- package/lib/shared/postcss/filterPluginsAllowedForSpecficFile.js +5 -13
- package/lib/shared/postcss/getAllowedPostCssPlugins.js +0 -3
- package/lib/shared/postcss/getSpecificPostCssPlugin.js +7 -17
- package/lib/shared/postcss/runPostCssForCssFile.js +1 -9
- package/lib/shared/pre_process/runPreProcess.js +0 -11
- package/lib/shared/server/configWebpackDevMiddleware.js +1 -8
- package/lib/shared/server/corsHandling.js +2 -6
- package/lib/shared/server/getIp.js +1 -7
- package/lib/shared/server/getServerURL.js +0 -6
- package/lib/shared/server/httpsOptions.js +0 -11
- package/lib/shared/server/initExpressApp.js +1 -4
- package/lib/shared/server/initialHTMLHandling.js +7 -16
- package/lib/shared/server/mockApiHandler.js +8 -16
- package/lib/shared/server/mockServer.js +0 -7
- package/lib/shared/server/serveContextFiles.js +1 -5
- package/lib/shared/server/serverBywebpackDevMiddleware.js +4 -9
- package/lib/shared/server/startHttpServer.js +0 -3
- package/lib/shared/server/startHttpsServer.js +1 -9
- package/lib/shared/server/unwanted/addHttp2Server.js +2 -7
- package/lib/shared/server/unwanted/configWebpackDevMiddleware.js +1 -8
- package/lib/shared/server/unwanted/mockApiSupport.js +0 -2
- package/lib/shared/server/unwanted/websocketMockSetup.js +1 -7
- package/lib/shared/server/urlConcat.js +3 -8
- package/lib/shared/utils/requireLocalOrGlobal.js +10 -25
- package/lib/shared/utils/versionPrint.js +1 -6
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/packages/client_build_tool/test-i18n-config.js +22 -0
|
@@ -4,13 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _utils = require("./utils");
|
|
9
|
-
|
|
10
8
|
var _LocaleChunkAssetsStore = require("./LocaleChunkAssetsStore");
|
|
11
|
-
|
|
12
9
|
/* eslint-disable max-classes-per-file */
|
|
10
|
+
|
|
13
11
|
const pluginName = 'I18nKeysIdentifier';
|
|
12
|
+
|
|
14
13
|
/**
|
|
15
14
|
* this plugin search the i18 keys and make it as I18nDependency.
|
|
16
15
|
* how it works?
|
|
@@ -20,7 +19,6 @@ const pluginName = 'I18nKeysIdentifier';
|
|
|
20
19
|
* after the walk of AST we get some I18n keys
|
|
21
20
|
* then we make it as I18nDependency.
|
|
22
21
|
*/
|
|
23
|
-
|
|
24
22
|
class I18nKeysIdentifer {
|
|
25
23
|
constructor({
|
|
26
24
|
jsResourceI18nKeys
|
|
@@ -28,9 +26,9 @@ class I18nKeysIdentifer {
|
|
|
28
26
|
this.jsResourceI18nKeys = jsResourceI18nKeys;
|
|
29
27
|
this.store = new _LocaleChunkAssetsStore.LocaleChunkAssetsStore();
|
|
30
28
|
}
|
|
31
|
-
|
|
32
29
|
apply(compiler) {
|
|
33
30
|
// const { splitChunks } = compiler.options.optimization;
|
|
31
|
+
|
|
34
32
|
// if (splitChunks) {
|
|
35
33
|
// if (splitChunks.defaultSizeTypes.includes('...')) {
|
|
36
34
|
// splitChunks.defaultSizeTypes.push(MODULE_TYPE);
|
|
@@ -46,31 +44,30 @@ class I18nKeysIdentifer {
|
|
|
46
44
|
parser.hooks.program.tap(pluginName, (ast, comments) => {
|
|
47
45
|
const {
|
|
48
46
|
module
|
|
49
|
-
} = parser.state;
|
|
50
|
-
|
|
47
|
+
} = parser.state;
|
|
48
|
+
//
|
|
51
49
|
if (!(module && /\.jsx?$/.test(module.resource))) {
|
|
52
50
|
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
}
|
|
52
|
+
// i18n grep proper contract regex
|
|
56
53
|
let i18nKeys = (0, _utils.collectI18nKeysfromAST)(ast, this.jsResourceI18nKeys);
|
|
57
|
-
i18nKeys = i18nKeys.concat(
|
|
54
|
+
i18nKeys = i18nKeys.concat(
|
|
55
|
+
// i18n grep proper contract regex
|
|
58
56
|
(0, _utils.collectI18nKeysfromComments)(comments, this.jsResourceI18nKeys));
|
|
59
|
-
|
|
60
57
|
if (i18nKeys.length) {
|
|
61
58
|
// console.log('i18nKeys.length', module.resource, i18nKeys);
|
|
62
59
|
this.store.updateModuleI18nKeys(module.resource, i18nKeys);
|
|
63
60
|
}
|
|
64
61
|
});
|
|
65
|
-
};
|
|
66
|
-
// const factory = params.normalModuleFactory;
|
|
62
|
+
};
|
|
67
63
|
|
|
64
|
+
// this below hook was tapped for collect I18n Key from files and add as Dependency
|
|
65
|
+
|
|
66
|
+
// const factory = params.normalModuleFactory;
|
|
68
67
|
|
|
69
68
|
factory.hooks.parser.for('javascript/auto').tap(pluginName, handler);
|
|
70
69
|
factory.hooks.parser.for('javascript/dynamic').tap(pluginName, handler);
|
|
71
70
|
});
|
|
72
71
|
}
|
|
73
|
-
|
|
74
72
|
}
|
|
75
|
-
|
|
76
73
|
exports.default = I18nKeysIdentifer;
|
package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nRuntimeDealerPlugin.js
CHANGED
|
@@ -4,56 +4,40 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.I18nRuntimeDealerPlugin = void 0;
|
|
7
|
-
|
|
8
7
|
var _webpack = require("webpack");
|
|
9
|
-
|
|
10
8
|
var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));
|
|
11
|
-
|
|
12
9
|
var _constants = require("./constants");
|
|
13
|
-
|
|
14
10
|
var _getI18nLoadingRuntimeModule = require("./getI18nLoadingRuntimeModule");
|
|
15
|
-
|
|
16
11
|
var _templateFileName = require("./templateFileName");
|
|
17
|
-
|
|
18
12
|
var _hashUtils = require("./utils/hashUtils");
|
|
19
|
-
|
|
20
13
|
var _urlConcat = require("../../../../server/urlConcat");
|
|
21
|
-
|
|
22
14
|
var _I18nFilesEmitPlugin = require("./I18nFilesEmitPlugin");
|
|
23
|
-
|
|
24
15
|
var _LocaleChunkAssetsStore = require("./LocaleChunkAssetsStore");
|
|
25
|
-
|
|
26
16
|
var _logger = require("../../../../../logger");
|
|
27
|
-
|
|
28
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
-
|
|
17
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
30
18
|
const {
|
|
31
19
|
RawSource
|
|
32
20
|
} = _webpack.sources;
|
|
33
|
-
const pluginName = 'I18nRuntimeDealerPlugin';
|
|
21
|
+
const pluginName = 'I18nRuntimeDealerPlugin';
|
|
34
22
|
|
|
23
|
+
// I18nExtractPlugin.loader = require.resolve('./loader');
|
|
35
24
|
class I18nRuntimeDealerPlugin {
|
|
36
25
|
constructor(options) {
|
|
37
26
|
this.options = options;
|
|
38
27
|
}
|
|
39
|
-
|
|
40
28
|
apply(compiler) {
|
|
41
29
|
compiler.hooks.thisCompilation.tap(pluginName, compilation => {
|
|
42
30
|
// Get store for cache
|
|
43
31
|
this.store = (0, _LocaleChunkAssetsStore.getLocaleChunkAssetsStore)(compilation);
|
|
44
|
-
|
|
45
32
|
if (!this.options.runtime) {
|
|
46
33
|
return;
|
|
47
34
|
}
|
|
48
|
-
|
|
49
35
|
this.createI18nDownloadCodeInRuntimeFile(compilation);
|
|
50
36
|
this.addI18nIntoInitialHtml(compilation);
|
|
51
37
|
});
|
|
52
38
|
}
|
|
53
|
-
|
|
54
39
|
addI18nIntoInitialHtml(compilation) {
|
|
55
40
|
const i18nStore = this.store;
|
|
56
|
-
|
|
57
41
|
_htmlWebpackPlugin.default.getHooks(compilation).beforeAssetTagGeneration.tap(pluginName, hookOptions => {
|
|
58
42
|
const {
|
|
59
43
|
assets
|
|
@@ -63,8 +47,8 @@ class I18nRuntimeDealerPlugin {
|
|
|
63
47
|
filename,
|
|
64
48
|
publicPath = '',
|
|
65
49
|
mainChunkName
|
|
66
|
-
} = this.options;
|
|
67
|
-
|
|
50
|
+
} = this.options;
|
|
51
|
+
// const dummyContent = '// dummy comment';
|
|
68
52
|
const dummyContentHash = 'dummy0content0hashes';
|
|
69
53
|
const entryPoint = compilation.entrypoints.get(mainChunkName);
|
|
70
54
|
const initialChunks = Array.from(entryPoint.chunks).filter(c => c.canBeInitial() && c.id !== c.runtime);
|
|
@@ -79,18 +63,17 @@ class I18nRuntimeDealerPlugin {
|
|
|
79
63
|
// So Dummy hash was being used it will not work just skip warnings
|
|
80
64
|
contentHash: dummyContentHash
|
|
81
65
|
});
|
|
82
|
-
|
|
83
66
|
return (0, _urlConcat.urlConcat)(publicPath, data.filename);
|
|
84
67
|
});
|
|
85
68
|
const allJSAssets = [...initialI18nAssets, ...assets.js].map(url => url.replaceAll('[locale]', templateLabel).replaceAll('%5Blocale%5D', templateLabel));
|
|
86
69
|
return {
|
|
87
|
-
assets: {
|
|
70
|
+
assets: {
|
|
71
|
+
...assets,
|
|
88
72
|
js: allJSAssets
|
|
89
73
|
}
|
|
90
74
|
};
|
|
91
75
|
});
|
|
92
76
|
}
|
|
93
|
-
|
|
94
77
|
createI18nDownloadCodeInRuntimeFile(compilation) {
|
|
95
78
|
const {
|
|
96
79
|
chunkFilename,
|
|
@@ -98,14 +81,11 @@ class I18nRuntimeDealerPlugin {
|
|
|
98
81
|
localeVarName
|
|
99
82
|
} = this.options;
|
|
100
83
|
const chunkFilenameHasContentHash = (0, _hashUtils.hasContentHash)(chunkFilename);
|
|
101
|
-
|
|
102
84
|
const getI18nChunks = mainChunk => this.filterI18nUsedChunks(mainChunk.getAllAsyncChunks());
|
|
103
|
-
|
|
104
85
|
const I18nLoadingRuntimeModule = (0, _getI18nLoadingRuntimeModule.getI18nLoadingRuntimeModule)({
|
|
105
86
|
getI18nChunks
|
|
106
87
|
});
|
|
107
88
|
const enabledChunks = new WeakSet();
|
|
108
|
-
|
|
109
89
|
const chunkFilenameUrlGenerator = (i18nChunks, locale) => (0, _templateFileName.templateFileName)({
|
|
110
90
|
compilation,
|
|
111
91
|
localeVarName,
|
|
@@ -113,25 +93,20 @@ class I18nRuntimeDealerPlugin {
|
|
|
113
93
|
contentHashes: this.getContentHashes(locale),
|
|
114
94
|
chunks: i18nChunks
|
|
115
95
|
});
|
|
116
|
-
|
|
117
96
|
const prefixFunc = () => _constants.I18N_CHUNK_NAME_GENERATION_SEGMENT;
|
|
118
|
-
|
|
119
97
|
const handler = (entryRuntimeChunk, set) => {
|
|
120
98
|
if (enabledChunks.has(entryRuntimeChunk)) {
|
|
121
99
|
return;
|
|
122
100
|
}
|
|
123
|
-
|
|
124
101
|
enabledChunks.add(entryRuntimeChunk);
|
|
125
102
|
const {
|
|
126
103
|
chunkFilename,
|
|
127
104
|
// filename: initialFilename,
|
|
128
105
|
runtimeOptions
|
|
129
106
|
} = this.options;
|
|
130
|
-
|
|
131
107
|
if (typeof chunkFilename === 'string' && /\[(full)?hash(:\d+)?\]/.test(chunkFilename)) {
|
|
132
108
|
set.add(_webpack.RuntimeGlobals.getFullHash);
|
|
133
109
|
}
|
|
134
|
-
|
|
135
110
|
set.add(_webpack.RuntimeGlobals.publicPath);
|
|
136
111
|
compilation.addRuntimeModule(entryRuntimeChunk, new I18nLoadingRuntimeModule(set, {
|
|
137
112
|
prefixFunc: chunkFilenameHasContentHash ? prefixFunc : chunkFilenameUrlGenerator,
|
|
@@ -139,18 +114,15 @@ class I18nRuntimeDealerPlugin {
|
|
|
139
114
|
chunkFilename
|
|
140
115
|
}));
|
|
141
116
|
};
|
|
142
|
-
|
|
143
117
|
compilation.hooks.runtimeRequirementInTree.for(_webpack.RuntimeGlobals.ensureChunkHandlers).tap(pluginName, handler);
|
|
144
|
-
|
|
145
118
|
if (chunkFilenameHasContentHash) {
|
|
146
119
|
compilation.hooks.processAssets.tap({
|
|
147
120
|
name: pluginName,
|
|
148
|
-
stage: _webpack.Compilation.PROCESS_ASSETS_STAGE_DERIVED
|
|
149
|
-
|
|
121
|
+
stage: _webpack.Compilation.PROCESS_ASSETS_STAGE_DERIVED
|
|
122
|
+
// additionalAssets: true
|
|
150
123
|
}, assets => {
|
|
151
124
|
// eslint-disable-next-line no-underscore-dangle
|
|
152
125
|
const entries = compilation._getChunkGraphEntries();
|
|
153
|
-
|
|
154
126
|
function createRuntimeFilePerLocale({
|
|
155
127
|
locale,
|
|
156
128
|
runtimeFileName,
|
|
@@ -161,9 +133,9 @@ class I18nRuntimeDealerPlugin {
|
|
|
161
133
|
const replaceText = chunkFilenameUrlGenerator(i18nChunks, locale);
|
|
162
134
|
const replacedStr = runtimeFileSourceStr.replace(_constants.I18N_CHUNK_NAME_GENERATION_SEGMENT, replaceText);
|
|
163
135
|
compilation.emitAsset(newRuntimeName, new RawSource(replacedStr));
|
|
164
|
-
}
|
|
165
|
-
|
|
136
|
+
}
|
|
166
137
|
|
|
138
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
167
139
|
for (const entryChunk of entries) {
|
|
168
140
|
const i18nChunks = getI18nChunks(entryChunk);
|
|
169
141
|
const runtimeFileName = [...entryChunk.files][0];
|
|
@@ -174,22 +146,21 @@ class I18nRuntimeDealerPlugin {
|
|
|
174
146
|
runtimeFileName,
|
|
175
147
|
runtimeFileSourceStr,
|
|
176
148
|
i18nChunks
|
|
177
|
-
}));
|
|
149
|
+
}));
|
|
150
|
+
// NOTE: we don't delete, Because of HTML plugin needs to add runtime file in html and efc
|
|
178
151
|
// compilation.deleteAsset(runtimeFileName);
|
|
179
152
|
}
|
|
180
153
|
});
|
|
181
154
|
compilation.hooks.processAssets.tap({
|
|
182
155
|
name: pluginName,
|
|
183
|
-
stage: _webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
|
|
184
|
-
|
|
156
|
+
stage: _webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
|
|
157
|
+
// additionalAssets: true
|
|
185
158
|
}, () => {
|
|
186
159
|
// eslint-disable-next-line no-underscore-dangle
|
|
187
|
-
const entries = compilation._getChunkGraphEntries();
|
|
188
|
-
|
|
189
|
-
|
|
160
|
+
const entries = compilation._getChunkGraphEntries();
|
|
161
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
190
162
|
for (const entryChunk of entries) {
|
|
191
163
|
const runtimeFileName = [...entryChunk.files][0] || '';
|
|
192
|
-
|
|
193
164
|
if (runtimeFileName.includes('runtime') && runtimeFileName.includes('[locale]')) {
|
|
194
165
|
(0, _logger.verboseLogger)('deleteAsset', runtimeFileName);
|
|
195
166
|
compilation.deleteAsset(runtimeFileName);
|
|
@@ -198,26 +169,21 @@ class I18nRuntimeDealerPlugin {
|
|
|
198
169
|
});
|
|
199
170
|
}
|
|
200
171
|
}
|
|
201
|
-
|
|
202
172
|
filterI18nUsedChunks(chunks) {
|
|
203
173
|
const i18nStore = this.store;
|
|
204
174
|
return Array.from(chunks).filter(c => i18nStore.isChunkHasI18n(c.id));
|
|
205
175
|
}
|
|
206
|
-
|
|
207
176
|
getContentHashes(locale) {
|
|
208
177
|
const i18nStore = this.store;
|
|
209
178
|
const contentHashes = {};
|
|
210
179
|
i18nStore.forEachChunkId(chunkId => {
|
|
211
180
|
const contentHash = i18nStore.getContentHash(chunkId, locale);
|
|
212
|
-
|
|
213
181
|
if (contentHash) {
|
|
214
182
|
contentHashes[chunkId] = contentHash;
|
|
215
183
|
}
|
|
216
|
-
});
|
|
217
|
-
|
|
184
|
+
});
|
|
185
|
+
// console.log({ contentHashes });
|
|
218
186
|
return contentHashes;
|
|
219
187
|
}
|
|
220
|
-
|
|
221
188
|
}
|
|
222
|
-
|
|
223
189
|
exports.I18nRuntimeDealerPlugin = I18nRuntimeDealerPlugin;
|
|
@@ -6,68 +6,53 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.LocaleChunkAssetsStore = void 0;
|
|
7
7
|
exports.getLocaleChunkAssetsStore = getLocaleChunkAssetsStore;
|
|
8
8
|
exports.setLocaleChunkAssetsStore = setLocaleChunkAssetsStore;
|
|
9
|
-
|
|
10
9
|
var _ModulesI18nKeysStore = require("./ModulesI18nKeysStore");
|
|
11
|
-
|
|
12
10
|
class LocaleChunkAssetsStore extends _ModulesI18nKeysStore.ModulesI18nKeysStore {
|
|
13
11
|
constructor() {
|
|
14
12
|
super();
|
|
15
13
|
this.data = {};
|
|
16
14
|
}
|
|
17
|
-
|
|
18
15
|
clear() {
|
|
19
16
|
this.data = {};
|
|
20
17
|
}
|
|
21
|
-
|
|
22
18
|
storeData(chunkId, locale, data) {
|
|
23
19
|
if (!this.data[chunkId]) {
|
|
24
20
|
this.data[chunkId] = {};
|
|
25
21
|
}
|
|
26
|
-
|
|
27
22
|
const chunkBasedData = this.data[chunkId];
|
|
28
|
-
chunkBasedData[locale] = {
|
|
23
|
+
chunkBasedData[locale] = {
|
|
24
|
+
...(chunkBasedData[locale] || {}),
|
|
29
25
|
...data
|
|
30
26
|
};
|
|
31
27
|
}
|
|
32
|
-
|
|
33
28
|
getChunkIdsWhichHasI18n() {
|
|
34
29
|
return Object.keys(this.data);
|
|
35
30
|
}
|
|
36
|
-
|
|
37
31
|
forEachChunkId(cb) {
|
|
38
32
|
// Object.keys(localeChunkAssestMap).forEach
|
|
39
33
|
this.getChunkIdsWhichHasI18n().forEach(cb);
|
|
40
34
|
}
|
|
41
|
-
|
|
42
35
|
isChunkHasI18n(chunkId) {
|
|
43
36
|
if (typeof chunkId === 'object') {
|
|
44
37
|
return super.isChunkHasI18n(chunkId);
|
|
45
38
|
}
|
|
46
|
-
|
|
47
39
|
return !!this.data[chunkId];
|
|
48
40
|
}
|
|
49
|
-
|
|
50
41
|
getDate(chunkId, locale) {
|
|
51
42
|
return this.data[chunkId]?.[locale];
|
|
52
43
|
}
|
|
53
|
-
|
|
54
44
|
getContent(chunkId, locale) {
|
|
55
45
|
return this.data[chunkId]?.[locale]?.content;
|
|
56
46
|
}
|
|
57
|
-
|
|
58
47
|
getContentHash(chunkId, locale) {
|
|
59
48
|
return this.data[chunkId]?.[locale]?.contentHash;
|
|
60
49
|
}
|
|
61
|
-
|
|
62
50
|
}
|
|
63
|
-
|
|
64
51
|
exports.LocaleChunkAssetsStore = LocaleChunkAssetsStore;
|
|
65
52
|
const storeCache = new WeakMap();
|
|
66
|
-
|
|
67
53
|
function getLocaleChunkAssetsStore(compilation) {
|
|
68
54
|
return storeCache.get(compilation);
|
|
69
55
|
}
|
|
70
|
-
|
|
71
56
|
function setLocaleChunkAssetsStore(compilation, store) {
|
|
72
57
|
return storeCache.set(compilation, store);
|
|
73
58
|
}
|
|
@@ -4,27 +4,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.ModulesI18nKeysStore = void 0;
|
|
7
|
-
|
|
8
7
|
var _iterateModulesInChunk = require("./iterateModulesInChunk");
|
|
9
|
-
|
|
10
8
|
class ModulesI18nKeysStore {
|
|
11
9
|
constructor() {
|
|
12
10
|
this.modulesI18nKeysMap = {};
|
|
13
11
|
this.compilation = null;
|
|
14
12
|
}
|
|
15
|
-
|
|
16
13
|
updateCompilation(compilation) {
|
|
17
14
|
this.compilation = compilation;
|
|
18
15
|
}
|
|
19
|
-
|
|
20
16
|
updateModuleI18nKeys(resource, i18nKeys) {
|
|
21
17
|
this.modulesI18nKeysMap[resource] = i18nKeys;
|
|
22
18
|
}
|
|
23
|
-
|
|
24
19
|
getModuleI18nKeys(resource) {
|
|
25
20
|
return this.modulesI18nKeysMap[resource];
|
|
26
21
|
}
|
|
27
|
-
|
|
28
22
|
isChunkHasI18n(chunk) {
|
|
29
23
|
const {
|
|
30
24
|
modulesI18nKeysMap,
|
|
@@ -40,7 +34,6 @@ class ModulesI18nKeysStore {
|
|
|
40
34
|
}) => {
|
|
41
35
|
if (mod.resource) {
|
|
42
36
|
const keys = modulesI18nKeysMap[mod.resource];
|
|
43
|
-
|
|
44
37
|
if (keys && keys.length > 0) {
|
|
45
38
|
hasModuleI18n = true;
|
|
46
39
|
stopLoop();
|
|
@@ -50,17 +43,14 @@ class ModulesI18nKeysStore {
|
|
|
50
43
|
});
|
|
51
44
|
return hasModuleI18n;
|
|
52
45
|
}
|
|
53
|
-
|
|
54
46
|
getI18nKeysForChunk(chunk) {
|
|
55
47
|
const {
|
|
56
48
|
modulesI18nKeysMap,
|
|
57
49
|
compilation
|
|
58
50
|
} = this;
|
|
59
51
|
const i18nKeysMap = {};
|
|
60
|
-
|
|
61
52
|
function updateI18nKeys(mod) {
|
|
62
53
|
const keys = modulesI18nKeysMap[mod.resource];
|
|
63
|
-
|
|
64
54
|
if (keys) {
|
|
65
55
|
// eslint-disable-next-line no-restricted-syntax
|
|
66
56
|
for (const key of keys) {
|
|
@@ -68,7 +58,6 @@ class ModulesI18nKeysStore {
|
|
|
68
58
|
}
|
|
69
59
|
}
|
|
70
60
|
}
|
|
71
|
-
|
|
72
61
|
(0, _iterateModulesInChunk.iterateModulesInChunk)({
|
|
73
62
|
chunk,
|
|
74
63
|
compilation,
|
|
@@ -82,7 +71,5 @@ class ModulesI18nKeysStore {
|
|
|
82
71
|
});
|
|
83
72
|
return Object.keys(i18nKeysMap);
|
|
84
73
|
}
|
|
85
|
-
|
|
86
74
|
}
|
|
87
|
-
|
|
88
75
|
exports.ModulesI18nKeysStore = ModulesI18nKeysStore;
|
|
@@ -4,26 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.TYPES = exports.SINGLE_DOT_PATH_SEGMENT = exports.MODULE_TYPE = exports.I18N_CHUNK_NAME_GENERATION_SEGMENT = exports.DEFAULT_FILENAME = exports.DEFAULT_CHUNK_FILENAME = exports.CODE_GENERATION_RESULT = exports.BASE_URI = exports.AUTO_PUBLIC_PATH = exports.ABSOLUTE_PUBLIC_PATH = void 0;
|
|
7
|
-
const MODULE_TYPE = 'i18n/mini-extract';
|
|
8
|
-
exports.
|
|
9
|
-
const
|
|
10
|
-
exports.
|
|
11
|
-
const
|
|
12
|
-
exports.
|
|
13
|
-
const
|
|
14
|
-
exports.
|
|
15
|
-
const
|
|
16
|
-
exports.
|
|
17
|
-
const I18N_CHUNK_NAME_GENERATION_SEGMENT = '__mini_i18n_extract_plugin_i18n_chunk_name_generation_segment__';
|
|
18
|
-
exports.I18N_CHUNK_NAME_GENERATION_SEGMENT = I18N_CHUNK_NAME_GENERATION_SEGMENT;
|
|
19
|
-
const DEFAULT_FILENAME = 'i18n-chunks/[locale]/[name].[contenthash].i18n.js';
|
|
20
|
-
exports.DEFAULT_FILENAME = DEFAULT_FILENAME;
|
|
21
|
-
const DEFAULT_CHUNK_FILENAME = 'i18n-chunks/[locale]/[id].[contenthash].i18n.js';
|
|
22
|
-
exports.DEFAULT_CHUNK_FILENAME = DEFAULT_CHUNK_FILENAME;
|
|
23
|
-
const TYPES = new Set([MODULE_TYPE]);
|
|
24
|
-
exports.TYPES = TYPES;
|
|
25
|
-
const CODE_GENERATION_RESULT = {
|
|
7
|
+
const MODULE_TYPE = exports.MODULE_TYPE = 'i18n/mini-extract';
|
|
8
|
+
const AUTO_PUBLIC_PATH = exports.AUTO_PUBLIC_PATH = '__mini_i18n_extract_plugin_public_path_auto__';
|
|
9
|
+
const ABSOLUTE_PUBLIC_PATH = exports.ABSOLUTE_PUBLIC_PATH = 'webpack:///mini-i18n-extract-plugin/';
|
|
10
|
+
const BASE_URI = exports.BASE_URI = 'webpack://';
|
|
11
|
+
const SINGLE_DOT_PATH_SEGMENT = exports.SINGLE_DOT_PATH_SEGMENT = '__mini_i18n_extract_plugin_single_dot_path_segment__';
|
|
12
|
+
const I18N_CHUNK_NAME_GENERATION_SEGMENT = exports.I18N_CHUNK_NAME_GENERATION_SEGMENT = '__mini_i18n_extract_plugin_i18n_chunk_name_generation_segment__';
|
|
13
|
+
const DEFAULT_FILENAME = exports.DEFAULT_FILENAME = 'i18n-chunks/[locale]/[name].[contenthash].i18n.js';
|
|
14
|
+
const DEFAULT_CHUNK_FILENAME = exports.DEFAULT_CHUNK_FILENAME = 'i18n-chunks/[locale]/[id].[contenthash].i18n.js';
|
|
15
|
+
const TYPES = exports.TYPES = new Set([MODULE_TYPE]);
|
|
16
|
+
const CODE_GENERATION_RESULT = exports.CODE_GENERATION_RESULT = {
|
|
26
17
|
sources: new Map(),
|
|
27
18
|
runtimeRequirements: new Set()
|
|
28
|
-
};
|
|
29
|
-
exports.CODE_GENERATION_RESULT = CODE_GENERATION_RESULT;
|
|
19
|
+
};
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createHash = createHash;
|
|
7
|
-
|
|
8
7
|
var _webpack = require("webpack");
|
|
9
|
-
|
|
10
8
|
function createHash({
|
|
11
9
|
outputOptions,
|
|
12
10
|
content
|
|
@@ -16,9 +14,7 @@ function createHash({
|
|
|
16
14
|
hashDigest,
|
|
17
15
|
hashDigestLength
|
|
18
16
|
} = outputOptions;
|
|
19
|
-
|
|
20
17
|
const hash = _webpack.util.createHash(hashFunction);
|
|
21
|
-
|
|
22
18
|
hash.update(content);
|
|
23
19
|
return hash.digest(hashDigest).substring(0, hashDigestLength);
|
|
24
20
|
}
|
package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/getI18nLoadingRuntimeModule.js
CHANGED
|
@@ -4,20 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getI18nLoadingRuntimeModule = getI18nLoadingRuntimeModule;
|
|
7
|
-
|
|
8
7
|
var _webpack = require("webpack");
|
|
9
|
-
|
|
10
8
|
/* eslint-disable no-restricted-syntax */
|
|
11
9
|
const getChunksMapObject = i18nChunks => {
|
|
12
10
|
const obj = {};
|
|
13
|
-
|
|
14
11
|
for (const chunk of i18nChunks) {
|
|
15
12
|
obj[chunk.id] = 1;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
return obj;
|
|
19
15
|
};
|
|
20
|
-
|
|
21
16
|
function getI18nLoadingRuntimeModule({
|
|
22
17
|
getI18nChunks
|
|
23
18
|
}) {
|
|
@@ -31,7 +26,6 @@ function getI18nLoadingRuntimeModule({
|
|
|
31
26
|
this.prefixFunc = prefixFunc;
|
|
32
27
|
this.runtimeOptions = runtimeOptions;
|
|
33
28
|
}
|
|
34
|
-
|
|
35
29
|
generate() {
|
|
36
30
|
const {
|
|
37
31
|
chunk,
|
|
@@ -44,17 +38,16 @@ function getI18nLoadingRuntimeModule({
|
|
|
44
38
|
outputOptions: {
|
|
45
39
|
crossOriginLoading
|
|
46
40
|
}
|
|
47
|
-
} = compilation;
|
|
41
|
+
} = compilation;
|
|
42
|
+
// const i18nChunks = getI18nChunks(chunk, compilation);
|
|
43
|
+
|
|
48
44
|
// REASON: we do it in here is in dev mode thing may change
|
|
49
45
|
// const i18nChunks = getI18nChunks(entryRuntimeChunk);
|
|
50
|
-
|
|
51
46
|
const i18nChunks = getI18nChunks(chunk);
|
|
52
47
|
const withLoading = runtimeRequirements.has(_webpack.RuntimeGlobals.ensureChunkHandlers) && i18nChunks.length > 0;
|
|
53
|
-
|
|
54
48
|
if (!withLoading) {
|
|
55
49
|
return '// no i18n chunks loading';
|
|
56
50
|
}
|
|
57
|
-
|
|
58
51
|
const chunkMap = getChunksMapObject(i18nChunks);
|
|
59
52
|
const {
|
|
60
53
|
attributes,
|
|
@@ -65,12 +58,9 @@ function getI18nLoadingRuntimeModule({
|
|
|
65
58
|
return _webpack.Template.asString([`${prefixFunc(i18nChunks)}`, `var createI18nScriptTag = ${runtimeTemplate.basicFunction('chunkId, fullsrc, resolve, reject', ['var scriptTag = document.createElement("script");', attributes ? _webpack.Template.asString(Object.entries(attributes).map(entry => {
|
|
66
59
|
const [key, value] = entry;
|
|
67
60
|
return `scriptTag.setAttribute(${JSON.stringify(key)}, ${JSON.stringify(value)});`;
|
|
68
|
-
})) : '', '__webpack_require__.nc && scriptTag.setAttribute("nonce", __webpack_require__.nc)', scriptType ? `scriptTag.type = ${JSON.stringify(scriptType)};` : '', `var onScriptComplete = ${runtimeTemplate.basicFunction('event', ['// avoid mem leaks.', 'scriptTag.onerror = scriptTag.onload = null;', 'if (event.type === \'load\') {', _webpack.Template.indent(['resolve();']), '} else {', _webpack.Template.indent(['var errorType = event && (event.type === \'load\' ? \'missing\' : event.type);', 'var realSrc = event && event.target && event.target.src || fullsrc;', 'var err = new Error("Loading I18N chunk " + chunkId + " failed.\\n(" + realSrc + ")");', 'err.code = "I18N_CHUNK_LOAD_FAILED";', 'err.type = errorType;', 'err.request = realSrc;', 'scriptTag.parentNode.removeChild(scriptTag)', 'reject(err);']), '}'])}`, 'scriptTag.onerror = scriptTag.onload = onScriptComplete;', 'scriptTag.src = fullsrc;', crossOriginLoading ? _webpack.Template.asString(['if (scriptTag.src.indexOf(window.location.origin + \'/\') !== 0) {', _webpack.Template.indent(`scriptTag.crossOrigin = ${JSON.stringify(crossOriginLoading)};`), '}']) : '', insertRoot && insertPlace || _webpack.Template.asString(['document.head.appendChild(scriptTag);']), 'return scriptTag;'])};`, `var findI18nScriptTag = ${runtimeTemplate.basicFunction('src, fullsrc', ['var existingScriptTags = document.getElementsByTagName("script");', 'for(var i = 0; i < existingScriptTags.length; i++) {', _webpack.Template.indent(['var tag = existingScriptTags[i];', 'var dataSrc = tag.getAttribute("data-src") || tag.getAttribute("src");', 'if((dataSrc === src || dataSrc === fullsrc)) return tag;']), '}', 'var existingStyleTags = document.getElementsByTagName("style");', 'for(var i = 0; i < existingStyleTags.length; i++) {', _webpack.Template.indent(['var tag = existingStyleTags[i];', 'var dataSrc = tag.getAttribute("data-src");', 'if(dataSrc === src || dataSrc === fullsrc) return tag;']), '}'])};`, `var loadI18nScriptTag = ${runtimeTemplate.basicFunction('chunkId', `return new Promise(${runtimeTemplate.basicFunction('resolve, reject', [`var src = ${_webpack.RuntimeGlobals.require}.miniI18nF(chunkId);`, `var fullsrc = ${_webpack.RuntimeGlobals.publicPath} + src;`, 'if(findI18nScriptTag(src, fullsrc)) return resolve();', 'createI18nScriptTag(chunkId, fullsrc, resolve, reject);'])});`)}`, '// object to store loaded I18N chunks', 'var installedI18nChunks = {', _webpack.Template.indent(
|
|
69
|
-
/** @type {string[]} */
|
|
61
|
+
})) : '', '__webpack_require__.nc && scriptTag.setAttribute("nonce", __webpack_require__.nc)', scriptType ? `scriptTag.type = ${JSON.stringify(scriptType)};` : '', `var onScriptComplete = ${runtimeTemplate.basicFunction('event', ['// avoid mem leaks.', 'scriptTag.onerror = scriptTag.onload = null;', 'if (event.type === \'load\') {', _webpack.Template.indent(['resolve();']), '} else {', _webpack.Template.indent(['var errorType = event && (event.type === \'load\' ? \'missing\' : event.type);', 'var realSrc = event && event.target && event.target.src || fullsrc;', 'var err = new Error("Loading I18N chunk " + chunkId + " failed.\\n(" + realSrc + ")");', 'err.code = "I18N_CHUNK_LOAD_FAILED";', 'err.type = errorType;', 'err.request = realSrc;', 'scriptTag.parentNode.removeChild(scriptTag)', 'reject(err);']), '}'])}`, 'scriptTag.onerror = scriptTag.onload = onScriptComplete;', 'scriptTag.src = fullsrc;', crossOriginLoading ? _webpack.Template.asString(['if (scriptTag.src.indexOf(window.location.origin + \'/\') !== 0) {', _webpack.Template.indent(`scriptTag.crossOrigin = ${JSON.stringify(crossOriginLoading)};`), '}']) : '', insertRoot && insertPlace || _webpack.Template.asString(['document.head.appendChild(scriptTag);']), 'return scriptTag;'])};`, `var findI18nScriptTag = ${runtimeTemplate.basicFunction('src, fullsrc', ['var existingScriptTags = document.getElementsByTagName("script");', 'for(var i = 0; i < existingScriptTags.length; i++) {', _webpack.Template.indent(['var tag = existingScriptTags[i];', 'var dataSrc = tag.getAttribute("data-src") || tag.getAttribute("src");', 'if((dataSrc === src || dataSrc === fullsrc)) return tag;']), '}', 'var existingStyleTags = document.getElementsByTagName("style");', 'for(var i = 0; i < existingStyleTags.length; i++) {', _webpack.Template.indent(['var tag = existingStyleTags[i];', 'var dataSrc = tag.getAttribute("data-src");', 'if(dataSrc === src || dataSrc === fullsrc) return tag;']), '}'])};`, `var loadI18nScriptTag = ${runtimeTemplate.basicFunction('chunkId', `return new Promise(${runtimeTemplate.basicFunction('resolve, reject', [`var src = ${_webpack.RuntimeGlobals.require}.miniI18nF(chunkId);`, `var fullsrc = ${_webpack.RuntimeGlobals.publicPath} + src;`, 'if(findI18nScriptTag(src, fullsrc)) return resolve();', 'createI18nScriptTag(chunkId, fullsrc, resolve, reject);'])});`)}`, '// object to store loaded I18N chunks', 'var installedI18nChunks = {', _webpack.Template.indent(/** @type {string[]} */
|
|
70
62
|
chunk.ids.map(id => `${JSON.stringify(id)}: 0`).join(',\n')), '};', '', `${_webpack.RuntimeGlobals.ensureChunkHandlers}.miniI18n = ${runtimeTemplate.basicFunction('chunkId, promises', [`var i18nChunks = ${JSON.stringify(chunkMap)};`, 'if(installedI18nChunks[chunkId]) promises.push(installedI18nChunks[chunkId]);', 'else if(installedI18nChunks[chunkId] !== 0 && i18nChunks[chunkId]) {', _webpack.Template.indent([`promises.push(installedI18nChunks[chunkId] = loadI18nScriptTag(chunkId).then(${runtimeTemplate.basicFunction('', 'installedI18nChunks[chunkId] = 0;')}, ${runtimeTemplate.basicFunction('e', ['delete installedI18nChunks[chunkId];', 'throw e;'])}));`]), '}'])};`, '']);
|
|
71
63
|
}
|
|
72
|
-
|
|
73
64
|
}
|
|
74
|
-
|
|
75
65
|
return I18nLoadingRuntimeModule;
|
|
76
66
|
}
|
|
@@ -4,36 +4,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.pluginName = exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _I18nKeysIdentifer = _interopRequireDefault(require("./I18nKeysIdentifer"));
|
|
9
|
-
|
|
10
8
|
var _optionsHandler = require("./optionsHandler");
|
|
11
|
-
|
|
12
9
|
var _I18nFilesEmitPlugin = require("./I18nFilesEmitPlugin");
|
|
13
|
-
|
|
14
10
|
var _I18nRuntimeDealerPlugin = require("./I18nRuntimeDealerPlugin");
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
12
|
// import getI18nKeysFormModules from './utils/getI18nKeysFormModules';
|
|
19
|
-
const pluginName = 'mini-i18n-extract-plugin';
|
|
20
|
-
exports.pluginName = pluginName;
|
|
21
|
-
const pluginSymbol = Symbol(pluginName);
|
|
22
13
|
|
|
14
|
+
const pluginName = exports.pluginName = 'mini-i18n-extract-plugin';
|
|
15
|
+
const pluginSymbol = Symbol(pluginName);
|
|
23
16
|
class I18nExtractPlugin {
|
|
24
17
|
constructor(options = {}) {
|
|
25
18
|
// initialize options
|
|
26
19
|
this.options = (0, _optionsHandler.optionsHandler)(options);
|
|
27
20
|
}
|
|
28
|
-
|
|
29
21
|
apply(compiler) {
|
|
30
22
|
new _I18nKeysIdentifer.default(this.options).apply(compiler);
|
|
31
23
|
new _I18nFilesEmitPlugin.I18nFilesEmitPlugin(this.options).apply(compiler);
|
|
32
24
|
new _I18nRuntimeDealerPlugin.I18nRuntimeDealerPlugin(this.options).apply(compiler);
|
|
33
25
|
}
|
|
34
|
-
|
|
35
26
|
}
|
|
36
|
-
|
|
37
27
|
exports.default = I18nExtractPlugin;
|
|
38
28
|
I18nExtractPlugin.pluginName = pluginName;
|
|
39
29
|
I18nExtractPlugin.pluginSymbol = pluginSymbol;
|
|
@@ -4,24 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.iterateModulesInChunk = iterateModulesInChunk;
|
|
7
|
-
|
|
8
7
|
var _ConcatenatedModule = _interopRequireDefault(require("webpack/lib/optimize/ConcatenatedModule"));
|
|
9
|
-
|
|
10
8
|
var _getChunkModules = require("./utils/getChunkModules");
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
10
|
function iterateModulesInChunk({
|
|
15
11
|
chunk,
|
|
16
12
|
cb,
|
|
17
13
|
compilation
|
|
18
14
|
}) {
|
|
19
15
|
let canStopLoop = false;
|
|
20
|
-
|
|
21
16
|
function stopLoop() {
|
|
22
17
|
canStopLoop = true;
|
|
23
18
|
}
|
|
24
|
-
|
|
25
19
|
function iterateNestedModules(mod) {
|
|
26
20
|
if (mod.resource) {
|
|
27
21
|
cb({
|
|
@@ -30,18 +24,15 @@ function iterateModulesInChunk({
|
|
|
30
24
|
});
|
|
31
25
|
return canStopLoop;
|
|
32
26
|
}
|
|
33
|
-
|
|
34
27
|
if (mod instanceof _ConcatenatedModule.default) {
|
|
35
28
|
const {
|
|
36
29
|
modules
|
|
37
30
|
} = mod;
|
|
38
31
|
return Array.from(modules).some(mod => iterateNestedModules(mod));
|
|
39
32
|
}
|
|
40
|
-
|
|
41
33
|
return canStopLoop;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
}
|
|
35
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
45
36
|
for (const mod of (0, _getChunkModules.getChunkModules)(chunk, compilation)) {
|
|
46
37
|
if (iterateNestedModules(mod)) {
|
|
47
38
|
return;
|