@zohodesk/client_build_tool 0.0.22-exp.5 → 0.0.23
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/CHANGELOG.md +8 -0
- package/README.md +4 -478
- package/README_backup.md +0 -482
- package/es/allCommandsConfigs.js +15 -0
- package/es/commands/build/commandExecutor.js +6 -0
- package/es/commands/build/config.js +5 -0
- package/es/commands/build/optionsProcessor.js +25 -0
- package/es/commands/build/preProcessor.js +4 -0
- package/es/commands/buildEs/commandExecutor.js +29 -0
- package/es/commands/buildEs/config.js +5 -0
- package/es/commands/buildEs/preProcessor.js +9 -0
- package/es/commands/buildLib/commandExecutor.js +24 -0
- package/es/commands/buildLib/config.js +5 -0
- package/es/commands/buildLib/preProcessor.js +9 -0
- package/es/commands/mockserver/commandExecutor.js +32 -0
- package/es/commands/mockserver/config.js +5 -0
- package/es/commands/pre_process/commandExecutor.js +10 -0
- package/es/commands/pre_process/config.js +5 -0
- package/es/commands/start/commandExecutor.js +4 -0
- package/es/commands/start/config.js +5 -0
- package/es/commands/start/optionsProcessor.js +21 -0
- package/es/commands/start/preProcessor.js +4 -0
- package/es/commands/template/commandExecutor.js +17 -0
- package/es/commands/template/config.js +5 -0
- package/es/commands/version/commandExecutor.js +5 -0
- package/es/commands/version/config.js +5 -0
- package/es/commandsRouter.js +58 -0
- package/es/index.js +4 -0
- package/es/logger.js +23 -0
- package/es/schemas/applyValuesToSchema/index.js +25 -0
- package/es/schemas/applyValuesToSchema/isObject.js +3 -0
- package/es/schemas/applyValuesToSchema/isValid.js +7 -0
- package/es/schemas/cliArgsToObject.js +32 -0
- package/es/schemas/defaultConfigValues.js +394 -0
- package/es/schemas/defaultConfigValuesOnly.js +196 -0
- package/es/schemas/deprecatedOptionsHandler.js +60 -0
- package/es/schemas/getNpmVersion.js +13 -0
- package/es/schemas/giveDefaultValue.js +11 -0
- package/es/schemas/npmConfigToObject.js +27 -0
- package/es/schemas/readOptions.js +67 -0
- package/es/schemas/readOptionsForConfigFile.js +28 -0
- package/es/shared/babel/addDefaultPlugins.js +8 -0
- package/es/shared/babel/babelWebConfig.js +43 -0
- package/es/shared/babel/babel_plugins/removeAttributesPlugin.js +21 -0
- package/es/shared/babel/getBabelPlugin.js +36 -0
- package/es/shared/babel/runBabelForJSFile.js +15 -0
- package/es/shared/babel/runBabelForTsFile.js +34 -0
- package/es/shared/bundler/webpack/common/decidePublicPath.js +45 -0
- package/es/shared/bundler/webpack/common/libAlias.js +24 -0
- package/es/shared/bundler/webpack/common/modeUtils.js +24 -0
- package/es/shared/bundler/webpack/common/nameTemplates.js +95 -0
- package/es/shared/bundler/webpack/common/resourceBasedPublicPath.js +12 -0
- package/es/shared/bundler/webpack/configCustomLoaders.js +3 -0
- package/es/shared/bundler/webpack/cssLoaders.js +8 -0
- package/es/shared/bundler/webpack/custom_plugins/BundleIntegrityReport/index.js +76 -0
- package/es/shared/bundler/webpack/custom_plugins/CdnChangePlugin/index.js +102 -0
- package/es/shared/bundler/webpack/custom_plugins/CdnChangePlugin/webpackCustomJsUrlLoader.js +36 -0
- package/es/shared/bundler/webpack/custom_plugins/ChunkHierarchyPlugin.js +65 -0
- package/es/shared/bundler/webpack/custom_plugins/CssCustomOrderPlugin.js +37 -0
- package/es/shared/bundler/webpack/custom_plugins/CustomScriptLoadingPlugin.js +97 -0
- package/es/shared/bundler/webpack/custom_plugins/EFCTemplatePlugin.js +98 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin.js +211 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/ContributionGuide.md +11 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nFilesEmitPlugin.js +160 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nKeysIdentifer.js +66 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nRuntimeDealerPlugin.js +201 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nSplit.md +95 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/LocaleChunkAssetsStore.js +59 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/ModulesI18nKeysStore.js +82 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/README.md +25 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/constants.js +13 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/createHash.js +15 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/getI18nLoadingRuntimeModule.js +72 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/index.js +23 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/iterateModulesInChunk.js +40 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/optionsHandler.js +59 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/pathCreator.js +15 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/readI18nValues.js +22 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/templateFileName.js +35 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/templateHashHelpers.js +70 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/collectI18nKeys.js +56 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/getChunkModules.js +6 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/hashUtils.js +10 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/index.js +2 -0
- package/es/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/propertiesUtils.js +121 -0
- package/es/shared/bundler/webpack/custom_plugins/InitialHtmlPlugin.js +85 -0
- package/es/shared/bundler/webpack/custom_plugins/InjectChunkGraphPlugin.js +47 -0
- package/es/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/addFilesNamesToManifestJson.js +20 -0
- package/es/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/createInitialEntries.js +11 -0
- package/es/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/createManifestJson.js +26 -0
- package/es/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/findInitialFileNames.js +11 -0
- package/es/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/index.js +34 -0
- package/es/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/removeHashFromFileName.js +11 -0
- package/es/shared/bundler/webpack/custom_plugins/MurphyInjectorPlugin/index.js +79 -0
- package/es/shared/bundler/webpack/custom_plugins/RTLSplitPlugin.js +0 -0
- package/es/shared/bundler/webpack/custom_plugins/ResourceHintsPlugin.js +185 -0
- package/es/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +47 -0
- package/es/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/RtlCssPlugin.js +70 -0
- package/es/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/RtrSplit.md +34 -0
- package/es/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/replaceCssDirTemplate.js +14 -0
- package/es/shared/bundler/webpack/custom_plugins/RuntimeResourceCleanup/index.js +63 -0
- package/es/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/classHandling.js +9 -0
- package/es/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/index.js +63 -0
- package/es/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/selectorWeightPrefixAdder.js +43 -0
- package/es/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/windowsModification.js +7 -0
- package/es/shared/bundler/webpack/custom_plugins/ServiceWorkerPlugin.js +104 -0
- package/es/shared/bundler/webpack/custom_plugins/ServiceWorkerPluginUtils.js +6 -0
- package/es/shared/bundler/webpack/custom_plugins/SourceMapPlugin/index.js +74 -0
- package/es/shared/bundler/webpack/custom_plugins/TPHashMappingPlugin/addHashToFilePath.js +10 -0
- package/es/shared/bundler/webpack/custom_plugins/TPHashMappingPlugin/index.js +36 -0
- package/es/shared/bundler/webpack/custom_plugins/UglifyCSSPlugin/index.js.js +35 -0
- package/es/shared/bundler/webpack/custom_plugins/VariableConversionCollector/ErrorHandler.js +52 -0
- package/es/shared/bundler/webpack/custom_plugins/VariableConversionCollector/index.js +341 -0
- package/es/shared/bundler/webpack/custom_plugins/custom_attribute_plugin/index.js +67 -0
- package/es/shared/bundler/webpack/custom_plugins/emitAsset.js +7 -0
- package/es/shared/bundler/webpack/custom_plugins/getInitialAssetsFuncTemplate.js +43 -0
- package/es/shared/bundler/webpack/custom_plugins/getInitialI18nAssetsArrayStr.js +79 -0
- package/es/shared/bundler/webpack/defaultVendorPatternList.js +3 -0
- package/es/shared/bundler/webpack/devtoolConfig.js +6 -0
- package/es/shared/bundler/webpack/entryConfig.js +25 -0
- package/es/shared/bundler/webpack/externals.js +10 -0
- package/es/shared/bundler/webpack/getCSSLoaders.js +17 -0
- package/es/shared/bundler/webpack/getFilenameFromModule.js +15 -0
- package/es/shared/bundler/webpack/jsLoaders.js +16 -0
- package/es/shared/bundler/webpack/loaderConfigs/assetLoaders.js +4 -0
- package/es/shared/bundler/webpack/loaderConfigs/babelLoaderConfig.js +10 -0
- package/es/shared/bundler/webpack/loaderConfigs/checkIsPatternsMatchFilename.js +45 -0
- package/es/shared/bundler/webpack/loaderConfigs/configHtmlTemplateLoader.js +11 -0
- package/es/shared/bundler/webpack/loaderConfigs/configPostCssLoader.js +23 -0
- package/es/shared/bundler/webpack/loaderConfigs/configWebWorkerLoader.js +13 -0
- package/es/shared/bundler/webpack/loaderConfigs/configsAssetsLoaders.js +71 -0
- package/es/shared/bundler/webpack/loaderConfigs/cssClassNameGenerate.js +56 -0
- package/es/shared/bundler/webpack/loaderConfigs/getCssLoaderOptions.js +11 -0
- package/es/shared/bundler/webpack/loaderConfigs/i18nIdReplaceLoaderConfig.js +40 -0
- package/es/shared/bundler/webpack/loaders/i18nIdReplaceLoader.js +116 -0
- package/es/shared/bundler/webpack/loaders/miniCssFallBackLoader.js +5 -0
- package/es/shared/bundler/webpack/loaders/workerLoader.js +121 -0
- package/es/shared/bundler/webpack/optimizationConfig.js +42 -0
- package/es/shared/bundler/webpack/outputConfig.js +35 -0
- package/es/shared/bundler/webpack/pluginConfigs/configBundleAnalyzer.js +30 -0
- package/es/shared/bundler/webpack/pluginConfigs/configBundleIntegrityReport.js +27 -0
- package/es/shared/bundler/webpack/pluginConfigs/configCSSMinifierPlugin.js +17 -0
- package/es/shared/bundler/webpack/pluginConfigs/configCdnChangePlugin.js +16 -0
- package/es/shared/bundler/webpack/pluginConfigs/configChunkHierarchyPlugin.js +10 -0
- package/es/shared/bundler/webpack/pluginConfigs/configCopyPublicFolders.js +50 -0
- package/es/shared/bundler/webpack/pluginConfigs/configCssCustomOrderPlugin.js +8 -0
- package/es/shared/bundler/webpack/pluginConfigs/configCustomAttributesPlugin.js +12 -0
- package/es/shared/bundler/webpack/pluginConfigs/configCustomScriptLoadingStrategyPlugin.js +67 -0
- package/es/shared/bundler/webpack/pluginConfigs/configEFCTemplatePlugin.js +37 -0
- package/es/shared/bundler/webpack/pluginConfigs/configEnvVariables.js +43 -0
- package/es/shared/bundler/webpack/pluginConfigs/configHtmlWebpackPlugin.js +52 -0
- package/es/shared/bundler/webpack/pluginConfigs/configI18nNumericIndexPlugin.js +17 -0
- package/es/shared/bundler/webpack/pluginConfigs/configI18nSplitPlugin.js +29 -0
- package/es/shared/bundler/webpack/pluginConfigs/configIgnorePlugin.js +8 -0
- package/es/shared/bundler/webpack/pluginConfigs/configInjectChunkGraphPlugin.js +12 -0
- package/es/shared/bundler/webpack/pluginConfigs/configManifestJsonPlugin.js +36 -0
- package/es/shared/bundler/webpack/pluginConfigs/configMiniCSSExtractPlugin.js +13 -0
- package/es/shared/bundler/webpack/pluginConfigs/configMurphyInjectorPlugin.js +19 -0
- package/es/shared/bundler/webpack/pluginConfigs/configProgressPlugin.js +18 -0
- package/es/shared/bundler/webpack/pluginConfigs/configResourceHintsPlugin.js +11 -0
- package/es/shared/bundler/webpack/pluginConfigs/configRtlCssPlugin.js +19 -0
- package/es/shared/bundler/webpack/pluginConfigs/configRuntimeResourceCleanup.js +20 -0
- package/es/shared/bundler/webpack/pluginConfigs/configSelectorWeightPlugin.js +18 -0
- package/es/shared/bundler/webpack/pluginConfigs/configServiceWorkerPlugin.js +29 -0
- package/es/shared/bundler/webpack/pluginConfigs/configSourceMapPlugin.js +12 -0
- package/es/shared/bundler/webpack/pluginConfigs/configTPHashMappingPlugin.js +20 -0
- package/es/shared/bundler/webpack/pluginConfigs/configVariableConversionPlugin.js +15 -0
- package/es/shared/bundler/webpack/plugins.js +33 -0
- package/es/shared/bundler/webpack/resolvers.js +70 -0
- package/es/shared/bundler/webpack/splitChunksConfig.js +106 -0
- package/es/shared/bundler/webpack/statsConfig.js +23 -0
- package/es/shared/bundler/webpack/tsLoaders.js +16 -0
- package/es/shared/bundler/webpack/utils/index.js +8 -0
- package/es/shared/bundler/webpack/utils/object-manipulation.js +82 -0
- package/es/shared/bundler/webpack/utils/updateArrayWithDefault.js +29 -0
- package/es/shared/bundler/webpack/webpackBuild.js +14 -0
- package/es/shared/bundler/webpack/webpackConfig.js +35 -0
- package/es/shared/commands-utils/doBasicRequirementCheck.js +10 -0
- package/es/shared/commands-utils/getCliPath.js +28 -0
- package/es/shared/commands-utils/index.js +3 -0
- package/es/shared/commands-utils/log.js +4 -0
- package/es/shared/commands-utils/readArgsFormCommandLine.js +4 -0
- package/es/shared/commands-utils/readOptionFormCommandLine.js +4 -0
- package/es/shared/commands-utils/spawnSyncIO.js +24 -0
- package/es/shared/constants.js +22 -0
- package/es/shared/fileUtils/copyFile.js +23 -0
- package/es/shared/fileUtils/directoryIterator.js +12 -0
- package/es/shared/fileUtils/watchRun.js +96 -0
- package/es/shared/postcss/custom_postcss_plugins/EmptyPlugin.js +18 -0
- package/es/shared/postcss/custom_postcss_plugins/HoverActivePlugin/constants.js +2 -0
- package/es/shared/postcss/custom_postcss_plugins/HoverActivePlugin/handleIgnores.js +58 -0
- package/es/shared/postcss/custom_postcss_plugins/HoverActivePlugin/index.js +122 -0
- package/es/shared/postcss/custom_postcss_plugins/HoverActivePlugin/insertBefore.js +22 -0
- package/es/shared/postcss/custom_postcss_plugins/HoverActivePlugin/isPreviouslyProcessed.js +11 -0
- package/es/shared/postcss/custom_postcss_plugins/HoverActivePlugin/replaceUtils.js +13 -0
- package/es/shared/postcss/custom_postcss_plugins/HoverActivePlugin/separateHoveredSelectorAndNormalSelector.js +17 -0
- package/es/shared/postcss/custom_postcss_plugins/HoverActivePlugin/specialCases.js +32 -0
- package/es/shared/postcss/custom_postcss_plugins/HoverActivePlugin/typeCheckUtils.js +28 -0
- package/es/shared/postcss/custom_postcss_plugins/RTLSplitPlugin.js +125 -0
- package/es/shared/postcss/custom_postcss_plugins/SelectorReplace.js +82 -0
- package/es/shared/postcss/custom_postcss_plugins/ValueReplacer.js +50 -0
- package/es/shared/postcss/custom_postcss_plugins/VariableModificationPlugin/index.js +318 -0
- package/es/shared/postcss/filterPluginsAllowedForSpecficFile.js +41 -0
- package/es/shared/postcss/getAllowedPostCssPlugins.js +20 -0
- package/es/shared/postcss/getSpecificPostCssPlugin.js +38 -0
- package/es/shared/postcss/runPostCssForCssFile.js +25 -0
- package/es/shared/pre_process/runPreProcess.js +47 -0
- package/es/shared/server/configWebpackDevMiddleware.js +26 -0
- package/es/shared/server/corsHandling.js +23 -0
- package/es/shared/server/getIp.js +18 -0
- package/es/shared/server/getServerURL.js +28 -0
- package/es/shared/server/httpsOptions.js +36 -0
- package/es/shared/server/initExpressApp.js +9 -0
- package/es/shared/server/initialHTMLHandling.js +92 -0
- package/es/shared/server/mockApiHandler.js +53 -0
- package/es/shared/server/mockServer.js +34 -0
- package/es/shared/server/serveContextFiles.js +17 -0
- package/es/shared/server/serverBywebpackDevMiddleware.js +21 -0
- package/es/shared/server/startHttpServer.js +18 -0
- package/es/shared/server/startHttpsServer.js +26 -0
- package/es/shared/server/unwanted/addHttp2Server.js +32 -0
- package/es/shared/server/unwanted/configWebpackDevMiddleware.js +35 -0
- package/es/shared/server/unwanted/mockApiSupport.js +11 -0
- package/es/shared/server/unwanted/websocketMockSetup.js +36 -0
- package/es/shared/server/urlConcat.js +35 -0
- package/es/shared/utils/requireLocalOrGlobal.js +57 -0
- package/es/shared/utils/utils.js +0 -0
- package/es/shared/utils/versionPrint.js +9 -0
- package/lib/shared/bundler/webpack/moduleConcatenationConfig.js +12 -4
- package/package.json +1 -1
- package/app/README.MD +0 -30
- package/app/es/test.js +0 -47
- package/app/package.json +0 -12
- package/lib/shared/bundler/webpack/custom_plugins/BundleIntegrityReport/utils.js +0 -15
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { Template, RuntimeGlobals, RuntimeModule } from 'webpack';
|
|
2
|
+
const pluginName = 'prefetch-preload-chunk-plugin';
|
|
3
|
+
/**
|
|
4
|
+
* NOTE: below functions are useable in webpack 5.79.0 as per day 28 Apr 2023
|
|
5
|
+
* Please checkout for future changes
|
|
6
|
+
* Here List of functions that take chunkId as Argument and return url without publicPath
|
|
7
|
+
* `__webpack_require__.u(chunkId)` - return's JS script urlPath
|
|
8
|
+
* `__webpack_require__.miniCssF(chunkId)` - return's CSS script urlPath
|
|
9
|
+
* `__webpack_require__.miniI18nF(chunkId)` - return's I18N script urlPath
|
|
10
|
+
*
|
|
11
|
+
*
|
|
12
|
+
* if url has .undefined. then chunk or url not valid or that file nt available
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export default class ResourceHintsPlugin {
|
|
16
|
+
constructor(_ref) {
|
|
17
|
+
let {
|
|
18
|
+
publicPath,
|
|
19
|
+
resourceHints
|
|
20
|
+
} = _ref;
|
|
21
|
+
this.resourceHints = resourceHints;
|
|
22
|
+
this.allowPrefetchingMultipleChunks = resourceHints.allowPrefetchingMultipleChunks;
|
|
23
|
+
this.publicPathsTemplateObj = {
|
|
24
|
+
js: publicPath,
|
|
25
|
+
css: publicPath,
|
|
26
|
+
i18n: publicPath
|
|
27
|
+
};
|
|
28
|
+
} // eslint-disable-next-line class-methods-use-this
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
apply(compiler) {
|
|
32
|
+
compiler.hooks.thisCompilation.tap(pluginName, compilation => {
|
|
33
|
+
const enabledChunks = new WeakSet();
|
|
34
|
+
|
|
35
|
+
const handler = (entryRuntimeChunk, set) => {
|
|
36
|
+
if (enabledChunks.has(entryRuntimeChunk)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
enabledChunks.add(entryRuntimeChunk);
|
|
41
|
+
set.add(RuntimeGlobals.getFullHash); // set.add(RuntimeGlobals.getChunkCssFilename);
|
|
42
|
+
|
|
43
|
+
const {
|
|
44
|
+
publicPathsTemplateObj
|
|
45
|
+
} = this;
|
|
46
|
+
compilation.addRuntimeModule(entryRuntimeChunk, // eslint-disable-next-line no-use-before-define
|
|
47
|
+
new ResourceHintsRuntimePlugin(compiler, {
|
|
48
|
+
chunk: entryRuntimeChunk,
|
|
49
|
+
allowPrefetchingMultipleChunks: this.allowPrefetchingMultipleChunks,
|
|
50
|
+
publicPathsTemplateObj
|
|
51
|
+
}));
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
compilation.hooks.runtimeRequirementInTree.for(RuntimeGlobals.ensureChunkHandlers).tap(pluginName, handler);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
class ResourceHintsRuntimePlugin extends RuntimeModule {
|
|
61
|
+
constructor(compiler, _ref2) {
|
|
62
|
+
let {
|
|
63
|
+
chunk,
|
|
64
|
+
publicPathsTemplateObj,
|
|
65
|
+
allowPrefetchingMultipleChunks
|
|
66
|
+
} = _ref2;
|
|
67
|
+
super('ResourceHintsRuntimePlugin loading', 10);
|
|
68
|
+
this.compiler = compiler;
|
|
69
|
+
this.publicPathsTemplateObj = publicPathsTemplateObj;
|
|
70
|
+
this.allowPrefetchingMultipleChunks = allowPrefetchingMultipleChunks;
|
|
71
|
+
this.chunk = chunk;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
generate() {
|
|
75
|
+
const {
|
|
76
|
+
chunk
|
|
77
|
+
} = this;
|
|
78
|
+
const idNameMap = chunk.getChunkMaps().name;
|
|
79
|
+
const nameIdMap = {};
|
|
80
|
+
let needsMap = this.allowPrefetchingMultipleChunks;
|
|
81
|
+
Object.keys(idNameMap).forEach(key => {
|
|
82
|
+
const value = idNameMap[key];
|
|
83
|
+
nameIdMap[value] = key;
|
|
84
|
+
|
|
85
|
+
if (key !== value) {
|
|
86
|
+
needsMap = true;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
let {
|
|
90
|
+
js: jsPP,
|
|
91
|
+
css: cssPP,
|
|
92
|
+
i18n: i18nPP
|
|
93
|
+
} = this.publicPathsTemplateObj;
|
|
94
|
+
jsPP = jsPP || RuntimeGlobals.publicPath;
|
|
95
|
+
cssPP = cssPP || RuntimeGlobals.publicPath;
|
|
96
|
+
i18nPP = i18nPP || RuntimeGlobals.publicPath;
|
|
97
|
+
/**
|
|
98
|
+
* naming abbr
|
|
99
|
+
* ntc -> nameToChunkIdMap
|
|
100
|
+
* cns -> chunkNames
|
|
101
|
+
* clt -> createLinkTag
|
|
102
|
+
* lpp -> loadAsPreloadOrPrefetch
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
return Template.asString([`const ntc = ${JSON.stringify(needsMap ? nameIdMap : {})};
|
|
106
|
+
const cns = Object.keys(ntc);
|
|
107
|
+
|
|
108
|
+
function clt(href, rel) {
|
|
109
|
+
let link = document.createElement("link");
|
|
110
|
+
link.href = href;
|
|
111
|
+
link.rel = rel;
|
|
112
|
+
__webpack_require__.nc && link.setAttribute("nonce", __webpack_require__.nc)
|
|
113
|
+
if(href.endsWith(".css")) {
|
|
114
|
+
link.as="style";
|
|
115
|
+
} else if (href.endsWith(".js")) {
|
|
116
|
+
link.as="script";
|
|
117
|
+
}
|
|
118
|
+
document.head.appendChild(link);
|
|
119
|
+
}
|
|
120
|
+
function isValidUrl(url) {
|
|
121
|
+
//return !url.includes(".undefined.");
|
|
122
|
+
return url.indexOf(".undefined") === -1;
|
|
123
|
+
}
|
|
124
|
+
function lpp(_chunkId, rel) {
|
|
125
|
+
let chunkId = ${RuntimeGlobals.require}.getChunkId(_chunkId);
|
|
126
|
+
// ${RuntimeGlobals.require}.e(chunkId);
|
|
127
|
+
if(__webpack_require__.O.j(chunkId)) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const jsUrl = ${jsPP} + __webpack_require__.u(chunkId);
|
|
131
|
+
const cssUrl = ${cssPP} + __webpack_require__.miniCssF(chunkId);
|
|
132
|
+
isValidUrl(jsUrl) && clt(jsUrl, rel);
|
|
133
|
+
isValidUrl(cssUrl) && clt(cssUrl, rel);
|
|
134
|
+
if(__webpack_require__.miniI18nF) {
|
|
135
|
+
const i18nUrl = ${i18nPP} + __webpack_require__.miniI18nF(chunkId);
|
|
136
|
+
isValidUrl(i18nUrl) && clt(i18nUrl, rel);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
${RuntimeGlobals.require}.getChunkId = function getChunkId(chunkId) {
|
|
141
|
+
${needsMap ? 'chunkId = ntc[chunkId]||chunkId;' : ''}
|
|
142
|
+
return chunkId;
|
|
143
|
+
}
|
|
144
|
+
${RuntimeGlobals.require}.getChunkIds = function getChunkIds(chunkId) {
|
|
145
|
+
${// eslint-disable-next-line no-nested-ternary
|
|
146
|
+
this.allowPrefetchingMultipleChunks ? `
|
|
147
|
+
const isRegExAsChunkId = chunkId instanceof RegExp;
|
|
148
|
+
if(isRegExAsChunkId) {
|
|
149
|
+
return cns.filter(chunkName => chunkId.test(chunkName)).map(chunkName => ntc[chunkName]);
|
|
150
|
+
}
|
|
151
|
+
return [${RuntimeGlobals.require}.getChunkId(chunkId)];
|
|
152
|
+
` : `return [${RuntimeGlobals.require}.getChunkId(chunkId)];`}
|
|
153
|
+
}
|
|
154
|
+
// Prefetch a chunk (${pluginName})
|
|
155
|
+
${RuntimeGlobals.require}.pfc = function prefetchChunk(chunkId) {
|
|
156
|
+
${`
|
|
157
|
+
let chunkIds = ${RuntimeGlobals.require}.getChunkIds(chunkId);
|
|
158
|
+
chunkIds.forEach(idOfAChunk => {
|
|
159
|
+
${RuntimeGlobals.require}.e(idOfAChunk);
|
|
160
|
+
})`}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// Preload a chunk (${pluginName})
|
|
164
|
+
${RuntimeGlobals.require}.plc = function preloadChunk(chunkId) {
|
|
165
|
+
let idOfAChunk = ${RuntimeGlobals.require}.getChunkIds(chunkId)[0];
|
|
166
|
+
lpp(idOfAChunk, "preload");
|
|
167
|
+
}
|
|
168
|
+
` // `// Prefetch a chunk (${pluginName})`,
|
|
169
|
+
// `${RuntimeGlobals.require}.pfc = function prefetchChunk(chunkId) {`,
|
|
170
|
+
// Template.indent([
|
|
171
|
+
// `chunkId = ${RuntimeGlobals.require}.getChunkId(chunkId)`,
|
|
172
|
+
// `${RuntimeGlobals.require}.e(chunkId);`
|
|
173
|
+
// ]),
|
|
174
|
+
// '};',
|
|
175
|
+
// `// Preload a chunk (${pluginName})`,
|
|
176
|
+
// `${RuntimeGlobals.require}.pfc = function prefetchChunk(chunkId) {`,
|
|
177
|
+
// Template.indent([
|
|
178
|
+
// `chunkId = ${RuntimeGlobals.require}.getChunkId(chunkId)`,
|
|
179
|
+
// `${RuntimeGlobals.require}.e(chunkId);`
|
|
180
|
+
// ]),
|
|
181
|
+
// '};'
|
|
182
|
+
]);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import HtmlWebpackPlugin from 'html-webpack-plugin'; // import { JavascriptModulesPlugin } from 'webpack';
|
|
2
|
+
|
|
3
|
+
import JavascriptModulesPlugin from 'webpack/lib/javascript/JavascriptModulesPlugin';
|
|
4
|
+
import { replaceCssDirTemplateMapper } from "./replaceCssDirTemplate";
|
|
5
|
+
const pluginName = 'OverwriteCssPathForRTL';
|
|
6
|
+
export default class OverwriteCssPathForRTL {
|
|
7
|
+
constructor() {
|
|
8
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
9
|
+
dirVarName: 'document.dir'
|
|
10
|
+
};
|
|
11
|
+
this.dirVarName = options.dirVarName || 'document.dir';
|
|
12
|
+
this.templateLabel = options.templateLabel || '{{--dir}}';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
overwriteCssPathinHTML(compilation) {
|
|
16
|
+
// NOTE: need to reconsider It is not working as expected
|
|
17
|
+
HtmlWebpackPlugin.getHooks(compilation).beforeAssetTagGeneration.tap(pluginName, data => {
|
|
18
|
+
const {
|
|
19
|
+
assets
|
|
20
|
+
} = data;
|
|
21
|
+
return { ...data,
|
|
22
|
+
assets: { ...assets,
|
|
23
|
+
css: assets.css && replaceCssDirTemplateMapper(assets.css, this.templateLabel)
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
overwriteCssPathinRequireEnsure(compilation, compiler) {
|
|
30
|
+
const {
|
|
31
|
+
RawSource
|
|
32
|
+
} = compiler.webpack.sources;
|
|
33
|
+
JavascriptModulesPlugin.getCompilationHooks(compilation).renderMain.tap(pluginName, source => {
|
|
34
|
+
const templateText = `"+(${this.dirVarName} === "rtl" ? "rtl": "ltr")+"`;
|
|
35
|
+
const replacedStr = source.source().replace(/\[dir\]/g, templateText);
|
|
36
|
+
return new RawSource(replacedStr);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
apply(compiler) {
|
|
41
|
+
compiler.hooks.thisCompilation.tap(pluginName, compilation => {
|
|
42
|
+
this.overwriteCssPathinHTML(compilation);
|
|
43
|
+
this.overwriteCssPathinRequireEnsure(compilation, compiler);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
2
|
+
// import rtlcss from 'rtlcss';
|
|
3
|
+
import { Compilation } from 'webpack';
|
|
4
|
+
import OverwriteCssPathForRTL from "./OverwriteCssPathForRTL";
|
|
5
|
+
import { separateRtlAndLtr } from "../../../../postcss/custom_postcss_plugins/RTLSplitPlugin";
|
|
6
|
+
import { isCss, isDirRelatedCss } from "../../utils";
|
|
7
|
+
const pluginName = 'RtlCssPlugin';
|
|
8
|
+
export class RtlCssPlugin {
|
|
9
|
+
constructor() {
|
|
10
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {Object} Options
|
|
14
|
+
* @property {String} dirVarName
|
|
15
|
+
* @property {Boolean} sourcemap
|
|
16
|
+
* @property {Object} config
|
|
17
|
+
*/
|
|
18
|
+
this.options = {
|
|
19
|
+
// dirVarName: options.dirVarName || 'document.dir',
|
|
20
|
+
sourcemap: options.sourcemap,
|
|
21
|
+
config: options.config
|
|
22
|
+
};
|
|
23
|
+
this.templateLabel = options.templateLabel || '{{--dir}}';
|
|
24
|
+
this.dirVarName = options.dirVarName || 'document.dir';
|
|
25
|
+
this.rtlSplitOptions = {
|
|
26
|
+
disableMinifySelector: options.disableMinifySelector
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
apply(compiler) {
|
|
31
|
+
const {
|
|
32
|
+
RawSource
|
|
33
|
+
} = compiler.webpack.sources;
|
|
34
|
+
new OverwriteCssPathForRTL({
|
|
35
|
+
templateLabel: this.templateLabel,
|
|
36
|
+
dirVarName: this.dirVarName
|
|
37
|
+
}).apply(compiler); // const { filename, sourcemap, config } = this.options;
|
|
38
|
+
// const { devtool } = compiler.options;
|
|
39
|
+
// const postcssOptions = {
|
|
40
|
+
// map: (sourcemap === undefined && !!devtool) || !!sourcemap
|
|
41
|
+
// };
|
|
42
|
+
|
|
43
|
+
compiler.hooks.compilation.tap(pluginName, compilation => {
|
|
44
|
+
// compilation.hooks.shouldGenerateChunkAssets.tap(pluginName, (...args) => {
|
|
45
|
+
// console.log('shouldGenerateChunkAssets', args);
|
|
46
|
+
// });
|
|
47
|
+
compilation.hooks.processAssets.tap({
|
|
48
|
+
name: pluginName,
|
|
49
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_COMPATIBILITY
|
|
50
|
+
}, assets => {
|
|
51
|
+
Object.keys(assets).filter(isCss).filter(isDirRelatedCss).forEach(chunkFilename => {
|
|
52
|
+
const {
|
|
53
|
+
source: asset
|
|
54
|
+
} = compilation.getAsset(chunkFilename);
|
|
55
|
+
const sourceStr = asset.source();
|
|
56
|
+
const {
|
|
57
|
+
ltr,
|
|
58
|
+
rtl
|
|
59
|
+
} = separateRtlAndLtr(sourceStr, this.rtlSplitOptions);
|
|
60
|
+
const ltrFilename = chunkFilename.replace('[dir]', 'ltr');
|
|
61
|
+
const rtlFilename = chunkFilename.replace('[dir]', 'rtl');
|
|
62
|
+
compilation.renameAsset(chunkFilename, ltrFilename);
|
|
63
|
+
compilation.updateAsset(ltrFilename, new RawSource(ltr));
|
|
64
|
+
compilation.emitAsset(rtlFilename, new RawSource(rtl));
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# RTL Split
|
|
2
|
+
|
|
3
|
+
we are doing in build time generating rtl related css code by using @zohodesk/postcss-rt npm.
|
|
4
|
+
It was automated, That postcss plugin create rtl reacted css and put them into same file, with css selector [dir=rtl] and ltr realted css with [dir=ltr].
|
|
5
|
+
Here is problem mostly no one need rtl and ltr related css at the same time in browser,
|
|
6
|
+
we are try to split them by [dir] and load which type of css is needed.
|
|
7
|
+
For this purpose we created RTL Split Plugin
|
|
8
|
+
|
|
9
|
+
# To Try it out rtl-ltr split
|
|
10
|
+
|
|
11
|
+
### how to use this feature?
|
|
12
|
+
|
|
13
|
+
to use this feature use have give the below oprtions
|
|
14
|
+
`package.json`
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
/// ...some things
|
|
19
|
+
"react-cli": {
|
|
20
|
+
// ...some things
|
|
21
|
+
"css": {
|
|
22
|
+
"plugins": {
|
|
23
|
+
"rtlSplit": {
|
|
24
|
+
"enableRTLSplit": true,
|
|
25
|
+
"templateLabel": "{{--dir}}", // this is for html template css file path dir template
|
|
26
|
+
"disableMinifySelector": false,
|
|
27
|
+
"dirVarName": "document.dir" // this will be used for download css based on dir
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// ...some things
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function replaceCssDirTemplate(filePath, cssDirTemplate) {
|
|
2
|
+
return filePath // added for efc and service worker handling
|
|
3
|
+
.replaceAll('[dir]', cssDirTemplate).replace('.ltr.css', `.${cssDirTemplate}.css`);
|
|
4
|
+
}
|
|
5
|
+
export function replaceCssDirTemplateMapper(assets, cssDirTemplate) {
|
|
6
|
+
return assets.map(filePath => replaceCssDirTemplate(filePath, cssDirTemplate));
|
|
7
|
+
}
|
|
8
|
+
export function replaceI18nLocalTemplate(filePath, localeTemplate) {
|
|
9
|
+
return filePath // added for efc and service worker handling
|
|
10
|
+
.replaceAll('[locale]', localeTemplate);
|
|
11
|
+
}
|
|
12
|
+
export function replaceI18nLocaleTemplateMapper(assets, localeTemplate) {
|
|
13
|
+
return assets.map(filePath => replaceI18nLocalTemplate(filePath, localeTemplate));
|
|
14
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Compilation } from 'webpack';
|
|
2
|
+
const pluginName = 'RuntimeResourceCleanupPlugin';
|
|
3
|
+
export default class RuntimeResourceCleanup {
|
|
4
|
+
constructor(_ref) {
|
|
5
|
+
let {
|
|
6
|
+
enable: scriptCleanUpEnabled,
|
|
7
|
+
chunkLoadingGlobal,
|
|
8
|
+
...options
|
|
9
|
+
} = _ref;
|
|
10
|
+
this.options = options;
|
|
11
|
+
this.scriptCleanUpEnabled = scriptCleanUpEnabled;
|
|
12
|
+
this.chunkLoadingGlobal = chunkLoadingGlobal;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
apply(compiler) {
|
|
16
|
+
compiler.hooks.compilation.tap(pluginName, compilation => {
|
|
17
|
+
compilation.hooks.processAssets.tap({
|
|
18
|
+
name: pluginName,
|
|
19
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
|
|
20
|
+
}, assets => {
|
|
21
|
+
const runtimeFiles = Object.keys(assets).filter(assetName => /.+?runtime.*\.js$/.test(assetName));
|
|
22
|
+
const searchString = 'chunkLoadingGlobal.forEach';
|
|
23
|
+
|
|
24
|
+
function generateScriptCleanUpCode(attributes) {
|
|
25
|
+
const [[attributeKey, attributeValue]] = Object.entries(attributes);
|
|
26
|
+
const selectorForGettingResources = `[${attributeKey}="${attributeValue}"]`;
|
|
27
|
+
return `
|
|
28
|
+
document.querySelectorAll('${selectorForGettingResources}').forEach(resource => resource.remove());
|
|
29
|
+
`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function generateRunTimeObjectCleanupCode() {
|
|
33
|
+
return `
|
|
34
|
+
Object.keys(__webpack_modules__).forEach(moduleKey => __webpack_modules__[moduleKey] = null);
|
|
35
|
+
Object.keys(__webpack_module_cache__).forEach(moduleCacheKey => __webpack_module_cache__[moduleCacheKey] = null);
|
|
36
|
+
__webpack_modules__ = null;
|
|
37
|
+
__webpack_module_cache__ = null;
|
|
38
|
+
Object.keys(__webpack_require__).forEach(staticMethodsKey => __webpack_require__[staticMethodsKey] = null);
|
|
39
|
+
__webpack_require__ = null;
|
|
40
|
+
`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function attachUninstallMethodToChunkGlobal() {
|
|
44
|
+
const {
|
|
45
|
+
chunkLoadingGlobal
|
|
46
|
+
} = this;
|
|
47
|
+
return `self['${chunkLoadingGlobal}'].unInstall = function() {
|
|
48
|
+
${generateRunTimeObjectCleanupCode()};
|
|
49
|
+
${this.scriptCleanUpEnabled ? generateScriptCleanUpCode(this.options.attributes) : ''}
|
|
50
|
+
}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
runtimeFiles.forEach(runtTimeFile => {
|
|
54
|
+
const runTimeSource = assets[runtTimeFile].source();
|
|
55
|
+
const newRunTimeCode = runTimeSource.replace(searchString, `${attachUninstallMethodToChunkGlobal.call(this)};${searchString}`);
|
|
56
|
+
const newRunTimeResource = new compiler.webpack.sources.RawSource(newRunTimeCode);
|
|
57
|
+
compilation.updateAsset(runtTimeFile, newRunTimeResource);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function hasPrevNodeIgnore(index, prevNode, ignoreComment) {
|
|
2
|
+
return index !== 0 && prevNode && prevNode.type && prevNode.type === 'comment' && prevNode.text.toLowerCase() === ignoreComment;
|
|
3
|
+
}
|
|
4
|
+
export function isAtRule(rule) {
|
|
5
|
+
return rule.parent && rule.parent.type === 'atrule';
|
|
6
|
+
}
|
|
7
|
+
export function isInsideMediaQuery(rule) {
|
|
8
|
+
return !!(isAtRule(rule) && rule.parent.name === 'media');
|
|
9
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import postcss from 'postcss';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { selectorWeightPrefixAdder } from "./selectorWeightPrefixAdder";
|
|
4
|
+
import { checkIsPatternsMatchFilename } from "../../loaderConfigs/checkIsPatternsMatchFilename";
|
|
5
|
+
|
|
6
|
+
class SelectorWeightPlugin {
|
|
7
|
+
constructor() {
|
|
8
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
9
|
+
this.options = {
|
|
10
|
+
selectorWeightConfig: options.configFile,
|
|
11
|
+
defaultSelector: options.defaultSelector,
|
|
12
|
+
customFileDetails: options.customFileDetails,
|
|
13
|
+
excludeStrings: options.excludeStrings,
|
|
14
|
+
patterns: options.patterns
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply(compiler) {
|
|
19
|
+
const {
|
|
20
|
+
defaultSelector,
|
|
21
|
+
customFileDetails,
|
|
22
|
+
excludeStrings,
|
|
23
|
+
patterns
|
|
24
|
+
} = this.options;
|
|
25
|
+
const rawdata = fs.readFileSync(customFileDetails);
|
|
26
|
+
const data = JSON.parse(rawdata);
|
|
27
|
+
compiler.hooks.compilation.tap('selector-weight-rewrite', compilation => {
|
|
28
|
+
compilation.hooks.optimizeModules.tap('selector-weight-rewrite', modules => {
|
|
29
|
+
const mods = Array.from(modules).filter(x => x.type.includes('css'));
|
|
30
|
+
mods.forEach(module => {
|
|
31
|
+
const filename = module.issuer.resource;
|
|
32
|
+
|
|
33
|
+
if (!checkIsPatternsMatchFilename(patterns, filename)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
/*
|
|
37
|
+
|
|
38
|
+
filename : Deskapp.module.css ?
|
|
39
|
+
data :
|
|
40
|
+
{
|
|
41
|
+
"DeskApp.module.css": {"defaultSelector" : ".desk_app_ui "}
|
|
42
|
+
}
|
|
43
|
+
selectorWeightConfig :
|
|
44
|
+
defaultSelector : .zoho_desk_ui
|
|
45
|
+
|
|
46
|
+
case filename = 'DeskApp.module.css' ?
|
|
47
|
+
data[filename].defaultSelector = '.desk_app_ui'
|
|
48
|
+
case filename is different ?
|
|
49
|
+
defaultSelector = '.zoho_desk_ui'
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
const rootOriginal = postcss.parse(module.content); // eslint-disable-next-line no-param-reassign
|
|
54
|
+
|
|
55
|
+
module.content = selectorWeightPrefixAdder(rootOriginal, data[filename] ? data[filename].defaultSelector : defaultSelector, excludeStrings).toString();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export default SelectorWeightPlugin;
|
package/es/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/selectorWeightPrefixAdder.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { hasPrevNodeIgnore, isInsideMediaQuery } from "./classHandling";
|
|
2
|
+
export function selectorWeightPrefixAdder(rootOriginal, selector, excludeStrings) {
|
|
3
|
+
rootOriginal.walkRules((rule, index) => {
|
|
4
|
+
const prevNode = rootOriginal.nodes[index - 1];
|
|
5
|
+
|
|
6
|
+
if (hasPrevNodeIgnore(index, prevNode, 'updateselector:ignore')) {
|
|
7
|
+
return;
|
|
8
|
+
} // TODO: need to verify cases
|
|
9
|
+
// if (!isInsideMediaQuery(rule)) {
|
|
10
|
+
// return;
|
|
11
|
+
// }
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const selectorArr = rule.selector.split(',');
|
|
15
|
+
selectorArr.forEach((singleSelectorStr, index) => {
|
|
16
|
+
if (excludeStrings.includes(singleSelectorStr.trim())) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (singleSelectorStr.includes(']')) {
|
|
21
|
+
if (singleSelectorStr.slice(singleSelectorStr.lastIndexOf(']') + 2).trim() === '') {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
selectorArr[index] = `${singleSelectorStr.slice(0, singleSelectorStr.lastIndexOf(']') + 1).trim()} ${selector}${singleSelectorStr.slice(singleSelectorStr.lastIndexOf(']') + 2).trim()}`;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
selectorArr[index] = `${selector}${singleSelectorStr}`;
|
|
30
|
+
}); // eslint-disable-next-line no-param-reassign
|
|
31
|
+
|
|
32
|
+
rule.selector = selectorArr.join(',\n');
|
|
33
|
+
});
|
|
34
|
+
return rootOriginal;
|
|
35
|
+
} // function convertSelectorWithoutAttribute (selector, conjunction) {
|
|
36
|
+
// const front = selector
|
|
37
|
+
// .slice(0, selector.lastIndexOf(']') + 1)
|
|
38
|
+
// .trim();
|
|
39
|
+
// const back = selector
|
|
40
|
+
// .slice(selector.lastIndexOf(']') + 2)
|
|
41
|
+
// .trim();
|
|
42
|
+
// return `${front} ${conjunction}${back}`;
|
|
43
|
+
// }
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const isWin = process.platform === 'win32';
|
|
2
|
+
export function windowsModification(array) {
|
|
3
|
+
return isWin ? array && Array.isArray(array) && array.map(r => r.replace(/\//g, '\\')) : array;
|
|
4
|
+
}
|
|
5
|
+
export function windowsModificationFile(filename) {
|
|
6
|
+
return isWin ? filename.replace(/\//g, '\\') : filename;
|
|
7
|
+
} // module.exports = { windowsModification, windowsModificationFile };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { getLocaleChunkAssetsStore } from "./I18nSplitPlugin/LocaleChunkAssetsStore";
|
|
3
|
+
import { emitAsset } from "./emitAsset";
|
|
4
|
+
import { replaceCssDirTemplateMapper } from "./RtlSplitPlugin/replaceCssDirTemplate";
|
|
5
|
+
import { cssDirTemplate, getInitialAssetsFuncTemplate } from "./getInitialAssetsFuncTemplate";
|
|
6
|
+
import { getI18nFileUrlPathTemplate } from "./ServiceWorkerPluginUtils";
|
|
7
|
+
const pluginName = 'ServiceWorkerPlugin';
|
|
8
|
+
export default class ServiceWorkerPlugin {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.templateFilePath = options.templateFilePath;
|
|
11
|
+
this.outputFilePath = options.outputFilePath;
|
|
12
|
+
this.publicPath = options.publicPath;
|
|
13
|
+
this.i18nFileNameTemplate = options.i18nFileNameTemplate;
|
|
14
|
+
this.chunkSplitEnable = options.chunkSplitEnable;
|
|
15
|
+
this.enableRTLSplit = options.enableRTLSplit;
|
|
16
|
+
this.entryPointName = options.entryPointName;
|
|
17
|
+
this.replaceText = options.replaceText; // this.publicPaths = options.publicPaths;
|
|
18
|
+
} // eslint-disable-next-line class-methods-use-this
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
isInitialChunk(chunk) {
|
|
22
|
+
if ('canBeInitial' in chunk) {
|
|
23
|
+
return chunk.canBeInitial();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return chunk.isInitial();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
apply(compiler) {
|
|
30
|
+
compiler.hooks.thisCompilation.tap(pluginName, compilation => {
|
|
31
|
+
// Get store for cache
|
|
32
|
+
this.store = getLocaleChunkAssetsStore(compilation);
|
|
33
|
+
});
|
|
34
|
+
compiler.hooks.thisCompilation.tap(pluginName, compilation => {
|
|
35
|
+
compilation.hooks.processAssets.tap({
|
|
36
|
+
name: pluginName,
|
|
37
|
+
stage: compilation.PROCESS_ASSETS_STAGE_DERIVED
|
|
38
|
+
}, () => {
|
|
39
|
+
this.createServiceWorkerFile(compilation, compiler);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
createServiceWorkerFile(compilation) {
|
|
45
|
+
const {
|
|
46
|
+
templateFilePath,
|
|
47
|
+
entryPointName,
|
|
48
|
+
outputFilePath,
|
|
49
|
+
chunkSplitEnable,
|
|
50
|
+
enableRTLSplit
|
|
51
|
+
} = this;
|
|
52
|
+
const templateContent = readFileSync(templateFilePath, 'utf-8');
|
|
53
|
+
let allChunkUrls = [];
|
|
54
|
+
const allI18nAssets = [];
|
|
55
|
+
const entryPoint = compilation.entrypoints.get(entryPointName);
|
|
56
|
+
const initialAssetsFuncTemplate = getInitialAssetsFuncTemplate({
|
|
57
|
+
entryPoint,
|
|
58
|
+
compilation,
|
|
59
|
+
enableRTLSplit,
|
|
60
|
+
i18nStore: this.store,
|
|
61
|
+
chunkSplitEnable,
|
|
62
|
+
i18nFileNameTemplate: this.i18nFileNameTemplate,
|
|
63
|
+
functionName: 'getInitialAssets'
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* NOTE:
|
|
67
|
+
* if chunkSplitEnable is false means,
|
|
68
|
+
* serviceWorker will get i18n files path for html
|
|
69
|
+
*/
|
|
70
|
+
// chunkSplitEnable &&
|
|
71
|
+
|
|
72
|
+
[...compilation.chunks].filter(c => !this.isInitialChunk(c)).forEach(chunk => {
|
|
73
|
+
allChunkUrls = [...allChunkUrls, ...chunk.files]; // allI18nAssets.push(
|
|
74
|
+
// getI18nFileUrlPathTemplate(
|
|
75
|
+
// compilation,
|
|
76
|
+
// chunk,
|
|
77
|
+
// this.i18nFileNameTemplate,
|
|
78
|
+
// '@locale@'
|
|
79
|
+
// )
|
|
80
|
+
// );
|
|
81
|
+
});
|
|
82
|
+
allChunkUrls = allChunkUrls.filter(fileName => !fileName.endsWith('.map'));
|
|
83
|
+
allChunkUrls = allChunkUrls.map(fileName => fileName.replace('smap/', ''));
|
|
84
|
+
|
|
85
|
+
if (enableRTLSplit) {
|
|
86
|
+
allChunkUrls = replaceCssDirTemplateMapper(allChunkUrls, cssDirTemplate);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const mod = templateContent.replace(this.replaceText, `
|
|
90
|
+
${initialAssetsFuncTemplate}
|
|
91
|
+
|
|
92
|
+
let initialAssetsObj = getInitialAssets();
|
|
93
|
+
|
|
94
|
+
let initialAssets = initialAssetsObj.i18n.concat(
|
|
95
|
+
initialAssetsObj.css,
|
|
96
|
+
initialAssetsObj.js
|
|
97
|
+
);
|
|
98
|
+
self.assets = initialAssets;
|
|
99
|
+
|
|
100
|
+
self.allChunks = ${JSON.stringify(allChunkUrls.concat(allI18nAssets))};`);
|
|
101
|
+
emitAsset(compilation, outputFilePath, mod);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
}
|