@zohodesk/react-cli 1.1.22 → 1.1.23-exp.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +77 -0
- package/lib/babel/cmjs-plugins-presets.js +6 -2
- package/lib/babel/es-plugins-presets.js +6 -2
- package/lib/configs/libAlias.js +36 -2
- package/lib/configs/resolvers.js +3 -1
- package/lib/loaders/workerLoader.js +39 -24
- package/lib/pluginUtils/configHtmlWebpackPlugins.js +62 -2
- package/lib/pluginUtils/getDevPlugins.js +11 -10
- package/lib/pluginUtils/getProdPlugins.js +3 -1
- package/lib/plugins/CustomScriptLoadingStrategyPlugin.js +109 -0
- package/lib/plugins/EventsHandlingPlugin.js +2 -2
- package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +1 -1
- package/lib/schemas/index.js +6 -1
- package/lib/utils/index.js +14 -0
- package/lib/utils/typeCheck.js +10 -0
- package/npm-shrinkwrap.json +176 -19652
- package/package.json +3 -2
package/README.md
CHANGED
@@ -44,6 +44,61 @@ Now to run app
|
|
44
44
|
|
45
45
|
# Change Logs
|
46
46
|
|
47
|
+
# 1.1.23 (28-06-2024)
|
48
|
+
|
49
|
+
**Features**
|
50
|
+
|
51
|
+
- alias feature added for library, application and jest. To enable it , configure your `react-cli.config.js` as below
|
52
|
+
|
53
|
+
```
|
54
|
+
{
|
55
|
+
alias: {
|
56
|
+
"@components": './src/components,
|
57
|
+
}
|
58
|
+
}
|
59
|
+
```
|
60
|
+
|
61
|
+
- For devmapping config jsConfig.json ad below
|
62
|
+
|
63
|
+
```
|
64
|
+
{
|
65
|
+
"compilerOptions": {
|
66
|
+
"baseUrl": ".",
|
67
|
+
"paths": {
|
68
|
+
"@components/*": [ "./src/components/*"],
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
```
|
73
|
+
|
74
|
+
- Customized Script loading strategy added. To enabled it, configure your `react-cli.config.js` as below
|
75
|
+
|
76
|
+
```
|
77
|
+
{
|
78
|
+
app: {
|
79
|
+
htmlTemplate: {
|
80
|
+
customScriptLoadingStrategey: {
|
81
|
+
enable: true,
|
82
|
+
options: {
|
83
|
+
async: [/.*js$/],
|
84
|
+
defer: [/^main.*\.js$/]
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
90
|
+
```
|
91
|
+
|
92
|
+
**Changes**
|
93
|
+
|
94
|
+
- Worker loading logic
|
95
|
+
|
96
|
+
# 1.1.22 (6-6-2024)
|
97
|
+
|
98
|
+
**Changes**
|
99
|
+
|
100
|
+
- Bug fix in Typescript
|
101
|
+
|
47
102
|
# 1.1.21 (4-6-2024)
|
48
103
|
|
49
104
|
- TypeScript support has been added for the application, library, and Jest.
|
@@ -59,6 +114,28 @@ Now to run app
|
|
59
114
|
```
|
60
115
|
- The Memory leak issue while downloading i18n and CSS files has been fixed
|
61
116
|
|
117
|
+
|
118
|
+
# 1.1.20-exp.1
|
119
|
+
|
120
|
+
**Changes**
|
121
|
+
|
122
|
+
- Added memory leak fixes for script, links tags
|
123
|
+
|
124
|
+
**Feature**
|
125
|
+
- Custom Script loading strategy support for initial html script tags.
|
126
|
+
|
127
|
+
# 1.1.19-exp.18
|
128
|
+
|
129
|
+
**Changes**
|
130
|
+
|
131
|
+
- To do further build size optimization by utilizing webpack provided config.
|
132
|
+
|
133
|
+
```
|
134
|
+
innerGraph: true,
|
135
|
+
usedExports: true,
|
136
|
+
sideEffects: true
|
137
|
+
```
|
138
|
+
|
62
139
|
# 1.1.20 (27-5-2024)
|
63
140
|
|
64
141
|
**Feature**
|
@@ -18,12 +18,16 @@ const {
|
|
18
18
|
babelCustomizationForLibrary: {
|
19
19
|
babelPlugins
|
20
20
|
},
|
21
|
-
enableTypeScript
|
21
|
+
enableTypeScript,
|
22
|
+
alias
|
22
23
|
} = (0, _utils.getOptions)();
|
23
24
|
const isProd = mode.toLowerCase() === 'prod';
|
24
25
|
const defaultPlugins = [[require.resolve('babel-plugin-transform-define'), isProd ? {
|
25
26
|
__DOCS__: false
|
26
|
-
} : {}], require.resolve('@babel/plugin-syntax-dynamic-import')
|
27
|
+
} : {}], require.resolve('@babel/plugin-syntax-dynamic-import'), [require.resolve('babel-plugin-module-resolver'), {
|
28
|
+
"root": ["./"],
|
29
|
+
alias
|
30
|
+
}]];
|
27
31
|
const resolvedPlugins = [];
|
28
32
|
babelPlugins.forEach(plugin => {
|
29
33
|
resolvedPlugins.push(require.resolve(plugin));
|
@@ -19,12 +19,16 @@ const {
|
|
19
19
|
babelCustomizationForLibrary: {
|
20
20
|
babelPlugins
|
21
21
|
},
|
22
|
-
enableTypeScript
|
22
|
+
enableTypeScript,
|
23
|
+
alias
|
23
24
|
} = (0, _utils.getOptions)();
|
24
25
|
const isProd = mode.toLowerCase() === 'prod';
|
25
26
|
const defaultPlugins = [[require.resolve('babel-plugin-transform-define'), isProd ? {
|
26
27
|
__DOCS__: false
|
27
|
-
} : {}], require.resolve('@babel/plugin-syntax-dynamic-import')
|
28
|
+
} : {}], require.resolve('@babel/plugin-syntax-dynamic-import'), [require.resolve('babel-plugin-module-resolver'), {
|
29
|
+
"root": ["./"],
|
30
|
+
alias
|
31
|
+
}]];
|
28
32
|
const resolvedPlugins = [];
|
29
33
|
babelPlugins.forEach(plugin => {
|
30
34
|
resolvedPlugins.push(require.resolve(plugin));
|
package/lib/configs/libAlias.js
CHANGED
@@ -3,12 +3,45 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
+
exports.aliasPathCreation = aliasPathCreation;
|
6
7
|
exports.libAlias = exports.jestModuleNameMapper = void 0;
|
8
|
+
|
9
|
+
var _utils = require("../utils");
|
10
|
+
|
11
|
+
var _path = _interopRequireDefault(require("path"));
|
12
|
+
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
14
|
+
|
7
15
|
// the reason for alias at the time was code tree shaking
|
8
16
|
// tree shaking was most compactable with ES module system
|
9
17
|
// FIXME: But there is a posiblity when these package does not have lib,
|
10
18
|
// app will work because of alias, But may be jest won't work because of not alais
|
11
19
|
// So need to think about use alais in jest
|
20
|
+
const appPath = process.cwd();
|
21
|
+
const {
|
22
|
+
alias,
|
23
|
+
app
|
24
|
+
} = (0, _utils.getOptions)();
|
25
|
+
const {
|
26
|
+
disableES5Transpile
|
27
|
+
} = app;
|
28
|
+
|
29
|
+
function aliasPathCreation(customAlias) {
|
30
|
+
if (customAlias == null) {
|
31
|
+
return {};
|
32
|
+
}
|
33
|
+
|
34
|
+
const newAlias = {};
|
35
|
+
Object.keys(customAlias).forEach(key => {
|
36
|
+
if (customAlias[key].startsWith('.')) {
|
37
|
+
newAlias[key] = _path.default.resolve(appPath, customAlias[key]);
|
38
|
+
} else {
|
39
|
+
newAlias[key] = customAlias[key];
|
40
|
+
}
|
41
|
+
});
|
42
|
+
return newAlias;
|
43
|
+
}
|
44
|
+
|
12
45
|
const libAlias = {
|
13
46
|
'@zohodesk/components/lib': '@zohodesk/components/es',
|
14
47
|
// '@zohodesk/zc-custom/lib': '@zohodesk/zc-custom/es',
|
@@ -31,8 +64,9 @@ const libAlias = {
|
|
31
64
|
// '^@components(.*)$': '<rootDir>/src/components$1',
|
32
65
|
|
33
66
|
exports.libAlias = libAlias;
|
34
|
-
const
|
35
|
-
|
67
|
+
const totalAlias = disableES5Transpile ? Object.assign({}, libAlias, aliasPathCreation(alias)) : aliasPathCreation(alias);
|
68
|
+
const jestModuleNameMapper = Object.keys(totalAlias).reduce((previousValue, key) => {
|
69
|
+
previousValue[`^${key}(.*)$`] = `${totalAlias[key]}$1`;
|
36
70
|
return previousValue;
|
37
71
|
}, {});
|
38
72
|
exports.jestModuleNameMapper = jestModuleNameMapper;
|
package/lib/configs/resolvers.js
CHANGED
@@ -21,6 +21,7 @@ function moduleResolver(options) {
|
|
21
21
|
moduleResolvePath,
|
22
22
|
disableES5Transpile
|
23
23
|
} = options.app;
|
24
|
+
const customAlias = options.alias;
|
24
25
|
let required = moduleResolvePath && (0, _requireLocalOrGlobal.requireLocal)(moduleResolvePath);
|
25
26
|
|
26
27
|
if (!required) {
|
@@ -32,10 +33,11 @@ function moduleResolver(options) {
|
|
32
33
|
}
|
33
34
|
|
34
35
|
const nodeModulesPath = required ? required.nodeModulesPath : _client_packages_group.nodeModulesPath;
|
36
|
+
const totalAlias = disableES5Transpile ? Object.assign({}, _libAlias.libAlias, (0, _libAlias.aliasPathCreation)(customAlias)) : (0, _libAlias.aliasPathCreation)(customAlias);
|
35
37
|
return {
|
36
38
|
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
37
39
|
modules: [nodeModulesPath, _constants.cliNodeModulesPath, 'node_modules'].filter(Boolean),
|
38
|
-
alias:
|
40
|
+
alias: totalAlias // alias: { ...libAlias, ...clientDependenies }
|
39
41
|
|
40
42
|
};
|
41
43
|
}
|
@@ -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,51 @@ 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 {
|
66
|
+
[getScriptLoadingStrategyForStringType(scriptLoadingStategey)]: [/.*/]
|
67
|
+
};
|
68
|
+
}
|
69
|
+
|
70
|
+
if ((0, _utils.getTypeOf)(scriptLoadingStategey) === 'object') {
|
71
|
+
return getScriptLoadingStrategyForObject(scriptLoadingStategey);
|
72
|
+
}
|
73
|
+
|
74
|
+
return {
|
75
|
+
[defaultScriptLoadingStrategy]: [/.*/]
|
76
|
+
};
|
77
|
+
}
|
29
78
|
|
30
79
|
function configHtmlWebpackPlugins(plugins, {
|
31
80
|
enableChunkHash = false,
|
@@ -33,7 +82,8 @@ function configHtmlWebpackPlugins(plugins, {
|
|
33
82
|
inject,
|
34
83
|
crossorigin,
|
35
84
|
hasEFC,
|
36
|
-
minify: minifyHtmlOptions = false
|
85
|
+
minify: minifyHtmlOptions = false,
|
86
|
+
customScriptLoadingStrategey = {}
|
37
87
|
}) {
|
38
88
|
const optionsHtmlWebpack = {
|
39
89
|
chunksSortMode: 'none',
|
@@ -44,7 +94,7 @@ function configHtmlWebpackPlugins(plugins, {
|
|
44
94
|
// ? minifyHtmlOptions
|
45
95
|
// : minifyHtmlOptions,,
|
46
96
|
templateParameters: _common.templateParameters,
|
47
|
-
scriptLoading:
|
97
|
+
scriptLoading: defaultScriptLoadingStrategy,
|
48
98
|
inject: inject
|
49
99
|
};
|
50
100
|
|
@@ -56,4 +106,14 @@ function configHtmlWebpackPlugins(plugins, {
|
|
56
106
|
crossorigin && plugins.push(new _htmlWebpackInjectAttributesPlugin.default({
|
57
107
|
crossorigin: 'anonymous'
|
58
108
|
}));
|
109
|
+
|
110
|
+
if (customScriptLoadingStrategey.enable) {
|
111
|
+
const currentScriptLoadingStrategy = getScriptLoadingStrategy(customScriptLoadingStrategey.options);
|
112
|
+
|
113
|
+
if ((0, _utils.getTypeOf)(currentScriptLoadingStrategy) === 'object') {
|
114
|
+
plugins.push(new _CustomScriptLoadingStrategyPlugin.default({
|
115
|
+
scriptLoadingStategey: currentScriptLoadingStrategy
|
116
|
+
}));
|
117
|
+
}
|
118
|
+
}
|
59
119
|
}
|
@@ -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
|
},
|
@@ -161,15 +162,15 @@ const getDevPlugins = (options, publicPath) => {
|
|
161
162
|
pluginsArr.push(new _lodashWebpackPlugin.default({
|
162
163
|
collections: true,
|
163
164
|
shorthands: true
|
164
|
-
}));
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
});
|
165
|
+
})); // configHtmlWebpackPlugins(pluginsArr, {
|
166
|
+
// enableChunkHash: false,
|
167
|
+
// folder,
|
168
|
+
// minify: false,
|
169
|
+
// inject,
|
170
|
+
// crossorigin,
|
171
|
+
// hasEFC,
|
172
|
+
// customScriptLoadingStrategey,
|
173
|
+
// });
|
173
174
|
|
174
175
|
if (hasEFC) {
|
175
176
|
pluginsArr.push(new _plugins.EFCPlugin({
|
@@ -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,109 @@
|
|
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
|
+
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
|
+
this.matchAndApplyCustomLoadingStrategyToScripts(tags);
|
102
|
+
callback(null, data);
|
103
|
+
});
|
104
|
+
});
|
105
|
+
}
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
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
@@ -15,6 +15,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
15
15
|
|
16
16
|
// TODO move deprecated options to separate file and manage seperately
|
17
17
|
var _default = {
|
18
|
+
alias: null,
|
18
19
|
unstableDepsInverse: {
|
19
20
|
value: false,
|
20
21
|
cli: 'unstable_deps_inverse'
|
@@ -322,7 +323,11 @@ var _default = {
|
|
322
323
|
},
|
323
324
|
htmlTemplate: {
|
324
325
|
minify: null,
|
325
|
-
inject: true
|
326
|
+
inject: true,
|
327
|
+
customScriptLoadingStrategey: {
|
328
|
+
enable: false,
|
329
|
+
options: null
|
330
|
+
}
|
326
331
|
},
|
327
332
|
removePropTypes: false,
|
328
333
|
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
|