@zohodesk/react-cli 0.0.1-beta.16 → 0.0.1-beta.160
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/.eslintignore +1 -0
- package/.eslintrc.js +46 -3
- package/CHANGELOG.md +5 -0
- package/README.md +650 -0
- package/bin/cli.js +134 -27
- package/cert/cert.pem +37 -129
- package/cert/key.pem +27 -27
- package/cert/passphrase.pem +1 -0
- package/files/eslintrc.js +62 -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 +33 -24
- package/lib/common/getPublicPathConfig.js +40 -0
- package/lib/common/index.js +27 -13
- package/lib/common/splitChunks.js +64 -26
- package/lib/common/sslcertUpdater.js +59 -0
- package/lib/common/templateParameters.js +25 -0
- package/lib/configs/jest.config.js +18 -28
- package/lib/configs/webpack.component.umd.config.js +31 -37
- package/lib/configs/webpack.css.umd.config.js +44 -44
- package/lib/configs/webpack.dev.config.js +113 -57
- package/lib/configs/webpack.docs.config.js +104 -98
- package/lib/configs/webpack.impact.config.js +116 -0
- package/lib/configs/webpack.prod.config.js +154 -86
- package/lib/hooks/docsProptypeHook.js +32 -38
- package/lib/jest/commitedFilesResult.js +144 -71
- package/lib/jest/coverageCollector.js +62 -29
- package/lib/jest/jsonMaker.js +54 -0
- package/lib/jest/preProcessors/cssPreprocessor.js +16 -18
- package/lib/jest/preProcessors/jsPreprocessor.js +5 -6
- package/lib/jest/preProcessors/otherFilesPreprocessor.js +5 -6
- package/lib/jest/result.js +91 -41
- package/lib/jest/run.js +74 -27
- package/lib/jest/setup.js +103 -102
- package/lib/loaderUtils/getCSSLoaders.js +77 -0
- package/lib/loaderUtils/getDevJsLoaders.js +30 -23
- package/lib/loaderUtils/index.js +14 -7
- package/lib/loaders/docsLoader.js +15 -15
- package/lib/loaders/docsPropsLoader.js +14 -17
- package/lib/loaders/fileBountryLoader.js +17 -0
- package/lib/loaders/fileLoader.js +47 -38
- package/lib/loaders/scriptInstrumentLoader.js +21 -20
- package/lib/loaders/selectorMappingLoader.js +75 -0
- package/lib/loaders/workerLoader.js +136 -0
- package/lib/middlewares/HMRMiddleware.js +59 -41
- package/lib/middlewares/SSTMiddleware.js +21 -0
- package/lib/pluginUtils/getDevPlugins.js +173 -26
- package/lib/pluginUtils/getDocsPlugins.js +32 -17
- package/lib/pluginUtils/getLibraryImactPlugins.js +23 -0
- package/lib/pluginUtils/getLibraryPlugins.js +8 -10
- package/lib/pluginUtils/getProdPlugins.js +238 -37
- 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 +77 -0
- package/lib/plugins/CleanupStatsPlugin.js +28 -0
- package/lib/plugins/EFCPlugin.js +211 -0
- package/lib/plugins/EFCPlugin.md +6 -0
- package/lib/plugins/I18NInjectIntoIndexPlugin.js +141 -0
- 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 +98 -97
- package/lib/plugins/OptimizeJSPlugin.js +24 -41
- package/lib/plugins/PublicPathCallbackPlugin.js +63 -0
- package/lib/plugins/PublicPathChangePlugin.js +187 -174
- package/lib/plugins/ReportGeneratePlugin.js +181 -0
- package/lib/plugins/RequireVariablePublicPlugin.js +30 -0
- package/lib/plugins/ResourceHintsPlugin.js +53 -35
- package/lib/plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +80 -0
- package/lib/plugins/RtlSplitPlugin/RtlCssPlugin.js +82 -0
- package/lib/plugins/RtlSplitPlugin/RtrSplit.md +30 -0
- package/lib/plugins/RtlSplitPlugin/replaceCssDirTemplate.js +26 -0
- package/lib/plugins/ScriptInstrumentPlugin.js +22 -37
- package/lib/plugins/ServiceWorkerPlugin.js +107 -0
- package/lib/plugins/ShadowDOMSupportPlugin.js +270 -0
- package/lib/plugins/SourceMapHookPlugin.js +25 -31
- package/lib/plugins/TPHashMappingPlugin.js +67 -0
- package/lib/plugins/UglifyCSSPlugin.js +23 -30
- package/lib/plugins/UnusedFilesFindPlugin.js +150 -97
- package/lib/plugins/index.js +118 -55
- package/lib/plugins/libraryImpactPlugin.js +190 -0
- package/lib/plugins/webpackwatchrunplugin.js +26 -0
- package/lib/postcss-plugins/ExcludeRTLPlugin.js +23 -0
- package/lib/postcss-plugins/RTLSplitPlugin.js +138 -0
- package/lib/schemas/index.js +463 -52
- package/lib/servers/clusterHubServer.js +22 -26
- package/lib/servers/docsServer.js +3 -5
- package/lib/servers/docsServerCore.js +93 -85
- package/lib/servers/helpServer.js +19 -21
- package/lib/servers/httpsOptions.js +19 -0
- package/lib/servers/impactServer.js +99 -92
- package/lib/servers/mockserver.js +44 -0
- package/lib/servers/nowatchserver.js +275 -0
- package/lib/servers/scrServer.js +147 -0
- package/lib/servers/server.js +118 -124
- package/lib/servers/ssServer.js +107 -65
- package/lib/sh/reportPublish.sh +16 -10
- package/lib/templates/CoverageScriptTemplate.js +45 -18
- package/lib/templates/WMSTemplate.js +17 -18
- package/lib/templates/linterConstant.js +10 -0
- package/lib/utils/babelPresets.js +12 -5
- package/lib/utils/buildstats.html +148 -0
- package/lib/utils/clean.js +12 -11
- package/lib/utils/copy.js +13 -127
- package/lib/utils/copyTimezones.js +21 -0
- package/lib/utils/createEventStream.js +24 -19
- package/lib/utils/cssClassNameGenerate.js +70 -0
- package/lib/utils/cssURLReplacer.js +67 -54
- package/lib/utils/dependencyPostPublish.js +42 -0
- package/lib/utils/fileUtils.js +125 -0
- package/lib/utils/folderIterator.js +47 -0
- package/lib/utils/getComponents.js +126 -0
- package/lib/utils/getCurrentBranch.js +11 -17
- package/lib/utils/getDependenciesImpactList.js +151 -0
- package/lib/utils/getHash.js +26 -0
- package/lib/utils/getIp.js +20 -0
- package/lib/utils/getOptions.js +55 -30
- package/lib/utils/getServerURL.js +25 -8
- package/lib/utils/index.js +259 -82
- package/lib/utils/init.js +2 -2
- package/lib/utils/initPreCommitHook.js +40 -31
- package/lib/utils/jsonHelper.js +97 -0
- package/lib/utils/libraryImpactConfig.js +63 -0
- 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 +142 -0
- package/lib/utils/mailSender.js +16 -25
- package/lib/utils/pullOrigin.js +28 -0
- package/lib/utils/reinstallDependencies.js +133 -0
- package/lib/utils/removeAttributes.js +25 -23
- package/lib/utils/repoClone.js +56 -63
- package/lib/utils/request.js +64 -77
- package/lib/utils/resultSchema.json +73 -0
- package/lib/utils/rtl.js +42 -0
- package/lib/utils/setEnvVariables.js +5 -6
- package/lib/utils/ssTestHack.js +48 -0
- package/lib/utils/switchBranch.js +28 -0
- package/lib/utils/urlConcat.js +22 -0
- package/package.json +92 -64
- package/templates/app/.eslintrc.js +140 -0
- package/templates/app/README.md +12 -12
- package/templates/app/app/index.html +24 -8
- 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 -13
- package/templates/app/package.json +37 -17
- package/templates/app/src/actions/SampleActions/index.js +37 -0
- package/templates/app/src/actions/index.js +65 -0
- package/templates/app/src/appUrls.js +19 -0
- package/templates/app/src/components/Alert/Alert.js +134 -0
- package/templates/app/src/components/Alert/Alert.module.css +79 -0
- package/templates/app/src/components/FreezeLayer/FreezeLayer.css +37 -0
- package/templates/app/src/components/FreezeLayer/FreezeLayer.js +84 -0
- package/templates/app/src/components/Sample/Sample.module.css +11 -0
- package/templates/app/src/components/Sample/SampleList.js +61 -0
- package/templates/app/src/components/Slider/Slider.css +41 -0
- package/templates/app/src/components/Slider/Slider.js +55 -0
- package/templates/app/src/containers/AlertContainer/index.js +15 -0
- package/templates/app/src/containers/AppContainer/index.js +96 -0
- package/templates/app/src/containers/AppContainer/index.module.css +27 -0
- package/templates/app/src/containers/CustomMatch/index.js +65 -0
- package/templates/app/src/containers/DevTools/index.js +10 -0
- package/templates/app/src/containers/Header/index.js +67 -0
- package/templates/app/src/containers/Header/index.module.css +43 -0
- package/templates/app/src/containers/Redirect/index.js +63 -0
- package/templates/app/src/containers/Redirector/index.js +47 -0
- package/templates/app/src/containers/SampleListContainer/ListContainer.js +42 -0
- package/templates/app/src/containers/SampleListContainer/ListContainer.module.css +3 -0
- package/templates/app/src/historyChange.js +5 -0
- package/templates/app/src/index.html +10 -0
- package/templates/app/src/index.js +24 -0
- package/templates/app/src/middleware/PromiseMiddleware.js +59 -0
- package/templates/app/src/reducers/alertData.js +11 -0
- package/templates/app/src/reducers/index.js +6 -0
- package/templates/app/src/reducers/samples.js +19 -0
- package/templates/app/src/store/configureStore.dev.js +51 -0
- package/templates/app/src/store/configureStore.js +5 -0
- package/templates/app/src/store/configureStore.prod.js +26 -0
- package/templates/app/src/util/Common.js +5 -0
- package/templates/app/src/util/RequestAPI.js +132 -0
- package/templates/appold/README.md +12 -0
- package/templates/appold/app/index.html +8 -0
- package/templates/appold/app/properties/ApplicationResources_en_US.properties +1 -0
- package/templates/appold/app/properties/i18nkeys.json +3 -0
- package/templates/appold/docs/all.html +69 -0
- package/templates/appold/mockapi/index.js +13 -0
- package/templates/{app → appold}/mockapi/tickets.json +0 -0
- package/templates/appold/package.json +17 -0
- package/templates/appold/src/components/Text/Text.css +0 -0
- package/templates/appold/src/components/Text/Text.js +23 -0
- package/templates/appold/src/components/Text/__tests__/Text.spec.js +30 -0
- package/templates/appold/src/components/Text/docs/Text__default.docs.js +16 -0
- package/templates/appold/src/components/docs.js +1 -0
- package/templates/appold/src/components/index.js +5 -0
- package/templates/appold/src/index.js +13 -0
- package/templates/docs/all.html +1 -1
- package/templates/docs/component.html +110 -69
- package/templates/docs/components.html +221 -0
- package/templates/docs/css/component.css +12 -14
- package/templates/docs/css/componentTest.css +7 -0
- package/templates/docs/css/style.css +150 -206
- package/templates/docs/impactReportTemplate.html +154 -0
- package/templates/docs/index.html +1482 -1336
- package/templates/library/src/index.js +0 -0
@@ -1,213 +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
|
-
|
16
|
+
const MODULE_TYPE = 'css/mini-extract';
|
17
|
+
let {
|
18
|
+
chunkSplitEnable
|
19
|
+
} = (0, _utils.getOptions)().i18n || {};
|
22
20
|
|
23
|
-
|
21
|
+
let filenameParser = filename => {
|
22
|
+
let filepaths = filename.split('/');
|
23
|
+
let hashedName = filepaths[filepaths.length - 1];
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
let {
|
26
|
+
name,
|
27
|
+
ext
|
28
|
+
} = _path.default.parse(hashedName);
|
28
29
|
|
29
|
-
|
30
|
-
name = _path$parse.name,
|
31
|
-
ext = _path$parse.ext;
|
32
|
-
|
33
|
-
var nameparts = name.split('.');
|
30
|
+
let nameparts = name.split('.');
|
34
31
|
return {
|
35
32
|
name: nameparts.slice(0, nameparts.length - 1).join('.') + ext,
|
36
|
-
hashedName
|
33
|
+
hashedName,
|
34
|
+
ext
|
37
35
|
};
|
38
36
|
};
|
39
37
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
38
|
+
class PublicPathChangePlugin {
|
39
|
+
constructor({
|
40
|
+
publicPaths,
|
41
|
+
resourceHints
|
42
|
+
}) {
|
46
43
|
if (Array.isArray(publicPaths)) {
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
44
|
+
let [js, css, image, font, i18njs] = publicPaths; //eslint-disable-next-line
|
45
|
+
|
46
|
+
publicPaths = {
|
47
|
+
__REACT_CLI_PUBLIC_PATHS__: {
|
48
|
+
js,
|
49
|
+
css,
|
50
|
+
image,
|
51
|
+
font,
|
52
|
+
i18njs
|
53
|
+
}
|
54
|
+
};
|
55
55
|
}
|
56
|
+
|
56
57
|
this.publicPaths = publicPaths;
|
58
|
+
this.resourceHints = resourceHints;
|
57
59
|
}
|
58
60
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
try {
|
68
|
-
for (var _iterator = mainChunk.getAllAsyncChunks()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
69
|
-
var chunk = _step.value;
|
70
|
-
var _iteratorNormalCompletion2 = true;
|
71
|
-
var _didIteratorError2 = false;
|
72
|
-
var _iteratorError2 = undefined;
|
73
|
-
|
74
|
-
try {
|
75
|
-
for (var _iterator2 = chunk.modulesIterable[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
76
|
-
var module = _step2.value;
|
77
|
-
|
78
|
-
if (module.type === MODULE_TYPE) {
|
79
|
-
obj[chunk.id] = 1;
|
80
|
-
break;
|
81
|
-
}
|
82
|
-
}
|
83
|
-
} catch (err) {
|
84
|
-
_didIteratorError2 = true;
|
85
|
-
_iteratorError2 = err;
|
86
|
-
} finally {
|
87
|
-
try {
|
88
|
-
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
89
|
-
_iterator2.return();
|
90
|
-
}
|
91
|
-
} finally {
|
92
|
-
if (_didIteratorError2) {
|
93
|
-
throw _iteratorError2;
|
94
|
-
}
|
95
|
-
}
|
96
|
-
}
|
97
|
-
}
|
98
|
-
} catch (err) {
|
99
|
-
_didIteratorError = true;
|
100
|
-
_iteratorError = err;
|
101
|
-
} finally {
|
102
|
-
try {
|
103
|
-
if (!_iteratorNormalCompletion && _iterator.return) {
|
104
|
-
_iterator.return();
|
105
|
-
}
|
106
|
-
} finally {
|
107
|
-
if (_didIteratorError) {
|
108
|
-
throw _iteratorError;
|
109
|
-
}
|
61
|
+
getCssChunkObject(mainChunk) {
|
62
|
+
const obj = {};
|
63
|
+
|
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;
|
110
69
|
}
|
111
70
|
}
|
71
|
+
}
|
72
|
+
|
73
|
+
return obj;
|
74
|
+
}
|
112
75
|
|
113
|
-
|
76
|
+
needChunkOnDemandLoadingCode(chunk) {
|
77
|
+
for (const chunkGroup of chunk.groupsIterable) {
|
78
|
+
if (chunkGroup.getNumberOfChildren() > 0) {
|
79
|
+
return true;
|
80
|
+
}
|
114
81
|
}
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
82
|
+
|
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);
|
129
96
|
}
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
try {
|
135
|
-
if (!_iteratorNormalCompletion3 && _iterator3.return) {
|
136
|
-
_iterator3.return();
|
137
|
-
}
|
138
|
-
} finally {
|
139
|
-
if (_didIteratorError3) {
|
140
|
-
throw _iteratorError3;
|
141
|
-
}
|
97
|
+
|
98
|
+
if (isValidFile) {
|
99
|
+
ruleMapping[filename] = typeof pattern !== 'string' ? pattern : {};
|
100
|
+
break;
|
142
101
|
}
|
143
102
|
}
|
144
103
|
|
145
|
-
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'}'`} />`;
|
146
115
|
}
|
147
|
-
}, {
|
148
|
-
key: 'apply',
|
149
|
-
value: function apply(compiler) {
|
150
|
-
var _this = this;
|
151
|
-
|
152
|
-
compiler.hooks.thisCompilation.tap('PublicPathChangePlugin', function (compilation) {
|
153
|
-
compilation.mainTemplate.hooks.requireEnsure.tap('PublicPathChangePlugin', function (source, chunk) {
|
154
|
-
var chunkMap = _this.getCssChunkObject(chunk);
|
155
|
-
if (Object.keys(chunkMap).length > 0) {
|
156
|
-
return source.replace('__webpack_require__.p', '__REACT_CLI_CSS_PUBLIC_PATH__');
|
157
|
-
}
|
158
|
-
});
|
159
|
-
});
|
160
116
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
117
|
+
return resourceHintsContent;
|
118
|
+
}
|
119
|
+
|
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);
|
124
|
+
|
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
|
+
}
|
167
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
|
+
}
|
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);
|
197
|
+
i18nObj = JSON.parse(JSON.parse(JSON.stringify(i18nObj)));
|
198
|
+
Object.keys(i18nObj).forEach(locale => {
|
199
|
+
i18nObj[locale] = i18njs + i18nObj[locale];
|
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
|
205
|
+
|
206
|
+
console.warn(e);
|
207
|
+
}
|
208
|
+
}
|
168
209
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
var manifest = stats.assets.reduce(function (files, asset) {
|
174
|
-
var filename = asset.name;
|
175
|
-
|
176
|
-
var fileType = (0, _utils.getFileType)(filename);
|
177
|
-
if (fileType === 'image' || fileType === 'font') {
|
178
|
-
var _filenameParser = filenameParser(filename),
|
179
|
-
name = _filenameParser.name,
|
180
|
-
hashedName = _filenameParser.hashedName;
|
181
|
-
|
182
|
-
files[name] = hashedName;
|
183
|
-
}
|
184
|
-
return files;
|
185
|
-
}, {});
|
186
|
-
|
187
|
-
Object.keys(compilation.assets).forEach(function (filename) {
|
188
|
-
var source = compilation.assets[filename].source();
|
189
|
-
if (Array.isArray(cdns)) {
|
190
|
-
cdns.forEach(function (cdn) {
|
191
|
-
if (/\.css$/g.test(filename)) {
|
192
|
-
var publicPaths = _this.publicPaths[cdn];
|
193
|
-
source = (0, _utils.cssUrlReplacer)(source, publicPaths, manifest);
|
194
|
-
} else if (/\.js$/g.test(filename)) {
|
195
|
-
var _publicPaths$cdn = _this.publicPaths[cdn],
|
196
|
-
js = _publicPaths$cdn.js,
|
197
|
-
css = _publicPaths$cdn.css;
|
198
|
-
|
199
|
-
source = source.replace(/__REACT_CLI_JS_PUBLIC_PATH__/g, '"' + js + '"');
|
200
|
-
source = source.replace(/__REACT_CLI_CSS_PUBLIC_PATH__/g, '"' + css + '"');
|
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>`);
|
201
213
|
}
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
214
|
+
}
|
215
|
+
|
216
|
+
compilation.assets[cdn === '__REACT_CLI_PUBLIC_PATHS__' ? filename : `${cdn}/${filename}`] = new _webpackSources.RawSource(source);
|
217
|
+
});
|
218
|
+
}
|
206
219
|
});
|
207
|
-
}
|
208
|
-
}
|
220
|
+
});
|
221
|
+
}
|
209
222
|
|
210
|
-
|
211
|
-
}();
|
223
|
+
}
|
212
224
|
|
213
|
-
|
225
|
+
var _default = PublicPathChangePlugin;
|
226
|
+
exports.default = _default;
|
@@ -0,0 +1,181 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _fs = _interopRequireDefault(require("fs"));
|
9
|
+
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
11
|
+
|
12
|
+
var _redis = _interopRequireDefault(require("redis"));
|
13
|
+
|
14
|
+
var _utils = require("../utils");
|
15
|
+
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
|
+
|
18
|
+
let options = (0, _utils.getOptions)();
|
19
|
+
let {
|
20
|
+
app: {
|
21
|
+
branch,
|
22
|
+
redisHost,
|
23
|
+
redisPort
|
24
|
+
}
|
25
|
+
} = options;
|
26
|
+
|
27
|
+
class reportGeneratePlugin {
|
28
|
+
apply(compiler) {
|
29
|
+
compiler.hooks.emit.tapAsync('reportGeneratePlugin', (compilation, callback) => {
|
30
|
+
function formatBytes(bytes) {
|
31
|
+
if (bytes) {
|
32
|
+
let isNegative;
|
33
|
+
|
34
|
+
if (bytes < 0) {
|
35
|
+
bytes = bytes * -1; //eslint-disable-line
|
36
|
+
|
37
|
+
isNegative = true;
|
38
|
+
}
|
39
|
+
|
40
|
+
if (bytes < 1024) {
|
41
|
+
if (isNegative) {
|
42
|
+
return `- ${bytes} Bytes`;
|
43
|
+
}
|
44
|
+
|
45
|
+
return `${bytes} Bytes`;
|
46
|
+
} else if (bytes < 1048576) {
|
47
|
+
if (isNegative) {
|
48
|
+
return `- ${(bytes / 1024).toFixed(3)} KB`;
|
49
|
+
}
|
50
|
+
|
51
|
+
return `${(bytes / 1024).toFixed(3)} KB`;
|
52
|
+
} else if (bytes < 1073741824) {
|
53
|
+
if (isNegative) {
|
54
|
+
return `- ${(bytes / 1048576).toFixed(3)} MB`;
|
55
|
+
}
|
56
|
+
|
57
|
+
return `${(bytes / 1048576).toFixed(3)} MB`;
|
58
|
+
}
|
59
|
+
|
60
|
+
if (isNegative) {
|
61
|
+
return `- ${(bytes / 1073741824).toFixed(3)} GB`;
|
62
|
+
}
|
63
|
+
|
64
|
+
return `${(bytes / 1073741824).toFixed(3)} GB`;
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
let client = _redis.default.createClient(redisPort, redisHost);
|
69
|
+
|
70
|
+
client.on('connect', () => {
|
71
|
+
(0, _utils.log)('Redis client connected');
|
72
|
+
});
|
73
|
+
client.on('error', err => {
|
74
|
+
(0, _utils.log)(`Something went wrong ${err}`);
|
75
|
+
});
|
76
|
+
|
77
|
+
if (_fs.default.existsSync(_path.default.resolve(process.cwd(), 'build', 'stats.json'))) {
|
78
|
+
let statsJSON = _fs.default.readFileSync(_path.default.resolve(process.cwd(), 'build', 'stats.json'), 'utf8');
|
79
|
+
|
80
|
+
statsJSON = JSON.parse(statsJSON);
|
81
|
+
let finalObj = {};
|
82
|
+
let branchName = branch ? branch : (0, _utils.getCurrentBranch)();
|
83
|
+
(0, _utils.log)(branchName);
|
84
|
+
statsJSON.assets.forEach(assetObj => {
|
85
|
+
let nameSplitList = assetObj.name.split('/')[assetObj.name.split('/').length - 1].split('.'); // eslint-disable-line
|
86
|
+
|
87
|
+
let [, hash] = nameSplitList;
|
88
|
+
let name = `${nameSplitList[0]}.${nameSplitList[2]}`;
|
89
|
+
let {
|
90
|
+
size
|
91
|
+
} = assetObj;
|
92
|
+
let tempObject = {
|
93
|
+
name,
|
94
|
+
hash,
|
95
|
+
size
|
96
|
+
}; // eslint-disable-next-line
|
97
|
+
|
98
|
+
if (!finalObj.hasOwnProperty(name)) {
|
99
|
+
finalObj[name] = tempObject;
|
100
|
+
}
|
101
|
+
});
|
102
|
+
client.exists(branchName, (err, bool) => {
|
103
|
+
if (!bool) {
|
104
|
+
client.set(branchName, JSON.stringify(finalObj), _redis.default.print);
|
105
|
+
client.quit();
|
106
|
+
} else {
|
107
|
+
let reportObj = {
|
108
|
+
increased: [],
|
109
|
+
hashChanged: [],
|
110
|
+
branchName
|
111
|
+
};
|
112
|
+
client.get(branchName, (err, reply) => {
|
113
|
+
if (err) {
|
114
|
+
(0, _utils.log)(err);
|
115
|
+
} else {
|
116
|
+
reply = JSON.parse(reply); // eslint-disable-line
|
117
|
+
|
118
|
+
Object.keys(reply).forEach(fileName => {
|
119
|
+
// eslint-disable-next-line
|
120
|
+
if (finalObj.hasOwnProperty(fileName)) {
|
121
|
+
if (parseInt(reply[fileName].size) < parseInt(finalObj[fileName].size)) {
|
122
|
+
reportObj.increased.push({
|
123
|
+
name: fileName,
|
124
|
+
size: {
|
125
|
+
old: formatBytes(reply[fileName].size),
|
126
|
+
new: formatBytes(finalObj[fileName].size),
|
127
|
+
diff: formatBytes(parseInt(finalObj[fileName].size) - parseInt(reply[fileName].size))
|
128
|
+
}
|
129
|
+
});
|
130
|
+
}
|
131
|
+
|
132
|
+
if (reply[fileName].hash !== finalObj[fileName].hash) {
|
133
|
+
reportObj.hashChanged.push({
|
134
|
+
name: fileName,
|
135
|
+
hash: {
|
136
|
+
old: reply[fileName].hash,
|
137
|
+
new: finalObj[fileName].hash
|
138
|
+
}
|
139
|
+
});
|
140
|
+
}
|
141
|
+
}
|
142
|
+
});
|
143
|
+
let json = JSON.stringify(reportObj);
|
144
|
+
|
145
|
+
_fs.default.writeFile(_path.default.resolve(process.cwd(), 'build', 'buildtrack.js'), `let statsJson=${json}`, err => {
|
146
|
+
if (err) {
|
147
|
+
throw err;
|
148
|
+
}
|
149
|
+
|
150
|
+
(0, _utils.log)('Stats Json generated!');
|
151
|
+
});
|
152
|
+
}
|
153
|
+
});
|
154
|
+
client.set(branchName, JSON.stringify(finalObj), _redis.default.print); // fs.copyFileSync(
|
155
|
+
// path.resolve(
|
156
|
+
// process.cwd(),
|
157
|
+
// 'node_modules',
|
158
|
+
// '@zohodesk',
|
159
|
+
// 'react-cli',
|
160
|
+
// 'lib',
|
161
|
+
// 'utils',
|
162
|
+
// 'buildstats.html'
|
163
|
+
// ),
|
164
|
+
// path.resolve(process.cwd(), 'build', 'buildstats.html')
|
165
|
+
// );
|
166
|
+
|
167
|
+
client.quit();
|
168
|
+
callback && callback();
|
169
|
+
}
|
170
|
+
|
171
|
+
if (err) {
|
172
|
+
(0, _utils.log)(err);
|
173
|
+
}
|
174
|
+
});
|
175
|
+
}
|
176
|
+
});
|
177
|
+
}
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
exports.default = reportGeneratePlugin;
|
@@ -0,0 +1,30 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
const {
|
9
|
+
Template
|
10
|
+
} = require('webpack');
|
11
|
+
|
12
|
+
const pluginName = 'RequireVariablePublicPlugin';
|
13
|
+
|
14
|
+
class RequireVariablePublicPlugin {
|
15
|
+
constructor(options) {
|
16
|
+
this.requireFuncName = options.requireFuncName;
|
17
|
+
}
|
18
|
+
|
19
|
+
apply(compiler) {
|
20
|
+
compiler.hooks.thisCompilation.tap(pluginName, ({
|
21
|
+
mainTemplate
|
22
|
+
}) => {
|
23
|
+
mainTemplate.hooks.requireExtensions.tap(pluginName, source => Template.asString([source, '', `window[${JSON.stringify(this.requireFuncName)}] = ${mainTemplate.requireFn};`]));
|
24
|
+
});
|
25
|
+
}
|
26
|
+
|
27
|
+
}
|
28
|
+
|
29
|
+
var _default = RequireVariablePublicPlugin;
|
30
|
+
exports.default = _default;
|