@zohodesk/client_build_tool 0.0.6-exp.40 → 0.0.6-exp.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/schemas/defaultConfigValues.js +4 -0
- package/lib/shared/bundler/webpack/custom_plugins/CustomScriptLoadingPlugin.js +110 -0
- package/lib/shared/bundler/webpack/pluginConfigs/configCustomScriptLoadingStrategyPlugin.js +76 -0
- package/lib/shared/bundler/webpack/plugins.js +3 -1
- package/lib/shared/bundler/webpack/utils/index.js +6 -1
- package/package.json +1 -1
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CustomScriptLoadingStrategyPlugin = void 0;
|
|
7
|
+
|
|
8
|
+
var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
const pluginName = 'CustomScriptLoadingStrategyPlugin';
|
|
13
|
+
|
|
14
|
+
class CustomScriptLoadingStrategyPlugin {
|
|
15
|
+
constructor({
|
|
16
|
+
scriptLoadingStategey
|
|
17
|
+
} = {}) {
|
|
18
|
+
this.scriptLoadingStrategy = scriptLoadingStategey;
|
|
19
|
+
this.tagNamesToMatch = ['script'];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getFileNameFromTagSrc(src) {
|
|
23
|
+
const fileNameArr = src.split('/');
|
|
24
|
+
return fileNameArr[fileNameArr.length - 1];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
addAttributestToTag(tag, attributes) {
|
|
28
|
+
tag.attributes = Object.assign({}, tag.attributes, attributes);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
matchFileName(tag, fileName) {
|
|
32
|
+
return fileName.test(this.getFileNameFromTagSrc(tag.attributes.src));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
blockingStrategy(tag) {
|
|
36
|
+
delete tag.attributes.defer;
|
|
37
|
+
delete tag.attributes.async;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
deferStrategy(tag) {
|
|
41
|
+
delete tag.attributes.async;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
asyncStrategy(tag) {
|
|
45
|
+
delete tag.attributes.defer;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
moduleStrategy(tag) {
|
|
49
|
+
this.deferStrategy(tag);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
matchStrategy(scriptLoadingStrategy, tag) {
|
|
53
|
+
if (scriptLoadingStrategy === 'blocking') {
|
|
54
|
+
this.blockingStrategy(tag);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (scriptLoadingStrategy === 'defer') {
|
|
58
|
+
this.deferStrategy(tag);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (scriptLoadingStrategy === 'async') {
|
|
62
|
+
this.asyncStrategy(tag);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (scriptLoadingStrategy === 'module') {
|
|
66
|
+
this.moduleStrategy(tag);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
matchAndApplyCustomLoadingStrategyToScripts(tags) {
|
|
71
|
+
Object.keys(this.scriptLoadingStrategy).forEach(scriptLoadingStrategy => {
|
|
72
|
+
const filesToMatch = this.scriptLoadingStrategy[scriptLoadingStrategy];
|
|
73
|
+
tags.forEach(tag => {
|
|
74
|
+
if (this.tagNamesToMatch.includes(tag.tagName) && tag.attributes.src) {
|
|
75
|
+
const isFileMatch = filesToMatch.some(fileName => this.matchFileName(tag, fileName));
|
|
76
|
+
|
|
77
|
+
if (isFileMatch) {
|
|
78
|
+
this.matchStrategy(scriptLoadingStrategy, tag);
|
|
79
|
+
this.addAttributestToTag(tag, {
|
|
80
|
+
[scriptLoadingStrategy]: true
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
} // filesToMatch.forEach(fileName => {
|
|
84
|
+
// if (!this.matchFileName(tag, fileName)) {
|
|
85
|
+
// return;
|
|
86
|
+
// }
|
|
87
|
+
// this.matchStrategy(scriptLoadingStrategy, tag);
|
|
88
|
+
// this.addAttributestToTag(tag, fileName, {
|
|
89
|
+
// [scriptLoadingStrategy]: true
|
|
90
|
+
// });
|
|
91
|
+
// });
|
|
92
|
+
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
apply(compiler) {
|
|
98
|
+
compiler.hooks.compilation.tap(pluginName, compilation => {
|
|
99
|
+
_htmlWebpackPlugin.default.getHooks(compilation).alterAssetTagGroups.tapAsync(pluginName, (data, callback) => {
|
|
100
|
+
const tags = [...data.bodyTags, ...data.headTags];
|
|
101
|
+
console.log(tags, 'dummy');
|
|
102
|
+
this.matchAndApplyCustomLoadingStrategyToScripts(tags);
|
|
103
|
+
callback(null, data);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
exports.CustomScriptLoadingStrategyPlugin = CustomScriptLoadingStrategyPlugin;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.configCustomScriptLoadingStrategyPlugin = configCustomScriptLoadingStrategyPlugin;
|
|
7
|
+
|
|
8
|
+
var _CustomScriptLoadingPlugin = require("../custom_plugins/CustomScriptLoadingPlugin");
|
|
9
|
+
|
|
10
|
+
var _utils = require("../utils");
|
|
11
|
+
|
|
12
|
+
const defaultScriptLoadingStrategy = 'defer';
|
|
13
|
+
const allowedScriptLoadingStrategies = ['blocking', 'defer', 'async', 'module'];
|
|
14
|
+
|
|
15
|
+
function isAllowedScriptLoadingStrategyUsed(scriptLoadingStategey) {
|
|
16
|
+
return allowedScriptLoadingStrategies.includes(scriptLoadingStategey);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getScriptLoadingStrategyForStringType(scriptLoadingStategey) {
|
|
20
|
+
if (isAllowedScriptLoadingStrategyUsed(scriptLoadingStategey)) {
|
|
21
|
+
return scriptLoadingStategey;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return defaultScriptLoadingStrategy;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getScriptLoadingStrategyForObject(scriptLoadingStategey) {
|
|
28
|
+
if (Object.keys(scriptLoadingStategey).length === 0) {
|
|
29
|
+
return defaultScriptLoadingStrategy;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const isAllowedScriptLoadingStrategy = Object.keys(scriptLoadingStategey).every(key => isAllowedScriptLoadingStrategyUsed(key));
|
|
33
|
+
|
|
34
|
+
if (isAllowedScriptLoadingStrategy) {
|
|
35
|
+
return Object.assign({}, scriptLoadingStategey);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
console.warn('un supported script loading strategy used', scriptLoadingStategey);
|
|
39
|
+
return defaultScriptLoadingStrategy;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getScriptLoadingStrategy(scriptLoadingStategey) {
|
|
43
|
+
if ((0, _utils.getTypeOf)(scriptLoadingStategey) === 'string') {
|
|
44
|
+
return {
|
|
45
|
+
[getScriptLoadingStrategyForStringType(scriptLoadingStategey)]: [/.*/]
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if ((0, _utils.getTypeOf)(scriptLoadingStategey) === 'object') {
|
|
50
|
+
return getScriptLoadingStrategyForObject(scriptLoadingStategey);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
[defaultScriptLoadingStrategy]: [/.*/]
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function configCustomScriptLoadingStrategyPlugin(options) {
|
|
59
|
+
const {
|
|
60
|
+
customScriptLoadingStrategey
|
|
61
|
+
} = options;
|
|
62
|
+
|
|
63
|
+
if (customScriptLoadingStrategey) {
|
|
64
|
+
const currentScriptLoadingStrategy = getScriptLoadingStrategy(customScriptLoadingStrategey.options);
|
|
65
|
+
|
|
66
|
+
if ((0, _utils.getTypeOf)(currentScriptLoadingStrategy) === 'object') {
|
|
67
|
+
return new _CustomScriptLoadingPlugin.CustomScriptLoadingStrategyPlugin({
|
|
68
|
+
scriptLoadingStategey: currentScriptLoadingStrategy
|
|
69
|
+
});
|
|
70
|
+
} else {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -47,10 +47,12 @@ var _configBundleIntegrityReport = require("./pluginConfigs/configBundleIntegrit
|
|
|
47
47
|
|
|
48
48
|
var _configRuntimeResourceCleanup = require("./pluginConfigs/configRuntimeResourceCleanup");
|
|
49
49
|
|
|
50
|
+
var _configCustomScriptLoadingStrategyPlugin = require("./pluginConfigs/configCustomScriptLoadingStrategyPlugin");
|
|
51
|
+
|
|
50
52
|
// import { IgnorePlugin } from 'webpack';
|
|
51
53
|
function plugins(options) {
|
|
52
54
|
const {
|
|
53
55
|
webpackPlugins
|
|
54
56
|
} = options;
|
|
55
|
-
return [(0, _configEnvVariables.configEnvVariables)(options), (0, _configCustomAttributesPlugin.configCustomAttributesPlugin)(options), (0, _configTPHashMappingPlugin.configTPHashMappingPlugin)(options), (0, _configCopyPublicFolders.configCopyPublicFolders)(options), (0, _configIgnorePlugin.configIgnorePlugin)(options), (0, _configMiniCSSExtractPlugin.configMiniCSSExtractPlugin)(options), (0, _configSelectorWeightPlugin.configSelectorWeightPlugin)(options), (0, _configVariableConversionPlugin.configVariableConversionPlugin)(options), (0, _configI18nSplitPlugin.configI18nSplitPlugin)(options), (0, _configRtlCssPlugin.configRtlCssPlugin)(options), (0, _configHtmlWebpackPlugin.configHtmlWebpackPlugin)(options), (0, _configCdnChangePlugin.configCdnChangePlugin)(options), (0, _configServiceWorkerPlugin.configServiceWorkerPlugin)(options), (0, _configEFCTemplatePlugin.configEFCTemplatePlugin)(options), (0, _configResourceHintsPlugin.configResourceHintsPlugin)(options), (0, _configBundleAnalyzer.configBundleAnalyzer)(options), (0, _configManifestJsonPlugin.configManifestJsonPlugin)(options), (0, _configSourceMapPlugin.configSourceMapPlugin)(options), (0, _configProgressPlugin.configProgressPlugin)(options), (0, _configBundleIntegrityReport.configBundleIntegrityReport)(options), (0, _configRuntimeResourceCleanup.configRuntimeResourceCleanup)(options), ...webpackPlugins].filter(Boolean);
|
|
57
|
+
return [(0, _configEnvVariables.configEnvVariables)(options), (0, _configCustomAttributesPlugin.configCustomAttributesPlugin)(options), (0, _configTPHashMappingPlugin.configTPHashMappingPlugin)(options), (0, _configCopyPublicFolders.configCopyPublicFolders)(options), (0, _configIgnorePlugin.configIgnorePlugin)(options), (0, _configMiniCSSExtractPlugin.configMiniCSSExtractPlugin)(options), (0, _configSelectorWeightPlugin.configSelectorWeightPlugin)(options), (0, _configVariableConversionPlugin.configVariableConversionPlugin)(options), (0, _configI18nSplitPlugin.configI18nSplitPlugin)(options), (0, _configRtlCssPlugin.configRtlCssPlugin)(options), (0, _configHtmlWebpackPlugin.configHtmlWebpackPlugin)(options), (0, _configCustomScriptLoadingStrategyPlugin.configCustomScriptLoadingStrategyPlugin)(options), (0, _configCdnChangePlugin.configCdnChangePlugin)(options), (0, _configServiceWorkerPlugin.configServiceWorkerPlugin)(options), (0, _configEFCTemplatePlugin.configEFCTemplatePlugin)(options), (0, _configResourceHintsPlugin.configResourceHintsPlugin)(options), (0, _configBundleAnalyzer.configBundleAnalyzer)(options), (0, _configManifestJsonPlugin.configManifestJsonPlugin)(options), (0, _configSourceMapPlugin.configSourceMapPlugin)(options), (0, _configProgressPlugin.configProgressPlugin)(options), (0, _configBundleIntegrityReport.configBundleIntegrityReport)(options), (0, _configRuntimeResourceCleanup.configRuntimeResourceCleanup)(options), ...webpackPlugins].filter(Boolean);
|
|
56
58
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.getTypeOf = getTypeOf;
|
|
6
7
|
exports.isJsFile = exports.isDirRelatedCss = exports.isCssFile = exports.isCss = void 0;
|
|
7
8
|
|
|
8
9
|
var _path = _interopRequireDefault(require("path"));
|
|
@@ -23,4 +24,8 @@ exports.isJsFile = isJsFile;
|
|
|
23
24
|
|
|
24
25
|
const isCssFile = file => /\.css$/.test(file);
|
|
25
26
|
|
|
26
|
-
exports.isCssFile = isCssFile;
|
|
27
|
+
exports.isCssFile = isCssFile;
|
|
28
|
+
|
|
29
|
+
function getTypeOf(value) {
|
|
30
|
+
return Object.prototype.toString.call(value).split(/\s/)[1].replace(/\]/, '').toLowerCase();
|
|
31
|
+
}
|