@zohodesk/react-cli 1.1.21 → 1.1.22-exp.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +22 -0
- package/lib/configs/resolvers.js +1 -0
- package/lib/configs/webpack.prod.config.js +4 -1
- package/lib/loaders/workerLoader.js +39 -24
- package/lib/pluginUtils/configHtmlWebpackPlugins.js +57 -1
- package/lib/pluginUtils/getDevPlugins.js +4 -2
- package/lib/pluginUtils/getProdPlugins.js +3 -1
- package/lib/plugins/CustomScriptLoadingStrategyPlugin.js +108 -0
- package/lib/plugins/EventsHandlingPlugin.js +2 -2
- package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +1 -1
- package/lib/schemas/index.js +5 -1
- package/lib/utils/index.js +14 -0
- package/lib/utils/typeCheck.js +10 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
@@ -59,6 +59,28 @@ Now to run app
|
|
59
59
|
```
|
60
60
|
- The Memory leak issue while downloading i18n and CSS files has been fixed
|
61
61
|
|
62
|
+
|
63
|
+
# 1.1.20-exp.1
|
64
|
+
|
65
|
+
**Changes**
|
66
|
+
|
67
|
+
- Added memory leak fixes for script, links tags
|
68
|
+
|
69
|
+
**Feature**
|
70
|
+
- Custom Script loading strategy support for initial html script tags.
|
71
|
+
|
72
|
+
# 1.1.19-exp.18
|
73
|
+
|
74
|
+
**Changes**
|
75
|
+
|
76
|
+
- To do further build size optimization by utilizing webpack provided config.
|
77
|
+
|
78
|
+
```
|
79
|
+
innerGraph: true,
|
80
|
+
usedExports: true,
|
81
|
+
sideEffects: true
|
82
|
+
```
|
83
|
+
|
62
84
|
# 1.1.20 (27-5-2024)
|
63
85
|
|
64
86
|
**Feature**
|
package/lib/configs/resolvers.js
CHANGED
@@ -33,6 +33,7 @@ function moduleResolver(options) {
|
|
33
33
|
|
34
34
|
const nodeModulesPath = required ? required.nodeModulesPath : _client_packages_group.nodeModulesPath;
|
35
35
|
return {
|
36
|
+
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
36
37
|
modules: [nodeModulesPath, _constants.cliNodeModulesPath, 'node_modules'].filter(Boolean),
|
37
38
|
alias: disableES5Transpile ? _libAlias.libAlias : {} // alias: { ...libAlias, ...clientDependenies }
|
38
39
|
|
@@ -103,7 +103,10 @@ module.exports = {
|
|
103
103
|
// exclude: /\/smap/
|
104
104
|
// })
|
105
105
|
// ],
|
106
|
-
moduleIds: 'named'
|
106
|
+
moduleIds: 'named',
|
107
|
+
usedExports: true,
|
108
|
+
// innerGraph: true, // this property present on webpack 5
|
109
|
+
sideEffects: true
|
107
110
|
},
|
108
111
|
stats: {
|
109
112
|
children: false,
|
@@ -19,32 +19,32 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
19
19
|
/* import WebWorkerTemplatePlugin from 'webpack/lib/webworker/WebWorkerTemplatePlugin';
|
20
20
|
import ExternalsPlugin from 'webpack/lib/ExternalsPlugin'; */
|
21
21
|
const schema = {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
type: 'object',
|
23
|
+
properties: {
|
24
|
+
publicPath: {
|
25
|
+
anyOf: [{
|
26
|
+
type: 'string'
|
27
27
|
}, {
|
28
|
-
|
28
|
+
instanceof: 'Function'
|
29
29
|
}]
|
30
30
|
},
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
filename: {
|
32
|
+
anyOf: [{
|
33
|
+
type: 'string',
|
34
|
+
minLength: 1
|
35
35
|
}, {
|
36
|
-
|
36
|
+
instanceof: 'Function'
|
37
37
|
}]
|
38
38
|
},
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
chunkFilename: {
|
40
|
+
type: 'string',
|
41
|
+
minLength: 1
|
42
42
|
},
|
43
|
-
|
44
|
-
|
43
|
+
esModule: {
|
44
|
+
type: 'boolean'
|
45
45
|
}
|
46
46
|
},
|
47
|
-
|
47
|
+
additionalProperties: false
|
48
48
|
}; // eslint-disable-next-line
|
49
49
|
|
50
50
|
function loader() {}
|
@@ -112,25 +112,40 @@ function pitch(request) {
|
|
112
112
|
}
|
113
113
|
|
114
114
|
function workerCode() {
|
115
|
+
if (this.workerInstance) {
|
116
|
+
return this.workerInstance;
|
117
|
+
}
|
118
|
+
|
115
119
|
let blob;
|
116
120
|
|
117
121
|
try {
|
118
122
|
blob = new Blob([`importScripts('${this.workerUrl}');`], {
|
119
|
-
|
123
|
+
type: 'application/javascript'
|
120
124
|
});
|
121
125
|
} catch (e1) {
|
122
126
|
throw new Error(e1);
|
123
127
|
}
|
124
128
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
return
|
129
|
+
const url = window.URL || window.webkitURL;
|
130
|
+
const blobUrl = url.createObjectURL(blob);
|
131
|
+
this.workerInstance = new Worker(blobUrl);
|
132
|
+
return this.workerInstance;
|
129
133
|
}
|
130
134
|
|
131
|
-
return cb(null,
|
135
|
+
return cb(null, `const workerObj ={\n
|
136
|
+
workerInstance: null, \n
|
132
137
|
workerUrl: __webpack_public_path__ + ${JSON.stringify(entry)}, \n
|
133
138
|
getInstance: ${workerCode} \n
|
134
|
-
}
|
139
|
+
};\n
|
140
|
+
workerObj.getInstance();
|
141
|
+
${options.esModule ? 'export default' : 'module.exports ='} workerObj;
|
142
|
+
`); // return cb(
|
143
|
+
// null,
|
144
|
+
// `${options.esModule ? 'export default' : 'module.exports ='} {\n
|
145
|
+
// workerInstance: null, \n
|
146
|
+
// workerUrl: __webpack_public_path__ + ${JSON.stringify(entry)}, \n
|
147
|
+
// getInstance: ${workerCode} \n
|
148
|
+
// }`
|
149
|
+
// );
|
135
150
|
});
|
136
151
|
}
|
@@ -13,6 +13,10 @@ var _htmlWebpackInjectAttributesPlugin = _interopRequireDefault(require("html-we
|
|
13
13
|
|
14
14
|
var _common = require("../common");
|
15
15
|
|
16
|
+
var _utils = require("../utils");
|
17
|
+
|
18
|
+
var _CustomScriptLoadingStrategyPlugin = _interopRequireDefault(require("../plugins/CustomScriptLoadingStrategyPlugin"));
|
19
|
+
|
16
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
21
|
|
18
22
|
const defaultHTMLMiniFyOption = {
|
@@ -26,6 +30,47 @@ const defaultHTMLMiniFyOption = {
|
|
26
30
|
removeStyleLinkTypeAttributes: true,
|
27
31
|
useShortDoctype: true
|
28
32
|
};
|
33
|
+
const defaultScriptLoadingStrategy = 'defer';
|
34
|
+
const allowedScriptLoadingStrategies = ['blocking', 'defer', 'async', 'module'];
|
35
|
+
|
36
|
+
function isAllowedScriptLoadingStrategyUsed(scriptLoadingStategey) {
|
37
|
+
return allowedScriptLoadingStrategies.includes(scriptLoadingStategey);
|
38
|
+
}
|
39
|
+
|
40
|
+
function getScriptLoadingStrategyForStringType(scriptLoadingStategey) {
|
41
|
+
if (isAllowedScriptLoadingStrategyUsed(scriptLoadingStategey)) {
|
42
|
+
return scriptLoadingStategey;
|
43
|
+
}
|
44
|
+
|
45
|
+
return defaultScriptLoadingStrategy;
|
46
|
+
}
|
47
|
+
|
48
|
+
function getScriptLoadingStrategyForObject(scriptLoadingStategey) {
|
49
|
+
if (Object.keys(scriptLoadingStategey).length === 0) {
|
50
|
+
return defaultScriptLoadingStrategy;
|
51
|
+
}
|
52
|
+
|
53
|
+
const isAllowedScriptLoadingStrategy = Object.keys(scriptLoadingStategey).every(key => isAllowedScriptLoadingStrategyUsed(key));
|
54
|
+
|
55
|
+
if (isAllowedScriptLoadingStrategy) {
|
56
|
+
return Object.assign({}, scriptLoadingStategey);
|
57
|
+
}
|
58
|
+
|
59
|
+
console.warn('un supported script loading strategy used', scriptLoadingStategey);
|
60
|
+
return defaultScriptLoadingStrategy;
|
61
|
+
}
|
62
|
+
|
63
|
+
function getScriptLoadingStrategy(scriptLoadingStategey) {
|
64
|
+
if ((0, _utils.getTypeOf)(scriptLoadingStategey) === 'string') {
|
65
|
+
return getScriptLoadingStrategyForStringType(scriptLoadingStategey);
|
66
|
+
}
|
67
|
+
|
68
|
+
if ((0, _utils.getTypeOf)(scriptLoadingStategey) === 'object') {
|
69
|
+
return getScriptLoadingStrategyForObject(scriptLoadingStategey);
|
70
|
+
}
|
71
|
+
|
72
|
+
return 'defer';
|
73
|
+
}
|
29
74
|
|
30
75
|
function configHtmlWebpackPlugins(plugins, {
|
31
76
|
enableChunkHash = false,
|
@@ -33,7 +78,8 @@ function configHtmlWebpackPlugins(plugins, {
|
|
33
78
|
inject,
|
34
79
|
crossorigin,
|
35
80
|
hasEFC,
|
36
|
-
minify: minifyHtmlOptions = false
|
81
|
+
minify: minifyHtmlOptions = false,
|
82
|
+
customScriptLoadingStrategey = {}
|
37
83
|
}) {
|
38
84
|
const optionsHtmlWebpack = {
|
39
85
|
chunksSortMode: 'none',
|
@@ -56,4 +102,14 @@ function configHtmlWebpackPlugins(plugins, {
|
|
56
102
|
crossorigin && plugins.push(new _htmlWebpackInjectAttributesPlugin.default({
|
57
103
|
crossorigin: 'anonymous'
|
58
104
|
}));
|
105
|
+
|
106
|
+
if (customScriptLoadingStrategey.enable) {
|
107
|
+
const currentScriptLoadingStrategy = getScriptLoadingStrategy(customScriptLoadingStrategey.options);
|
108
|
+
|
109
|
+
if ((0, _utils.getTypeOf)(currentScriptLoadingStrategy) === 'object') {
|
110
|
+
plugins.push(new _CustomScriptLoadingStrategyPlugin.default({
|
111
|
+
scriptLoadingStategey: currentScriptLoadingStrategy
|
112
|
+
}));
|
113
|
+
}
|
114
|
+
}
|
59
115
|
}
|
@@ -62,7 +62,8 @@ const getDevPlugins = (options, publicPath) => {
|
|
62
62
|
mode
|
63
63
|
},
|
64
64
|
htmlTemplate: {
|
65
|
-
inject
|
65
|
+
inject,
|
66
|
+
customScriptLoadingStrategey
|
66
67
|
},
|
67
68
|
crossorigin
|
68
69
|
},
|
@@ -168,7 +169,8 @@ const getDevPlugins = (options, publicPath) => {
|
|
168
169
|
minify: false,
|
169
170
|
inject,
|
170
171
|
crossorigin,
|
171
|
-
hasEFC
|
172
|
+
hasEFC,
|
173
|
+
customScriptLoadingStrategey
|
172
174
|
});
|
173
175
|
|
174
176
|
if (hasEFC) {
|
@@ -80,7 +80,8 @@ const getProdPlugins = (options, publicPath = '') => {
|
|
80
80
|
} = options.app;
|
81
81
|
const {
|
82
82
|
inject,
|
83
|
-
minify: minifyHtmlOptions
|
83
|
+
minify: minifyHtmlOptions,
|
84
|
+
customScriptLoadingStrategey
|
84
85
|
} = htmlTemplate;
|
85
86
|
const {
|
86
87
|
i18n
|
@@ -178,6 +179,7 @@ const getProdPlugins = (options, publicPath = '') => {
|
|
178
179
|
folder,
|
179
180
|
inject,
|
180
181
|
minify: minifyHtmlOptions,
|
182
|
+
customScriptLoadingStrategey,
|
181
183
|
crossorigin,
|
182
184
|
hasEFC
|
183
185
|
});
|
@@ -0,0 +1,108 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = 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
|
+
}
|
20
|
+
|
21
|
+
getFileNameFromTagSrc(src) {
|
22
|
+
const fileNameArr = src.split('/');
|
23
|
+
return fileNameArr[fileNameArr.length - 1];
|
24
|
+
}
|
25
|
+
|
26
|
+
addAttributestToTag(tag, attributes) {
|
27
|
+
tag.attributes = Object.assign({}, tag.attributes, attributes);
|
28
|
+
}
|
29
|
+
|
30
|
+
matchFileName(tag, fileName) {
|
31
|
+
return fileName.test(this.getFileNameFromTagSrc(tag.attributes.src));
|
32
|
+
}
|
33
|
+
|
34
|
+
blockingStrategy(tag) {
|
35
|
+
delete tag.attributes.defer;
|
36
|
+
delete tag.attributes.async;
|
37
|
+
}
|
38
|
+
|
39
|
+
deferStrategy(tag) {
|
40
|
+
delete tag.attributes.async;
|
41
|
+
}
|
42
|
+
|
43
|
+
asyncStrategy(tag) {
|
44
|
+
delete tag.attributes.defer;
|
45
|
+
}
|
46
|
+
|
47
|
+
moduleStrategy(tag) {
|
48
|
+
this.deferStrategy(tag);
|
49
|
+
}
|
50
|
+
|
51
|
+
matchStrategy(scriptLoadingStrategy, tag) {
|
52
|
+
if (scriptLoadingStrategy === 'blocking') {
|
53
|
+
this.blockingStrategy(tag);
|
54
|
+
}
|
55
|
+
|
56
|
+
if (scriptLoadingStrategy === 'defer') {
|
57
|
+
this.deferStrategy(tag);
|
58
|
+
}
|
59
|
+
|
60
|
+
if (scriptLoadingStrategy === 'async') {
|
61
|
+
this.asyncStrategy(tag);
|
62
|
+
}
|
63
|
+
|
64
|
+
if (scriptLoadingStrategy === 'module') {
|
65
|
+
this.moduleStrategy(tag);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
matchAndApplyCustomLoadingStrategyToScripts(tags) {
|
70
|
+
Object.keys(this.scriptLoadingStrategy).forEach(scriptLoadingStrategy => {
|
71
|
+
const filesToMatch = this.scriptLoadingStrategy[scriptLoadingStrategy];
|
72
|
+
tags.forEach(tag => {
|
73
|
+
if (tag.attributes.src) {
|
74
|
+
const isFileMatch = filesToMatch.some(fileName => this.matchFileName(tag, fileName));
|
75
|
+
|
76
|
+
if (isFileMatch) {
|
77
|
+
this.matchStrategy(scriptLoadingStrategy, tag);
|
78
|
+
this.addAttributestToTag(tag, {
|
79
|
+
[scriptLoadingStrategy]: true
|
80
|
+
});
|
81
|
+
}
|
82
|
+
} // filesToMatch.forEach(fileName => {
|
83
|
+
// if (!this.matchFileName(tag, fileName)) {
|
84
|
+
// return;
|
85
|
+
// }
|
86
|
+
// this.matchStrategy(scriptLoadingStrategy, tag);
|
87
|
+
// this.addAttributestToTag(tag, fileName, {
|
88
|
+
// [scriptLoadingStrategy]: true
|
89
|
+
// });
|
90
|
+
// });
|
91
|
+
|
92
|
+
});
|
93
|
+
});
|
94
|
+
}
|
95
|
+
|
96
|
+
apply(compiler) {
|
97
|
+
compiler.hooks.compilation.tap(pluginName, compilation => {
|
98
|
+
_htmlWebpackPlugin.default.getHooks(compilation).alterAssetTagGroups.tapAsync(pluginName, (data, callback) => {
|
99
|
+
const tags = [...data.bodyTags, ...data.headTags];
|
100
|
+
this.matchAndApplyCustomLoadingStrategyToScripts(tags);
|
101
|
+
callback(null, data);
|
102
|
+
});
|
103
|
+
});
|
104
|
+
}
|
105
|
+
|
106
|
+
}
|
107
|
+
|
108
|
+
exports.default = CustomScriptLoadingStrategyPlugin;
|
@@ -18,10 +18,10 @@ class EventsHandlingPlugin {
|
|
18
18
|
fn: compilation => {
|
19
19
|
compilation.mainTemplate.hooks.requireEnsure.tap('CustomAttributePlugin', source => {
|
20
20
|
// const str = attributeSetTemplate(cssAttributes, 'linkTag');
|
21
|
-
const sourceStr = source.replace('linkTag.onerror = function(event) {', 'linkTag.onerror = function(event) { linkTag.onerror = linkTag.onload = null');
|
21
|
+
const sourceStr = source.replace('linkTag.onerror = function(event) {', 'linkTag.onerror = function(event) { linkTag.onerror = linkTag.onload = null;');
|
22
22
|
const replacedSourceStr = sourceStr.replace('linkTag.onload = resolve', `linkTag.onload = () => {
|
23
|
+
linkTag.onerror = linkTag.onload = null;
|
23
24
|
resolve();
|
24
|
-
linkTag.onerror = linkTag.onload = null
|
25
25
|
};`);
|
26
26
|
return replacedSourceStr;
|
27
27
|
});
|
@@ -229,8 +229,8 @@ class I18nDownlodLogic {
|
|
229
229
|
}
|
230
230
|
var scriptTag = document.createElement("script");
|
231
231
|
scriptTag.onload = () => {
|
232
|
-
resolve();
|
233
232
|
scriptTag.onerror = scriptTag.onload = null;
|
233
|
+
resolve();
|
234
234
|
};
|
235
235
|
scriptTag.onerror = function(event) {
|
236
236
|
scriptTag.onerror = scriptTag.onload = null;
|
package/lib/schemas/index.js
CHANGED
@@ -322,7 +322,11 @@ var _default = {
|
|
322
322
|
},
|
323
323
|
htmlTemplate: {
|
324
324
|
minify: null,
|
325
|
-
inject: true
|
325
|
+
inject: true,
|
326
|
+
customScriptLoadingStrategey: {
|
327
|
+
enable: false,
|
328
|
+
options: null
|
329
|
+
}
|
326
330
|
},
|
327
331
|
removePropTypes: false,
|
328
332
|
customChunksBaseConfig: null,
|
package/lib/utils/index.js
CHANGED
@@ -167,6 +167,20 @@ var _getComponents = _interopRequireDefault(require("./getComponents"));
|
|
167
167
|
|
168
168
|
var _ssTestHack = _interopRequireDefault(require("./ssTestHack"));
|
169
169
|
|
170
|
+
var _typeCheck = require("./typeCheck");
|
171
|
+
|
172
|
+
Object.keys(_typeCheck).forEach(function (key) {
|
173
|
+
if (key === "default" || key === "__esModule") return;
|
174
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
175
|
+
if (key in exports && exports[key] === _typeCheck[key]) return;
|
176
|
+
Object.defineProperty(exports, key, {
|
177
|
+
enumerable: true,
|
178
|
+
get: function () {
|
179
|
+
return _typeCheck[key];
|
180
|
+
}
|
181
|
+
});
|
182
|
+
});
|
183
|
+
|
170
184
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
171
185
|
|
172
186
|
// eslint-disable-next-line no-duplicate-imports
|
package/npm-shrinkwrap.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@zohodesk/react-cli",
|
3
|
-
"version": "1.1.
|
3
|
+
"version": "1.1.22-exp.1",
|
4
4
|
"lockfileVersion": 2,
|
5
5
|
"requires": true,
|
6
6
|
"packages": {
|
7
7
|
"": {
|
8
8
|
"name": "@zohodesk/react-cli",
|
9
|
-
"version": "1.1.
|
9
|
+
"version": "1.1.22-exp.1",
|
10
10
|
"license": "ISC",
|
11
11
|
"dependencies": {
|
12
12
|
"@babel/cli": "7.10.5",
|