@zohodesk/react-cli 0.0.1-beta.99 → 0.0.1-betaa.138.1
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintignore +7 -7
- package/.eslintrc.js +183 -183
- package/CHANGELOG.md +5 -0
- package/README.md +636 -491
- package/bin/cli.js +372 -367
- package/files/eslintrc.js +57 -0
- package/files/prettierrc.js +3 -0
- package/lib/babel/cmjs-plugins-presets.js +16 -9
- package/lib/babel/es-plugins-presets.js +26 -14
- package/lib/common/getEntries.js +31 -22
- package/lib/common/getPublicPathConfig.js +27 -13
- package/lib/common/index.js +21 -25
- package/lib/common/splitChunks.js +62 -53
- package/lib/common/templateParameters.js +10 -8
- package/lib/configs/jest.config.js +15 -25
- package/lib/configs/webpack.component.umd.config.js +31 -37
- package/lib/configs/webpack.css.umd.config.js +44 -47
- package/lib/configs/webpack.dev.config.js +70 -52
- package/lib/configs/webpack.docs.config.js +106 -106
- package/lib/configs/webpack.prod.config.js +95 -75
- package/lib/hooks/docsProptypeHook.js +32 -38
- package/lib/jest/commitedFilesResult.js +103 -74
- package/lib/jest/coverageCollector.js +41 -21
- package/lib/jest/jsonMaker.js +15 -16
- package/lib/jest/preProcessors/cssPreprocessor.js +16 -18
- package/lib/jest/preProcessors/jsPreprocessor.js +3 -5
- package/lib/jest/preProcessors/otherFilesPreprocessor.js +5 -6
- package/lib/jest/result.js +90 -45
- package/lib/jest/run.js +43 -43
- package/lib/jest/setup.js +102 -95
- package/lib/loaderUtils/getCSSLoaders.js +21 -22
- package/lib/loaderUtils/getDevJsLoaders.js +25 -23
- package/lib/loaderUtils/index.js +11 -13
- package/lib/loaders/docsLoader.js +15 -15
- package/lib/loaders/docsPropsLoader.js +14 -17
- package/lib/loaders/fileLoader.js +33 -35
- package/lib/loaders/scriptInstrumentLoader.js +21 -20
- package/lib/loaders/workerLoader.js +136 -0
- package/lib/middlewares/HMRMiddleware.js +54 -45
- package/lib/middlewares/SSTMiddleware.js +8 -5
- package/lib/pluginUtils/getDevPlugins.js +114 -52
- package/lib/pluginUtils/getDocsPlugins.js +25 -29
- package/lib/pluginUtils/getLibraryPlugins.js +8 -10
- package/lib/pluginUtils/getProdPlugins.js +163 -74
- package/lib/pluginUtils/getServerPlugins.js +8 -11
- package/lib/pluginUtils/getUMDCSSPlugins.js +11 -15
- package/lib/pluginUtils/getUMDComponentPlugins.js +11 -15
- package/lib/pluginUtils/index.js +36 -43
- package/lib/plugins/CdnChangePlugin.js +63 -0
- package/lib/plugins/CleanupStatsPlugin.js +18 -32
- package/lib/plugins/CustomAttributePlugin.js +79 -0
- package/lib/plugins/CustomAttributePlugin.md +35 -0
- package/lib/plugins/EFCPlugin.js +185 -0
- package/lib/plugins/I18NInjectIntoIndexPlugin.js +118 -52
- package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +60 -0
- package/lib/plugins/I18nSplitPlugin/I18nDependency.js +44 -0
- package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +266 -0
- package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +183 -0
- package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +100 -0
- package/lib/plugins/I18nSplitPlugin/I18nSplit.md +86 -0
- package/lib/plugins/I18nSplitPlugin/README.md +25 -0
- package/lib/plugins/I18nSplitPlugin/index.js +185 -0
- package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +64 -0
- package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +13 -0
- package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +26 -0
- package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +40 -0
- package/lib/plugins/I18nSplitPlugin/utils/index.js +31 -0
- package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +112 -0
- package/lib/plugins/ManifestPlugin.js +52 -63
- package/lib/plugins/ModuleStatsPlugin.js +83 -173
- package/lib/plugins/OptimizeJSPlugin.js +24 -41
- package/lib/plugins/PublicPathCallbackPlugin.js +42 -116
- package/lib/plugins/PublicPathChangePlugin.js +175 -284
- package/lib/plugins/ReportGeneratePlugin.js +150 -151
- package/lib/plugins/ResourceHintsPlugin.js +53 -35
- package/lib/plugins/ScriptInstrumentPlugin.js +22 -37
- package/lib/plugins/ServiceWorkerPlugin.js +81 -57
- package/lib/plugins/ShadowDOMSupportPlugin.js +153 -234
- package/lib/plugins/SourceMapHookPlugin.js +21 -33
- package/lib/plugins/TPHashMappingPlugin.js +67 -0
- package/lib/plugins/UglifyCSSPlugin.js +23 -30
- package/lib/plugins/UnusedFilesFindPlugin.js +137 -152
- package/lib/plugins/index.js +100 -91
- package/lib/plugins/webpackwatchrunplugin.js +18 -30
- package/lib/postcss-plugins/ExcludeRTLPlugin.js +14 -17
- package/lib/schemas/index.js +336 -81
- package/lib/servers/clusterHubServer.js +22 -26
- package/lib/servers/docsServer.js +3 -5
- package/lib/servers/docsServerCore.js +84 -91
- package/lib/servers/helpServer.js +19 -21
- package/lib/servers/impactServer.js +99 -92
- package/lib/servers/mockserver.js +24 -24
- package/lib/servers/scrServer.js +78 -98
- package/lib/servers/server.js +101 -122
- package/lib/servers/ssServer.js +63 -61
- package/lib/sh/pre-commit.sh +34 -34
- package/lib/sh/reportPublish.sh +45 -46
- package/lib/templates/CoverageScriptTemplate.js +45 -18
- package/lib/templates/WMSTemplate.js +17 -18
- package/lib/templates/linterConstant.js +6 -4
- package/lib/utils/babelPresets.js +12 -5
- package/lib/utils/buildstats.html +148 -148
- package/lib/utils/clean.js +12 -11
- package/lib/utils/copy.js +12 -34
- package/lib/utils/copyTimezones.js +9 -16
- package/lib/utils/createEventStream.js +24 -19
- package/lib/utils/cssClassNameGenerate.js +44 -73
- package/lib/utils/cssURLReplacer.js +60 -54
- package/lib/utils/dependencyPostPublish.js +20 -19
- package/lib/utils/fileUtils.js +66 -54
- package/lib/utils/folderIterator.js +20 -21
- package/lib/utils/getComponents.js +70 -27
- package/lib/utils/getCurrentBranch.js +11 -17
- package/lib/utils/getDependenciesImpactList.js +114 -187
- package/lib/utils/getHash.js +9 -13
- package/lib/utils/getIp.js +9 -9
- package/lib/utils/getOptions.js +26 -29
- package/lib/utils/getServerURL.js +19 -10
- package/lib/utils/index.js +147 -126
- package/lib/utils/init.js +2 -2
- package/lib/utils/initPreCommitHook.js +40 -32
- package/lib/utils/jsonHelper.js +37 -21
- package/lib/utils/lint/addScripts.js +27 -0
- package/lib/utils/lint/checkExistingConfig.js +67 -0
- package/lib/utils/lint/copyConfigs.js +24 -0
- package/lib/utils/lint/index.js +54 -0
- package/lib/utils/lint/lintScripts.js +11 -0
- package/lib/utils/lint/lintSetup.js +31 -0
- package/lib/utils/lint/lintStagedPreCommitHook.js +7 -0
- package/lib/utils/lint/question.js +30 -0
- package/lib/utils/lintReporter.js +70 -56
- package/lib/utils/mailSender.js +12 -27
- package/lib/utils/pullOrigin.js +21 -18
- package/lib/utils/reinstallDependencies.js +76 -85
- package/lib/utils/removeAttributes.js +25 -23
- package/lib/utils/repoClone.js +47 -45
- package/lib/utils/request.js +64 -77
- package/lib/utils/resultSchema.json +73 -73
- package/lib/utils/rtl.js +22 -29
- package/lib/utils/setEnvVariables.js +5 -6
- package/lib/utils/ssTestHack.js +21 -19
- package/lib/utils/switchBranch.js +21 -20
- package/lib/utils/urlConcat.js +22 -0
- package/package.json +141 -136
- package/templates/app/.eslintrc.js +140 -140
- package/templates/app/README.md +12 -12
- package/templates/app/app/index.html +24 -24
- package/templates/app/app/properties/ApplicationResources_en_US.properties +1 -1
- package/templates/app/app/properties/i18nkeys.json +3 -3
- package/templates/app/docs/all.html +69 -69
- package/templates/app/mockapi/index.js +18 -18
- package/templates/app/package.json +37 -37
- package/templates/app/src/actions/SampleActions/index.js +37 -37
- package/templates/app/src/actions/index.js +65 -65
- package/templates/app/src/appUrls.js +19 -19
- package/templates/app/src/components/Alert/Alert.js +134 -134
- package/templates/app/src/components/Alert/Alert.module.css +79 -79
- package/templates/app/src/components/FreezeLayer/FreezeLayer.css +37 -37
- package/templates/app/src/components/FreezeLayer/FreezeLayer.js +84 -84
- package/templates/app/src/components/Sample/Sample.module.css +11 -11
- package/templates/app/src/components/Sample/SampleList.js +61 -61
- package/templates/app/src/components/Slider/Slider.css +41 -41
- package/templates/app/src/components/Slider/Slider.js +55 -55
- package/templates/app/src/containers/AlertContainer/index.js +15 -15
- package/templates/app/src/containers/AppContainer/index.js +96 -96
- package/templates/app/src/containers/AppContainer/index.module.css +27 -27
- package/templates/app/src/containers/CustomMatch/index.js +65 -65
- package/templates/app/src/containers/DevTools/index.js +10 -10
- package/templates/app/src/containers/Header/index.js +67 -67
- package/templates/app/src/containers/Header/index.module.css +43 -43
- package/templates/app/src/containers/Redirect/index.js +63 -63
- package/templates/app/src/containers/Redirector/index.js +47 -47
- package/templates/app/src/containers/SampleListContainer/ListContainer.js +42 -42
- package/templates/app/src/containers/SampleListContainer/ListContainer.module.css +3 -3
- package/templates/app/src/historyChange.js +5 -5
- package/templates/app/src/index.html +10 -10
- package/templates/app/src/index.js +24 -24
- package/templates/app/src/middleware/PromiseMiddleware.js +59 -59
- package/templates/app/src/reducers/alertData.js +11 -11
- package/templates/app/src/reducers/index.js +6 -6
- package/templates/app/src/reducers/samples.js +19 -19
- package/templates/app/src/store/configureStore.dev.js +51 -51
- package/templates/app/src/store/configureStore.js +5 -5
- package/templates/app/src/store/configureStore.prod.js +26 -26
- package/templates/app/src/util/Common.js +5 -5
- package/templates/app/src/util/RequestAPI.js +132 -132
- package/templates/docs/all.html +249 -249
- package/templates/docs/component.html +178 -178
- package/templates/docs/components.html +221 -221
- package/templates/docs/css/b.min.css +6 -6
- package/templates/docs/css/component.css +42 -42
- package/templates/docs/css/componentTest.css +6 -6
- package/templates/docs/css/hopscotch.css +585 -585
- package/templates/docs/css/style.css +1022 -1022
- package/templates/docs/index.html +1493 -1493
- package/templates/docs/js/active-line.js +72 -72
- package/templates/docs/js/b.min.js +7 -7
- package/templates/docs/js/codemirror.js +9680 -9680
- package/templates/docs/js/designTokens.js +334 -334
- package/templates/docs/js/j.min.js +4 -4
- package/templates/docs/js/javascript.js +874 -874
- package/templates/docs/js/matchbrackets.js +145 -145
@@ -1,335 +1,226 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
+
exports.default = void 0;
|
6
7
|
|
7
|
-
var
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
8
9
|
|
9
|
-
var
|
10
|
+
var _webpackSources = require("webpack-sources");
|
10
11
|
|
11
|
-
var
|
12
|
-
|
13
|
-
var _path2 = _interopRequireDefault(_path);
|
14
|
-
|
15
|
-
var _webpackSources = require('webpack-sources');
|
16
|
-
|
17
|
-
var _utils = require('../utils');
|
12
|
+
var _utils = require("../utils");
|
18
13
|
|
19
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
20
15
|
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
const MODULE_TYPE = 'css/mini-extract';
|
17
|
+
let {
|
18
|
+
chunkSplitEnable
|
19
|
+
} = (0, _utils.getOptions)().i18n || {};
|
24
20
|
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
let filenameParser = filename => {
|
22
|
+
let filepaths = filename.split('/');
|
23
|
+
let hashedName = filepaths[filepaths.length - 1];
|
28
24
|
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
let {
|
26
|
+
name,
|
27
|
+
ext
|
28
|
+
} = _path.default.parse(hashedName);
|
32
29
|
|
33
|
-
|
30
|
+
let nameparts = name.split('.');
|
34
31
|
return {
|
35
32
|
name: nameparts.slice(0, nameparts.length - 1).join('.') + ext,
|
36
|
-
hashedName
|
37
|
-
ext
|
33
|
+
hashedName,
|
34
|
+
ext
|
38
35
|
};
|
39
36
|
};
|
40
37
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
_classCallCheck(this, PublicPathChangePlugin);
|
47
|
-
|
38
|
+
class PublicPathChangePlugin {
|
39
|
+
constructor({
|
40
|
+
publicPaths,
|
41
|
+
resourceHints
|
42
|
+
}) {
|
48
43
|
if (Array.isArray(publicPaths)) {
|
49
|
-
|
50
|
-
_publicPaths2 = _slicedToArray(_publicPaths, 5),
|
51
|
-
js = _publicPaths2[0],
|
52
|
-
css = _publicPaths2[1],
|
53
|
-
image = _publicPaths2[2],
|
54
|
-
font = _publicPaths2[3],
|
55
|
-
i18njs = _publicPaths2[4];
|
56
|
-
//eslint-disable-next-line
|
57
|
-
|
44
|
+
let [js, css, image, font, i18njs] = publicPaths; //eslint-disable-next-line
|
58
45
|
|
59
46
|
publicPaths = {
|
60
|
-
__REACT_CLI_PUBLIC_PATHS__: {
|
47
|
+
__REACT_CLI_PUBLIC_PATHS__: {
|
48
|
+
js,
|
49
|
+
css,
|
50
|
+
image,
|
51
|
+
font,
|
52
|
+
i18njs
|
53
|
+
}
|
61
54
|
};
|
62
55
|
}
|
56
|
+
|
63
57
|
this.publicPaths = publicPaths;
|
64
58
|
this.resourceHints = resourceHints;
|
65
59
|
}
|
66
60
|
|
67
|
-
|
68
|
-
|
69
|
-
value: function getCssChunkObject(mainChunk) {
|
70
|
-
var obj = {};
|
71
|
-
var _iteratorNormalCompletion = true;
|
72
|
-
var _didIteratorError = false;
|
73
|
-
var _iteratorError = undefined;
|
74
|
-
|
75
|
-
try {
|
76
|
-
for (var _iterator = mainChunk.getAllAsyncChunks()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
77
|
-
var chunk = _step.value;
|
78
|
-
var _iteratorNormalCompletion2 = true;
|
79
|
-
var _didIteratorError2 = false;
|
80
|
-
var _iteratorError2 = undefined;
|
81
|
-
|
82
|
-
try {
|
83
|
-
for (var _iterator2 = chunk.modulesIterable[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
84
|
-
var module = _step2.value;
|
85
|
-
|
86
|
-
if (module.type === MODULE_TYPE) {
|
87
|
-
obj[chunk.id] = 1;
|
88
|
-
break;
|
89
|
-
}
|
90
|
-
}
|
91
|
-
} catch (err) {
|
92
|
-
_didIteratorError2 = true;
|
93
|
-
_iteratorError2 = err;
|
94
|
-
} finally {
|
95
|
-
try {
|
96
|
-
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
97
|
-
_iterator2.return();
|
98
|
-
}
|
99
|
-
} finally {
|
100
|
-
if (_didIteratorError2) {
|
101
|
-
throw _iteratorError2;
|
102
|
-
}
|
103
|
-
}
|
104
|
-
}
|
105
|
-
}
|
106
|
-
} catch (err) {
|
107
|
-
_didIteratorError = true;
|
108
|
-
_iteratorError = err;
|
109
|
-
} finally {
|
110
|
-
try {
|
111
|
-
if (!_iteratorNormalCompletion && _iterator.return) {
|
112
|
-
_iterator.return();
|
113
|
-
}
|
114
|
-
} finally {
|
115
|
-
if (_didIteratorError) {
|
116
|
-
throw _iteratorError;
|
117
|
-
}
|
118
|
-
}
|
119
|
-
}
|
61
|
+
getCssChunkObject(mainChunk) {
|
62
|
+
const obj = {};
|
120
63
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
var _iteratorNormalCompletion3 = true;
|
127
|
-
var _didIteratorError3 = false;
|
128
|
-
var _iteratorError3 = undefined;
|
129
|
-
|
130
|
-
try {
|
131
|
-
for (var _iterator3 = chunk.groupsIterable[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
132
|
-
var chunkGroup = _step3.value;
|
133
|
-
|
134
|
-
if (chunkGroup.getNumberOfChildren() > 0) {
|
135
|
-
return true;
|
136
|
-
}
|
137
|
-
}
|
138
|
-
} catch (err) {
|
139
|
-
_didIteratorError3 = true;
|
140
|
-
_iteratorError3 = err;
|
141
|
-
} finally {
|
142
|
-
try {
|
143
|
-
if (!_iteratorNormalCompletion3 && _iterator3.return) {
|
144
|
-
_iterator3.return();
|
145
|
-
}
|
146
|
-
} finally {
|
147
|
-
if (_didIteratorError3) {
|
148
|
-
throw _iteratorError3;
|
149
|
-
}
|
64
|
+
for (const chunk of mainChunk.getAllAsyncChunks()) {
|
65
|
+
for (const module of chunk.modulesIterable) {
|
66
|
+
if (module.type === MODULE_TYPE) {
|
67
|
+
obj[chunk.id] = 1;
|
68
|
+
break;
|
150
69
|
}
|
151
70
|
}
|
71
|
+
}
|
152
72
|
|
153
|
-
|
73
|
+
return obj;
|
74
|
+
}
|
75
|
+
|
76
|
+
needChunkOnDemandLoadingCode(chunk) {
|
77
|
+
for (const chunkGroup of chunk.groupsIterable) {
|
78
|
+
if (chunkGroup.getNumberOfChildren() > 0) {
|
79
|
+
return true;
|
80
|
+
}
|
154
81
|
}
|
155
|
-
}, {
|
156
|
-
key: 'getResourceHints',
|
157
|
-
value: function getResourceHints(resourceHints, manifest, publicPaths) {
|
158
|
-
var ruleMapping = {};
|
159
|
-
var validFiles = Object.keys(manifest).filter(function (filename) {
|
160
|
-
var isValidFile = false;
|
161
|
-
var _iteratorNormalCompletion4 = true;
|
162
|
-
var _didIteratorError4 = false;
|
163
|
-
var _iteratorError4 = undefined;
|
164
|
-
|
165
|
-
try {
|
166
|
-
for (var _iterator4 = resourceHints[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
167
|
-
var pattern = _step4.value;
|
168
|
-
|
169
|
-
if (typeof pattern === 'string') {
|
170
|
-
isValidFile = new RegExp(pattern).test(filename);
|
171
|
-
} else {
|
172
|
-
isValidFile = new RegExp(pattern.pattern).test(filename);
|
173
|
-
}
|
174
|
-
if (isValidFile) {
|
175
|
-
ruleMapping[filename] = typeof pattern !== 'string' ? pattern : {};
|
176
|
-
break;
|
177
|
-
}
|
178
|
-
}
|
179
|
-
} catch (err) {
|
180
|
-
_didIteratorError4 = true;
|
181
|
-
_iteratorError4 = err;
|
182
|
-
} finally {
|
183
|
-
try {
|
184
|
-
if (!_iteratorNormalCompletion4 && _iterator4.return) {
|
185
|
-
_iterator4.return();
|
186
|
-
}
|
187
|
-
} finally {
|
188
|
-
if (_didIteratorError4) {
|
189
|
-
throw _iteratorError4;
|
190
|
-
}
|
191
|
-
}
|
192
|
-
}
|
193
82
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
var rules = ruleMapping[file];
|
209
|
-
resourceHintsContent += '<link rel=' + (rules.hint || 'preload') + ' href=\'' + (publicPaths[fileType] + filename) + '\'' + (rules.hint === 'prefetch' ? '' : 'as=\'' + fileType + '\' crossorigin=\'' + (rules.crossorigin || 'false') + '\'') + ' />';
|
83
|
+
return false;
|
84
|
+
}
|
85
|
+
|
86
|
+
getResourceHints(resourceHints, manifest, publicPaths) {
|
87
|
+
let ruleMapping = {};
|
88
|
+
let validFiles = Object.keys(manifest).filter(filename => {
|
89
|
+
let isValidFile = false;
|
90
|
+
|
91
|
+
for (let pattern of resourceHints) {
|
92
|
+
if (typeof pattern === 'string') {
|
93
|
+
isValidFile = new RegExp(pattern).test(filename);
|
94
|
+
} else {
|
95
|
+
isValidFile = new RegExp(pattern.pattern).test(filename);
|
210
96
|
}
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
try {
|
216
|
-
if (!_iteratorNormalCompletion5 && _iterator5.return) {
|
217
|
-
_iterator5.return();
|
218
|
-
}
|
219
|
-
} finally {
|
220
|
-
if (_didIteratorError5) {
|
221
|
-
throw _iteratorError5;
|
222
|
-
}
|
97
|
+
|
98
|
+
if (isValidFile) {
|
99
|
+
ruleMapping[filename] = typeof pattern !== 'string' ? pattern : {};
|
100
|
+
break;
|
223
101
|
}
|
224
102
|
}
|
225
103
|
|
226
|
-
return
|
104
|
+
return isValidFile;
|
105
|
+
});
|
106
|
+
let resourceHintsContent = '';
|
107
|
+
|
108
|
+
for (let file of validFiles) {
|
109
|
+
let {
|
110
|
+
fileType,
|
111
|
+
filename
|
112
|
+
} = manifest[file];
|
113
|
+
let rules = ruleMapping[file];
|
114
|
+
resourceHintsContent += `<link rel=${rules.hint || 'preload'} href='${publicPaths[fileType] + filename}'${rules.hint === 'prefetch' ? '' : `as='${fileType}' crossorigin='${rules.crossorigin || 'false'}'`} />`;
|
227
115
|
}
|
228
|
-
}, {
|
229
|
-
key: 'apply',
|
230
|
-
value: function apply(compiler) {
|
231
|
-
var _this = this;
|
232
|
-
|
233
|
-
compiler.hooks.thisCompilation.tap('PublicPathChangePlugin', function (compilation) {
|
234
|
-
compilation.mainTemplate.hooks.requireEnsure.tap('PublicPathChangePlugin', function (source, chunk) {
|
235
|
-
var chunkMap = _this.getCssChunkObject(chunk);
|
236
|
-
if (Object.keys(chunkMap).length > 0) {
|
237
|
-
return source.replace('__webpack_require__.p', '__REACT_CLI_CSS_PUBLIC_PATH__');
|
238
|
-
}
|
239
|
-
});
|
240
|
-
});
|
241
116
|
|
242
|
-
|
243
|
-
|
244
|
-
if (_this.needChunkOnDemandLoadingCode(chunk)) {
|
245
|
-
return source.replace('__webpack_require__.p', '__REACT_CLI_JS_PUBLIC_PATH__');
|
246
|
-
}
|
247
|
-
});
|
248
|
-
});
|
249
|
-
|
250
|
-
compiler.hooks.emit.tap('PublicPathChangePlugin', function (compilation) {
|
251
|
-
var cdns = Object.keys(_this.publicPaths);
|
252
|
-
var stats = compilation.getStats().toJson();
|
253
|
-
|
254
|
-
var manifest = stats.assets.reduce(function (files, asset) {
|
255
|
-
var filename = asset.name;
|
256
|
-
|
257
|
-
var fileType = (0, _utils.getFileType)(filename);
|
258
|
-
if (fileType === 'image' || fileType === 'font') {
|
259
|
-
var _filenameParser = filenameParser(filename),
|
260
|
-
name = _filenameParser.name,
|
261
|
-
hashedName = _filenameParser.hashedName,
|
262
|
-
ext = _filenameParser.ext;
|
263
|
-
|
264
|
-
files[name] = { hashedName: hashedName, ext: ext, fileType: fileType, filename: filename };
|
265
|
-
}
|
266
|
-
return files;
|
267
|
-
}, {});
|
268
|
-
|
269
|
-
Object.keys(compilation.assets).forEach(function (filename) {
|
270
|
-
if (Array.isArray(cdns)) {
|
271
|
-
cdns.forEach(function (cdn) {
|
272
|
-
var source = compilation.assets[filename].source();
|
273
|
-
if (/\.css$/g.test(filename)) {
|
274
|
-
var publicPaths = _this.publicPaths[cdn];
|
275
|
-
source = (0, _utils.cssUrlReplacer)(source, publicPaths, manifest, cdn);
|
276
|
-
} else if (/\.js$/g.test(filename)) {
|
277
|
-
var _publicPaths$cdn = _this.publicPaths[cdn],
|
278
|
-
js = _publicPaths$cdn.js,
|
279
|
-
css = _publicPaths$cdn.css,
|
280
|
-
image = _publicPaths$cdn.image,
|
281
|
-
font = _publicPaths$cdn.font;
|
282
|
-
|
283
|
-
if (typeof source === 'string') {
|
284
|
-
source = source.replace(/__REACT_CLI_JS_PUBLIC_PATH__/g, '"' + js + '"');
|
285
|
-
source = source.replace(/__REACT_CLI_CSS_PUBLIC_PATH__/g, '"' + css + '"');
|
286
|
-
source = source.replace(/__REACT_CLI_IMAGE_PUBLIC_PATH__/g, '"' + image + '"');
|
287
|
-
source = source.replace(/__REACT_CLI_FONT_PUBLIC_PATH__/g, '"' + font + '"');
|
288
|
-
}
|
289
|
-
} else if (/\.html$/g.test(filename)) {
|
290
|
-
var _publicPaths$cdn2 = _this.publicPaths[cdn],
|
291
|
-
_js = _publicPaths$cdn2.js,
|
292
|
-
_css = _publicPaths$cdn2.css,
|
293
|
-
i18njs = _publicPaths$cdn2.i18njs;
|
294
|
-
|
295
|
-
|
296
|
-
source = source.replace(new RegExp('<script defer src="([^"]*)"', 'g'), function (match, arg) {
|
297
|
-
return match.replace(arg, _js + arg);
|
298
|
-
});
|
299
|
-
source = source.replace(new RegExp('<link href="([^"]*)"', 'g'), function (match, arg) {
|
300
|
-
return match.replace(arg, _css + arg);
|
301
|
-
});
|
117
|
+
return resourceHintsContent;
|
118
|
+
}
|
302
119
|
|
303
|
-
|
304
|
-
|
305
|
-
|
120
|
+
apply(compiler) {
|
121
|
+
compiler.hooks.thisCompilation.tap('PublicPathChangePlugin', compilation => {
|
122
|
+
compilation.mainTemplate.hooks.requireEnsure.tap('PublicPathChangePlugin', (source, chunk) => {
|
123
|
+
const chunkMap = this.getCssChunkObject(chunk);
|
306
124
|
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
125
|
+
if (Object.keys(chunkMap).length > 0) {
|
126
|
+
return source.replace('__webpack_require__.p', '__REACT_CLI_CSS_PUBLIC_PATH__');
|
127
|
+
}
|
128
|
+
});
|
129
|
+
});
|
130
|
+
compiler.hooks.compilation.tap('PublicPathChangePlugin', compilation => {
|
131
|
+
compilation.mainTemplate.hooks.localVars.tap('PublicPathChangePlugin', (source, chunk) => {
|
132
|
+
if (this.needChunkOnDemandLoadingCode(chunk)) {
|
133
|
+
return source.replace('__webpack_require__.p', '__REACT_CLI_JS_PUBLIC_PATH__');
|
134
|
+
}
|
135
|
+
});
|
136
|
+
});
|
137
|
+
compiler.hooks.emit.tap('PublicPathChangePlugin', compilation => {
|
138
|
+
let cdns = Object.keys(this.publicPaths);
|
139
|
+
let stats = compilation.getStats().toJson();
|
140
|
+
let manifest = stats.assets.reduce((files, asset) => {
|
141
|
+
let {
|
142
|
+
name: filename
|
143
|
+
} = asset;
|
144
|
+
let fileType = (0, _utils.getFileType)(filename);
|
145
|
+
|
146
|
+
if (fileType === 'image' || fileType === 'font') {
|
147
|
+
let {
|
148
|
+
name,
|
149
|
+
hashedName,
|
150
|
+
ext
|
151
|
+
} = filenameParser(filename);
|
152
|
+
files[name] = {
|
153
|
+
hashedName,
|
154
|
+
ext,
|
155
|
+
fileType,
|
156
|
+
filename
|
157
|
+
};
|
158
|
+
}
|
311
159
|
|
160
|
+
return files;
|
161
|
+
}, {});
|
162
|
+
Object.keys(compilation.assets).forEach(filename => {
|
163
|
+
if (Array.isArray(cdns)) {
|
164
|
+
cdns.forEach(cdn => {
|
165
|
+
let source = compilation.assets[filename].source();
|
166
|
+
|
167
|
+
if (/\.css$/g.test(filename)) {
|
168
|
+
let publicPaths = this.publicPaths[cdn];
|
169
|
+
source = (0, _utils.cssUrlReplacer)(source, publicPaths, manifest, cdn);
|
170
|
+
} else if (/\.js$/g.test(filename)) {
|
171
|
+
let {
|
172
|
+
js,
|
173
|
+
css,
|
174
|
+
image,
|
175
|
+
font
|
176
|
+
} = this.publicPaths[cdn];
|
177
|
+
|
178
|
+
if (typeof source === 'string') {
|
179
|
+
source = source.replace(/__REACT_CLI_JS_PUBLIC_PATH__/g, `"${js}"`);
|
180
|
+
source = source.replace(/__REACT_CLI_CSS_PUBLIC_PATH__/g, `"${css}"`);
|
181
|
+
source = source.replace(/__REACT_CLI_IMAGE_PUBLIC_PATH__/g, `"${image}"`);
|
182
|
+
source = source.replace(/__REACT_CLI_FONT_PUBLIC_PATH__/g, `"${font}"`);
|
183
|
+
}
|
184
|
+
} else if (/\.html$/g.test(filename)) {
|
185
|
+
let {
|
186
|
+
js,
|
187
|
+
css,
|
188
|
+
i18njs
|
189
|
+
} = this.publicPaths[cdn];
|
190
|
+
source = source.replace(new RegExp('<script defer src="([^"]*)"', 'g'), (match, arg) => match.replace(arg, js + arg));
|
191
|
+
source = source.replace(new RegExp('<link href="([^"]*)"', 'g'), (match, arg) => match.replace(arg, css + arg));
|
192
|
+
let [i18nStr] = source.match(/<!--I18nInfoToServer(.*?)I18nInfoToServer-->/gm);
|
193
|
+
|
194
|
+
if (i18nStr && !chunkSplitEnable) {
|
195
|
+
try {
|
196
|
+
let [i18nObj] = i18nStr.match(/{(.*?)}/gm);
|
312
197
|
i18nObj = JSON.parse(JSON.parse(JSON.stringify(i18nObj)));
|
313
|
-
Object.keys(i18nObj).forEach(
|
198
|
+
Object.keys(i18nObj).forEach(locale => {
|
314
199
|
i18nObj[locale] = i18njs + i18nObj[locale];
|
315
200
|
});
|
201
|
+
source = source.replace(/<!--I18nInfoToServer(.*?)I18nInfoToServer-->/gm, `<!--I18nInfoToServer${JSON.stringify(i18nObj)}I18nInfoToServer-->`);
|
202
|
+
} catch (e) {
|
203
|
+
// eslint-disable-next-line no-console
|
204
|
+
console.warn('may be I18nInfoToServer inside object was not valid make sure it is parseable by JSON.parse'); // eslint-disable-next-line no-console
|
316
205
|
|
317
|
-
|
318
|
-
}
|
319
|
-
if (Array.isArray(_this.resourceHints) && _this.resourceHints.length) {
|
320
|
-
var resourceHintsContent = _this.getResourceHints(_this.resourceHints, manifest, _this.publicPaths[cdn]);
|
321
|
-
source = source.replace(/<\/head>/g, resourceHintsContent + '</head>');
|
206
|
+
console.warn(e);
|
322
207
|
}
|
323
208
|
}
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
209
|
+
|
210
|
+
if (Array.isArray(this.resourceHints) && this.resourceHints.length) {
|
211
|
+
let resourceHintsContent = this.getResourceHints(this.resourceHints, manifest, this.publicPaths[cdn]);
|
212
|
+
source = source.replace(/<\/head>/g, `${resourceHintsContent}</head>`);
|
213
|
+
}
|
214
|
+
}
|
215
|
+
|
216
|
+
compilation.assets[cdn === '__REACT_CLI_PUBLIC_PATHS__' ? filename : `${cdn}/${filename}`] = new _webpackSources.RawSource(source);
|
217
|
+
});
|
218
|
+
}
|
328
219
|
});
|
329
|
-
}
|
330
|
-
}
|
220
|
+
});
|
221
|
+
}
|
331
222
|
|
332
|
-
|
333
|
-
}();
|
223
|
+
}
|
334
224
|
|
335
|
-
|
225
|
+
var _default = PublicPathChangePlugin;
|
226
|
+
exports.default = _default;
|