@zohodesk/react-cli 0.0.1-exp.175.1 → 0.0.1-exp.176.11
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +35 -40
- package/docs/SelectorWeight.md +6 -0
- package/docs/VariableConversion.md +33 -1
- package/lib/babel/cmjs-plugins-presets.js +4 -0
- package/lib/babel/es-plugins-presets.js +4 -0
- package/lib/common/getEntries.js +10 -0
- package/lib/common/getPublicPathConfig.js +6 -0
- package/lib/common/index.js +5 -0
- package/lib/common/splitChunks.js +13 -2
- package/lib/common/sslcertUpdater.js +17 -6
- package/lib/common/templateParameters.js +2 -0
- package/lib/common/testPattern.js +21 -10
- package/lib/common/valueReplacer.js +15 -0
- package/lib/configs/jest.config.js +9 -0
- package/lib/configs/libAlias.js +2 -4
- package/lib/configs/webpack.component.umd.config.js +5 -0
- package/lib/configs/webpack.css.umd.config.js +13 -5
- package/lib/configs/webpack.dev.config.js +36 -2
- package/lib/configs/webpack.docs.config.js +21 -1
- package/lib/configs/webpack.impact.config.js +19 -1
- package/lib/configs/webpack.prod.config.js +37 -3
- package/lib/hooks/docsProptypeHook.js +7 -3
- package/lib/jest/commitedFilesResult.js +45 -3
- package/lib/jest/coverageCollector.js +11 -0
- package/lib/jest/jsonMaker.js +6 -0
- package/lib/jest/preProcessors/cssPreprocessor.js +8 -0
- package/lib/jest/preProcessors/jsPreprocessor.js +2 -0
- package/lib/jest/preProcessors/otherFilesPreprocessor.js +3 -0
- package/lib/jest/result.js +22 -0
- package/lib/jest/run.js +17 -6
- package/lib/jest/setup.js +57 -5
- package/lib/loaderUtils/configsAssetsLoaders.js +11 -1
- package/lib/loaderUtils/getCSSLoaders.js +35 -20
- package/lib/loaderUtils/getDevJsLoaders.js +8 -0
- package/lib/loaderUtils/index.js +3 -0
- package/lib/loaderUtils/windowsModification.js +11 -0
- package/lib/loaders/docsLoader.js +7 -0
- package/lib/loaders/docsPropsLoader.js +7 -3
- package/lib/loaders/fileBountryLoader.js +2 -0
- package/lib/loaders/fileLoader.js +22 -11
- package/lib/loaders/scriptInstrumentLoader.js +13 -5
- package/lib/loaders/selectorMappingLoader.js +25 -7
- package/lib/loaders/workerLoader.js +20 -4
- package/lib/middlewares/HMRMiddleware.js +26 -13
- package/lib/middlewares/SSTMiddleware.js +3 -0
- package/lib/pluginUtils/configHtmlWebpackPlugins.js +9 -3
- package/lib/pluginUtils/getDevPlugins.js +63 -17
- package/lib/pluginUtils/getDocsPlugins.js +10 -1
- package/lib/pluginUtils/getLibraryImactPlugins.js +5 -4
- package/lib/pluginUtils/getLibraryPlugins.js +5 -0
- package/lib/pluginUtils/getProdPlugins.js +72 -23
- package/lib/pluginUtils/getServerPlugins.js +5 -0
- package/lib/pluginUtils/getUMDCSSPlugins.js +7 -0
- package/lib/pluginUtils/getUMDComponentPlugins.js +7 -0
- package/lib/pluginUtils/index.js +8 -0
- package/lib/plugins/CdnChangePlugin.js +14 -0
- package/lib/plugins/CleanupStatsPlugin.js +5 -0
- package/lib/plugins/EFCPlugin.js +34 -23
- package/lib/plugins/EFCTemplatePlugin.js +32 -23
- package/lib/plugins/I18NInjectIntoIndexPlugin.js +34 -8
- package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +17 -12
- package/lib/plugins/I18nSplitPlugin/I18nDependency.js +10 -4
- package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +39 -8
- package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +29 -14
- package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +22 -13
- package/lib/plugins/I18nSplitPlugin/index.js +23 -13
- package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +12 -2
- package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +1 -0
- package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +5 -0
- package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +6 -0
- package/lib/plugins/I18nSplitPlugin/utils/index.js +4 -0
- package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +20 -2
- package/lib/plugins/ManifestPlugin.js +17 -0
- package/lib/plugins/ModuleStatsPlugin.js +23 -0
- package/lib/plugins/OptimizeJSPlugin.js +7 -0
- package/lib/plugins/PublicPathCallbackPlugin.js +10 -0
- package/lib/plugins/PublicPathChangePlugin.js +36 -4
- package/lib/plugins/ReportGeneratePlugin.js +30 -4
- package/lib/plugins/RequireVariablePublicPlugin.js +6 -0
- package/lib/plugins/ResourceHintsPlugin.js +10 -3
- package/lib/plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +17 -12
- package/lib/plugins/RtlSplitPlugin/RtlCssPlugin.js +16 -9
- package/lib/plugins/RtlSplitPlugin/replaceCssDirTemplate.js +5 -2
- package/lib/plugins/ScriptInstrumentPlugin.js +7 -0
- package/lib/plugins/SelectorPlugin.js +97 -0
- package/lib/plugins/ServiceWorkerPlugin.js +20 -4
- package/lib/plugins/ShadowDOMSupportPlugin.js +40 -3
- package/lib/plugins/SourceMapHookPlugin.js +9 -0
- package/lib/plugins/TPHashMappingPlugin.js +15 -1
- package/lib/plugins/UglifyCSSPlugin.js +9 -0
- package/lib/plugins/UnusedFilesFindPlugin.js +35 -2
- package/lib/plugins/VariableConversionCollector.js +252 -0
- package/lib/plugins/composeCommonPlugin.js +30 -0
- package/lib/plugins/index.js +19 -0
- package/lib/plugins/libraryImpactPlugin.js +32 -0
- package/lib/plugins/webpackwatchrunplugin.js +5 -0
- package/lib/postcss-plugins/ExcludePlugin.js +4 -0
- package/lib/postcss-plugins/RTLSplitPlugin.js +27 -14
- package/lib/postcss-plugins/ValueReplacer.js +6 -9
- package/lib/postcss-plugins/__test__/hoverActivePlugin.spec.js +3 -0
- package/lib/postcss-plugins/hoverActivePlugin.js +66 -30
- package/lib/postcss-plugins/variableModificationPlugin/ErrorHandler.js +40 -13
- package/lib/postcss-plugins/variableModificationPlugin/index.js +215 -141
- package/lib/postcss-plugins/variableModifier.js +20 -13
- package/lib/schemas/index.js +23 -4
- package/lib/servers/clusterHubServer.js +10 -0
- package/lib/servers/devBuild.js +24 -13
- package/lib/servers/docsServer.js +2 -0
- package/lib/servers/docsServerCore.js +21 -0
- package/lib/servers/getCliPath.js +9 -0
- package/lib/servers/helpServer.js +5 -0
- package/lib/servers/httpsOptions.js +4 -0
- package/lib/servers/impactServer.js +34 -2
- package/lib/servers/mockserver.js +9 -0
- package/lib/servers/nowatchserver.js +34 -12
- package/lib/servers/scrServer.js +20 -13
- package/lib/servers/server.js +35 -7
- package/lib/servers/ssServer.js +16 -0
- package/lib/templates/CoverageScriptTemplate.js +14 -0
- package/lib/templates/WMSTemplate.js +12 -6
- package/lib/utils/babelPresets.js +2 -0
- package/lib/utils/clean.js +8 -2
- package/lib/utils/copy.js +6 -0
- package/lib/utils/copyTimezones.js +8 -0
- package/lib/utils/createEventStream.js +4 -0
- package/lib/utils/cssClassNameGenerate.js +19 -3
- package/lib/utils/cssURLReplacer.js +50 -38
- package/lib/utils/dependencyPostPublish.js +9 -0
- package/lib/utils/fileUtils.js +26 -0
- package/lib/utils/folderIterator.js +10 -0
- package/lib/utils/getComponents.js +21 -0
- package/lib/utils/getCurrentBranch.js +5 -0
- package/lib/utils/getDependenciesImpactList.js +21 -0
- package/lib/utils/getFileType.js +49 -0
- package/lib/utils/getHash.js +7 -0
- package/lib/utils/getIp.js +2 -0
- package/lib/utils/getOptions.js +39 -14
- package/lib/utils/getServerURL.js +7 -0
- package/lib/utils/index.js +47 -2
- package/lib/utils/init.js +1 -0
- package/lib/utils/initPreCommitHook.js +29 -6
- package/lib/utils/jsonHelper.js +19 -2
- package/lib/utils/libraryImpactConfig.js +2 -0
- package/lib/utils/lint/addScripts.js +5 -2
- package/lib/utils/lint/checkExistingConfig.js +12 -3
- package/lib/utils/lint/copyConfigs.js +3 -0
- package/lib/utils/lint/index.js +9 -0
- package/lib/utils/lint/lintScripts.js +1 -0
- package/lib/utils/lint/lintSetup.js +4 -3
- package/lib/utils/lint/lintStagedPreCommitHook.js +1 -0
- package/lib/utils/lint/question.js +7 -0
- package/lib/utils/lintReporter.js +20 -0
- package/lib/utils/mailSender.js +7 -0
- package/lib/utils/pullOrigin.js +4 -0
- package/lib/utils/reinstallDependencies.js +28 -0
- package/lib/utils/removeAttributes.js +7 -0
- package/lib/utils/repoClone.js +27 -2
- package/lib/utils/request.js +12 -0
- package/lib/utils/rtl.js +16 -4
- package/lib/utils/setEnvVariables.js +2 -0
- package/lib/utils/ssTestHack.js +10 -0
- package/lib/utils/switchBranch.js +4 -0
- package/lib/utils/urlConcat.js +4 -0
- package/lib/utils/useExitCleanup.js +10 -9
- package/package.json +10 -9
@@ -3,7 +3,9 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
+
|
6
7
|
var _collectI18nKeys = require("./collectI18nKeys");
|
8
|
+
|
7
9
|
Object.keys(_collectI18nKeys).forEach(function (key) {
|
8
10
|
if (key === "default" || key === "__esModule") return;
|
9
11
|
if (key in exports && exports[key] === _collectI18nKeys[key]) return;
|
@@ -14,7 +16,9 @@ Object.keys(_collectI18nKeys).forEach(function (key) {
|
|
14
16
|
}
|
15
17
|
});
|
16
18
|
});
|
19
|
+
|
17
20
|
var _propertiesUtils = require("./propertiesUtils");
|
21
|
+
|
18
22
|
Object.keys(_propertiesUtils).forEach(function (key) {
|
19
23
|
if (key === "default" || key === "__esModule") return;
|
20
24
|
if (key in exports && exports[key] === _propertiesUtils[key]) return;
|
@@ -6,11 +6,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
exports.getAllI18n = getAllI18n;
|
7
7
|
exports.getPropertiesAsJSON = getPropertiesAsJSON;
|
8
8
|
exports.jsonToString = jsonToString;
|
9
|
+
|
9
10
|
var _fs = require("fs");
|
11
|
+
|
10
12
|
var _path = require("path");
|
13
|
+
|
11
14
|
function isComment(line) {
|
12
15
|
return line[0] === '#';
|
13
16
|
}
|
17
|
+
|
14
18
|
function getPropertiesAsJSON(filePath) {
|
15
19
|
try {
|
16
20
|
const data = (0, _fs.readFileSync)(filePath);
|
@@ -18,12 +22,15 @@ function getPropertiesAsJSON(filePath) {
|
|
18
22
|
const i18nObj = {};
|
19
23
|
source.split(/\r?\n\r?/).forEach(fline => {
|
20
24
|
const line = fline.trim();
|
25
|
+
|
21
26
|
if (!line || isComment(line)) {
|
22
27
|
return;
|
23
28
|
}
|
29
|
+
|
24
30
|
const ind = line.indexOf('=');
|
25
31
|
const key = line.slice(0, ind).replace(/\\ /g, ' ');
|
26
32
|
const value = line.slice(ind + 1);
|
33
|
+
|
27
34
|
if (key && value) {
|
28
35
|
i18nObj[key] = value;
|
29
36
|
}
|
@@ -33,15 +40,19 @@ function getPropertiesAsJSON(filePath) {
|
|
33
40
|
return {};
|
34
41
|
}
|
35
42
|
}
|
43
|
+
|
36
44
|
function getLang(file) {
|
37
45
|
let underScoreIndex = file.indexOf('_');
|
38
46
|
let language = 'en_US';
|
47
|
+
|
39
48
|
if (underScoreIndex !== -1) {
|
40
49
|
language = file.substring(underScoreIndex + 1);
|
41
50
|
language = language.slice(0, language.indexOf('.'));
|
42
51
|
}
|
52
|
+
|
43
53
|
return language;
|
44
54
|
}
|
55
|
+
|
45
56
|
function getAllI18n({
|
46
57
|
folderPath,
|
47
58
|
disableDefault,
|
@@ -55,11 +66,13 @@ function getAllI18n({
|
|
55
66
|
const context = (0, _path.join)(process.cwd(), folderPath);
|
56
67
|
files.forEach(file => {
|
57
68
|
const filePath = (0, _path.join)(context, file);
|
69
|
+
|
58
70
|
if (exclude.test(filePath) || !include.test(filePath)) {
|
59
71
|
// console.log('exclude', filePath);
|
60
72
|
return;
|
61
|
-
}
|
62
|
-
|
73
|
+
} // console.log('include', filePath);
|
74
|
+
|
75
|
+
|
63
76
|
const i18n = getPropertiesAsJSON(filePath);
|
64
77
|
allLangI18n[getLang(file)] = disableDefault ? i18n : Object.assign({}, jsResourceI18nKeys, i18n);
|
65
78
|
});
|
@@ -69,22 +82,27 @@ function getAllI18n({
|
|
69
82
|
return {};
|
70
83
|
}
|
71
84
|
}
|
85
|
+
|
72
86
|
function jsonToString(json, keySeperator) {
|
73
87
|
let str = '{';
|
74
88
|
let keys = Object.keys(json);
|
75
89
|
keys.forEach((key, i) => {
|
76
90
|
let value = json[key];
|
91
|
+
|
77
92
|
if (!value) {
|
78
93
|
return;
|
79
94
|
}
|
95
|
+
|
80
96
|
str += `"${keySeperator ? key.replace(/(\.|\\(\s+))/g, keySeperator) : key}":"${value.replace(/.?"/g, match => {
|
81
97
|
if (match[0] === '\\') {
|
82
98
|
return match;
|
83
99
|
} else if (match.length === 2) {
|
84
100
|
return `${match[0]}\\${match[1]}`;
|
85
101
|
}
|
102
|
+
|
86
103
|
return `\\${match}`;
|
87
104
|
}).replace(/(\r\n|\n|\r)/g, '')}"`;
|
105
|
+
|
88
106
|
if (i !== keys.length - 1) {
|
89
107
|
str += ',';
|
90
108
|
}
|
@@ -4,32 +4,42 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
|
+
|
7
8
|
var _path = _interopRequireDefault(require("path"));
|
9
|
+
|
8
10
|
var _webpackSources = require("webpack-sources");
|
11
|
+
|
9
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
|
+
|
10
14
|
let filenameParser = filename => {
|
11
15
|
let filepaths = filename.split('/');
|
12
16
|
let hashedName = filepaths[filepaths.length - 1];
|
17
|
+
|
13
18
|
let {
|
14
19
|
name,
|
15
20
|
ext
|
16
21
|
} = _path.default.parse(hashedName);
|
22
|
+
|
17
23
|
let nameparts = name.split('.');
|
24
|
+
|
18
25
|
if (ext === '.css' && /^(rtl|ltr)$/.test(nameparts[nameparts.length - 1])) {
|
19
26
|
return {
|
20
27
|
name: nameparts.slice(0, nameparts.length - 2).join('.') + ext,
|
21
28
|
hashedName
|
22
29
|
};
|
23
30
|
}
|
31
|
+
|
24
32
|
return {
|
25
33
|
name: nameparts.slice(0, nameparts.length - 1).join('.') + ext,
|
26
34
|
hashedName
|
27
35
|
};
|
28
36
|
};
|
37
|
+
|
29
38
|
class ManifestPlugin {
|
30
39
|
constructor(options) {
|
31
40
|
this.options = options;
|
32
41
|
}
|
42
|
+
|
33
43
|
apply(compiler) {
|
34
44
|
compiler.hooks.emit.tap('PublicPathChangePlugin', compilation => {
|
35
45
|
let stats = compilation.getStats().toJson();
|
@@ -38,20 +48,25 @@ class ManifestPlugin {
|
|
38
48
|
name: filename,
|
39
49
|
hashedName
|
40
50
|
} = filenameParser(name);
|
51
|
+
|
41
52
|
if (chunk.canBeInitial()) {
|
42
53
|
if (!files.entryFiles) {
|
43
54
|
files.entryFiles = {};
|
44
55
|
}
|
56
|
+
|
45
57
|
files.entryFiles[filename] = hashedName;
|
46
58
|
}
|
59
|
+
|
47
60
|
files[filename] = hashedName;
|
48
61
|
return files;
|
49
62
|
}, files), {});
|
50
63
|
manifest = stats.assets.reduce((files, asset) => {
|
51
64
|
let isEntryAsset = asset.chunks.length > 0;
|
65
|
+
|
52
66
|
if (isEntryAsset) {
|
53
67
|
return files;
|
54
68
|
}
|
69
|
+
|
55
70
|
let {
|
56
71
|
name: filename
|
57
72
|
} = asset;
|
@@ -65,5 +80,7 @@ class ManifestPlugin {
|
|
65
80
|
compilation.assets[this.options.fileName] = new _webpackSources.RawSource(JSON.stringify(manifest));
|
66
81
|
});
|
67
82
|
}
|
83
|
+
|
68
84
|
}
|
85
|
+
|
69
86
|
exports.default = ManifestPlugin;
|
@@ -4,29 +4,39 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
|
+
|
7
8
|
var _path = _interopRequireDefault(require("path"));
|
9
|
+
|
8
10
|
var _webpackSources = require("webpack-sources");
|
11
|
+
|
9
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
|
+
|
10
14
|
let isValidModule = name => {
|
11
15
|
if (name.includes('node_modules') && (name.includes(`@zohodesk${_path.default.sep}components`) || name.includes(`@zohodesk${_path.default.sep}dot`) || name.includes(`@zohodesk${_path.default.sep}icons`) || name.includes(`@zohodesk${_path.default.sep}svg`)) && !name.endsWith('docs.js')) {
|
12
16
|
return true;
|
13
17
|
}
|
18
|
+
|
14
19
|
return !name.includes('index.js') && !name.endsWith('.css') && !name.endsWith('.png') && !name.includes('node_modules') && name.includes('src');
|
15
20
|
};
|
21
|
+
|
16
22
|
let getModuleName = modulePath => {
|
17
23
|
let [name] = _path.default.parse(modulePath).name.split('.');
|
24
|
+
|
18
25
|
if (modulePath.includes(`@zohodesk${_path.default.sep}components`)) {
|
19
26
|
name = `@zohodesk/components/${name}`;
|
20
27
|
} else if (modulePath.includes(`@zohodesk${_path.default.sep}dot`)) {
|
21
28
|
name = `@zohodesk/dot/${name}`;
|
22
29
|
}
|
30
|
+
|
23
31
|
return name;
|
24
32
|
};
|
33
|
+
|
25
34
|
class ModuleStatsPlugin {
|
26
35
|
constructor(options = {}) {
|
27
36
|
this.options = options;
|
28
37
|
this.options.filename = options.filename || 'js/moduleStats.js';
|
29
38
|
}
|
39
|
+
|
30
40
|
apply(compiler) {
|
31
41
|
compiler.hooks.emit.tap('ModuleStatsPlugin', compilation => {
|
32
42
|
let stats = compilation.getStats().toJson();
|
@@ -34,11 +44,13 @@ class ModuleStatsPlugin {
|
|
34
44
|
let {
|
35
45
|
modules
|
36
46
|
} = stats;
|
47
|
+
|
37
48
|
for (let module of modules) {
|
38
49
|
let {
|
39
50
|
name,
|
40
51
|
reasons
|
41
52
|
} = module;
|
53
|
+
|
42
54
|
if (isValidModule(name)) {
|
43
55
|
let references = new Set();
|
44
56
|
let referencedby = new Set();
|
@@ -47,6 +59,7 @@ class ModuleStatsPlugin {
|
|
47
59
|
compilation.modules.forEach(module => {
|
48
60
|
module.reasons.forEach(reason => {
|
49
61
|
let exportedValue = reason.dependency;
|
62
|
+
|
50
63
|
if (exportedValue.type === 'harmony export imported specifier') {
|
51
64
|
if (exportedValue.module.userRequest.includes(name.replace('.', ''))) {
|
52
65
|
docsName = exportedValue.name;
|
@@ -55,29 +68,35 @@ class ModuleStatsPlugin {
|
|
55
68
|
});
|
56
69
|
});
|
57
70
|
let currentModuleName = name;
|
71
|
+
|
58
72
|
if (Array.isArray(reasons)) {
|
59
73
|
for (let reason of reasons) {
|
60
74
|
let {
|
61
75
|
moduleName
|
62
76
|
} = reason;
|
77
|
+
|
63
78
|
if (isValidModule(moduleName)) {
|
64
79
|
let reasonedModuleName = moduleName;
|
65
80
|
referencedby.add(reasonedModuleName);
|
66
81
|
}
|
67
82
|
}
|
68
83
|
}
|
84
|
+
|
69
85
|
for (let subModule of modules) {
|
70
86
|
let {
|
71
87
|
name: subModuleName,
|
72
88
|
reasons
|
73
89
|
} = subModule;
|
90
|
+
|
74
91
|
if (isValidModule(subModuleName)) {
|
75
92
|
let currentModuleName = subModuleName;
|
93
|
+
|
76
94
|
if (Array.isArray(reasons)) {
|
77
95
|
for (let reason of reasons) {
|
78
96
|
let {
|
79
97
|
moduleName: reasonedModuleName
|
80
98
|
} = reason;
|
99
|
+
|
81
100
|
if (name === reasonedModuleName) {
|
82
101
|
references.add(currentModuleName);
|
83
102
|
}
|
@@ -85,6 +104,7 @@ class ModuleStatsPlugin {
|
|
85
104
|
}
|
86
105
|
}
|
87
106
|
}
|
107
|
+
|
88
108
|
results[currentModuleName] = {
|
89
109
|
name: currentModuleName,
|
90
110
|
references: Array.from(references),
|
@@ -94,8 +114,11 @@ class ModuleStatsPlugin {
|
|
94
114
|
};
|
95
115
|
}
|
96
116
|
}
|
117
|
+
|
97
118
|
compilation.assets[this.options.filename] = new _webpackSources.RawSource(JSON.stringify(results));
|
98
119
|
});
|
99
120
|
}
|
121
|
+
|
100
122
|
}
|
123
|
+
|
101
124
|
exports.default = ModuleStatsPlugin;
|
@@ -4,13 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
|
+
|
7
8
|
var _optimizeJs = _interopRequireDefault(require("optimize-js"));
|
9
|
+
|
8
10
|
var _webpackSources = require("webpack-sources");
|
11
|
+
|
9
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
|
+
|
10
14
|
class OptimizeJSPlugin {
|
11
15
|
constructor(options = {}) {
|
12
16
|
this.optimize = options.optimize;
|
13
17
|
}
|
18
|
+
|
14
19
|
apply(compiler) {
|
15
20
|
compiler.hooks.compilation.tap('OptimizeJSPlugin', compilation => {
|
16
21
|
compilation.hooks.afterOptimizeChunks.tap('OptimizeJSPlugin', chunks => {
|
@@ -29,6 +34,8 @@ class OptimizeJSPlugin {
|
|
29
34
|
});
|
30
35
|
});
|
31
36
|
}
|
37
|
+
|
32
38
|
}
|
39
|
+
|
33
40
|
var _default = OptimizeJSPlugin;
|
34
41
|
exports.default = _default;
|
@@ -5,14 +5,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
7
|
const MODULE_TYPE = 'css/mini-extract';
|
8
|
+
|
8
9
|
class PublicPathCallbackPlugin {
|
9
10
|
constructor({
|
10
11
|
callback
|
11
12
|
}) {
|
12
13
|
this.publicPathCallback = callback;
|
13
14
|
}
|
15
|
+
|
14
16
|
getCssChunkObject(mainChunk) {
|
15
17
|
const obj = {};
|
18
|
+
|
16
19
|
for (const chunk of mainChunk.getAllAsyncChunks()) {
|
17
20
|
for (const module of chunk.modulesIterable) {
|
18
21
|
if (module.type === MODULE_TYPE) {
|
@@ -21,20 +24,25 @@ class PublicPathCallbackPlugin {
|
|
21
24
|
}
|
22
25
|
}
|
23
26
|
}
|
27
|
+
|
24
28
|
return obj;
|
25
29
|
}
|
30
|
+
|
26
31
|
needChunkOnDemandLoadingCode(chunk) {
|
27
32
|
for (const chunkGroup of chunk.groupsIterable) {
|
28
33
|
if (chunkGroup.getNumberOfChildren() > 0) {
|
29
34
|
return true;
|
30
35
|
}
|
31
36
|
}
|
37
|
+
|
32
38
|
return false;
|
33
39
|
}
|
40
|
+
|
34
41
|
apply(compiler) {
|
35
42
|
compiler.hooks.thisCompilation.tap('PublicPathCallbackPlugin', compilation => {
|
36
43
|
compilation.mainTemplate.hooks.requireEnsure.tap('PublicPathCallbackPlugin', (source, chunk) => {
|
37
44
|
const chunkMap = this.getCssChunkObject(chunk);
|
45
|
+
|
38
46
|
if (Object.keys(chunkMap).length > 0) {
|
39
47
|
return source.replace('__webpack_require__.p', `${this.publicPathCallback}("css")`);
|
40
48
|
}
|
@@ -48,6 +56,8 @@ class PublicPathCallbackPlugin {
|
|
48
56
|
});
|
49
57
|
});
|
50
58
|
}
|
59
|
+
|
51
60
|
}
|
61
|
+
|
52
62
|
var _default = PublicPathCallbackPlugin;
|
53
63
|
exports.default = _default;
|
@@ -4,21 +4,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
|
+
|
7
8
|
var _path = _interopRequireDefault(require("path"));
|
9
|
+
|
8
10
|
var _webpackSources = require("webpack-sources");
|
11
|
+
|
9
12
|
var _utils = require("../utils");
|
13
|
+
|
10
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
|
+
|
11
16
|
const MODULE_TYPE = 'css/mini-extract';
|
12
17
|
let {
|
13
18
|
chunkSplitEnable
|
14
19
|
} = (0, _utils.getOptions)().i18n || {};
|
20
|
+
|
15
21
|
let filenameParser = filename => {
|
16
22
|
let filepaths = filename.split('/');
|
17
23
|
let hashedName = filepaths[filepaths.length - 1];
|
24
|
+
|
18
25
|
let {
|
19
26
|
name,
|
20
27
|
ext
|
21
28
|
} = _path.default.parse(hashedName);
|
29
|
+
|
22
30
|
let nameparts = name.split('.');
|
23
31
|
return {
|
24
32
|
name: nameparts.slice(0, nameparts.length - 1).join('.') + ext,
|
@@ -26,14 +34,15 @@ let filenameParser = filename => {
|
|
26
34
|
ext
|
27
35
|
};
|
28
36
|
};
|
37
|
+
|
29
38
|
class PublicPathChangePlugin {
|
30
39
|
constructor({
|
31
40
|
publicPaths,
|
32
41
|
resourceHints
|
33
42
|
}) {
|
34
43
|
if (Array.isArray(publicPaths)) {
|
35
|
-
let [js, css, image, font, i18njs] = publicPaths;
|
36
|
-
|
44
|
+
let [js, css, image, font, i18njs] = publicPaths; //eslint-disable-next-line
|
45
|
+
|
37
46
|
publicPaths = {
|
38
47
|
__REACT_CLI_PUBLIC_PATHS__: {
|
39
48
|
js,
|
@@ -44,11 +53,14 @@ class PublicPathChangePlugin {
|
|
44
53
|
}
|
45
54
|
};
|
46
55
|
}
|
56
|
+
|
47
57
|
this.publicPaths = publicPaths;
|
48
58
|
this.resourceHints = resourceHints;
|
49
59
|
}
|
60
|
+
|
50
61
|
getCssChunkObject(mainChunk) {
|
51
62
|
const obj = {};
|
63
|
+
|
52
64
|
for (const chunk of mainChunk.getAllAsyncChunks()) {
|
53
65
|
for (const module of chunk.modulesIterable) {
|
54
66
|
if (module.type === MODULE_TYPE) {
|
@@ -57,34 +69,42 @@ class PublicPathChangePlugin {
|
|
57
69
|
}
|
58
70
|
}
|
59
71
|
}
|
72
|
+
|
60
73
|
return obj;
|
61
74
|
}
|
75
|
+
|
62
76
|
needChunkOnDemandLoadingCode(chunk) {
|
63
77
|
for (const chunkGroup of chunk.groupsIterable) {
|
64
78
|
if (chunkGroup.getNumberOfChildren() > 0) {
|
65
79
|
return true;
|
66
80
|
}
|
67
81
|
}
|
82
|
+
|
68
83
|
return false;
|
69
84
|
}
|
85
|
+
|
70
86
|
getResourceHints(resourceHints, manifest, publicPaths) {
|
71
87
|
let ruleMapping = {};
|
72
88
|
let validFiles = Object.keys(manifest).filter(filename => {
|
73
89
|
let isValidFile = false;
|
90
|
+
|
74
91
|
for (let pattern of resourceHints) {
|
75
92
|
if (typeof pattern === 'string') {
|
76
93
|
isValidFile = new RegExp(pattern).test(filename);
|
77
94
|
} else {
|
78
95
|
isValidFile = new RegExp(pattern.pattern).test(filename);
|
79
96
|
}
|
97
|
+
|
80
98
|
if (isValidFile) {
|
81
99
|
ruleMapping[filename] = typeof pattern !== 'string' ? pattern : {};
|
82
100
|
break;
|
83
101
|
}
|
84
102
|
}
|
103
|
+
|
85
104
|
return isValidFile;
|
86
105
|
});
|
87
106
|
let resourceHintsContent = '';
|
107
|
+
|
88
108
|
for (let file of validFiles) {
|
89
109
|
let {
|
90
110
|
fileType,
|
@@ -93,12 +113,15 @@ class PublicPathChangePlugin {
|
|
93
113
|
let rules = ruleMapping[file];
|
94
114
|
resourceHintsContent += `<link rel=${rules.hint || 'preload'} href='${publicPaths[fileType] + filename}'${rules.hint === 'prefetch' ? '' : `as='${fileType}' crossorigin='${rules.crossorigin || 'false'}'`} />`;
|
95
115
|
}
|
116
|
+
|
96
117
|
return resourceHintsContent;
|
97
118
|
}
|
119
|
+
|
98
120
|
apply(compiler) {
|
99
121
|
compiler.hooks.thisCompilation.tap('PublicPathChangePlugin', compilation => {
|
100
122
|
compilation.mainTemplate.hooks.requireEnsure.tap('PublicPathChangePlugin', (source, chunk) => {
|
101
123
|
const chunkMap = this.getCssChunkObject(chunk);
|
124
|
+
|
102
125
|
if (Object.keys(chunkMap).length > 0) {
|
103
126
|
return source.replace('__webpack_require__.p', '__REACT_CLI_CSS_PUBLIC_PATH__');
|
104
127
|
}
|
@@ -119,6 +142,7 @@ class PublicPathChangePlugin {
|
|
119
142
|
name: filename
|
120
143
|
} = asset;
|
121
144
|
let fileType = (0, _utils.getFileType)(filename);
|
145
|
+
|
122
146
|
if (fileType === 'image' || fileType === 'font') {
|
123
147
|
let {
|
124
148
|
name,
|
@@ -132,12 +156,14 @@ class PublicPathChangePlugin {
|
|
132
156
|
filename
|
133
157
|
};
|
134
158
|
}
|
159
|
+
|
135
160
|
return files;
|
136
161
|
}, {});
|
137
162
|
Object.keys(compilation.assets).forEach(filename => {
|
138
163
|
if (Array.isArray(cdns)) {
|
139
164
|
cdns.forEach(cdn => {
|
140
165
|
let source = compilation.assets[filename].source();
|
166
|
+
|
141
167
|
if (/\.css$/g.test(filename)) {
|
142
168
|
let publicPaths = this.publicPaths[cdn];
|
143
169
|
source = (0, _utils.cssUrlReplacer)(source, publicPaths, manifest, cdn);
|
@@ -148,6 +174,7 @@ class PublicPathChangePlugin {
|
|
148
174
|
image,
|
149
175
|
font
|
150
176
|
} = this.publicPaths[cdn];
|
177
|
+
|
151
178
|
if (typeof source === 'string') {
|
152
179
|
source = source.replace(/__REACT_CLI_JS_PUBLIC_PATH__/g, `"${js}"`);
|
153
180
|
source = source.replace(/__REACT_CLI_CSS_PUBLIC_PATH__/g, `"${css}"`);
|
@@ -163,6 +190,7 @@ class PublicPathChangePlugin {
|
|
163
190
|
source = source.replace(new RegExp('<script defer src="([^"]*)"', 'g'), (match, arg) => match.replace(arg, js + arg));
|
164
191
|
source = source.replace(new RegExp('<link href="([^"]*)"', 'g'), (match, arg) => match.replace(arg, css + arg));
|
165
192
|
let [i18nStr] = source.match(/<!--I18nInfoToServer(.*?)I18nInfoToServer-->/gm);
|
193
|
+
|
166
194
|
if (i18nStr && !chunkSplitEnable) {
|
167
195
|
try {
|
168
196
|
let [i18nObj] = i18nStr.match(/{(.*?)}/gm);
|
@@ -173,22 +201,26 @@ class PublicPathChangePlugin {
|
|
173
201
|
source = source.replace(/<!--I18nInfoToServer(.*?)I18nInfoToServer-->/gm, `<!--I18nInfoToServer${JSON.stringify(i18nObj)}I18nInfoToServer-->`);
|
174
202
|
} catch (e) {
|
175
203
|
// eslint-disable-next-line no-console
|
176
|
-
console.warn('may be I18nInfoToServer inside object was not valid make sure it is parseable by JSON.parse');
|
177
|
-
|
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
|
+
|
178
206
|
console.warn(e);
|
179
207
|
}
|
180
208
|
}
|
209
|
+
|
181
210
|
if (Array.isArray(this.resourceHints) && this.resourceHints.length) {
|
182
211
|
let resourceHintsContent = this.getResourceHints(this.resourceHints, manifest, this.publicPaths[cdn]);
|
183
212
|
source = source.replace(/<\/head>/g, `${resourceHintsContent}</head>`);
|
184
213
|
}
|
185
214
|
}
|
215
|
+
|
186
216
|
compilation.assets[cdn === '__REACT_CLI_PUBLIC_PATHS__' ? filename : `${cdn}/${filename}`] = new _webpackSources.RawSource(source);
|
187
217
|
});
|
188
218
|
}
|
189
219
|
});
|
190
220
|
});
|
191
221
|
}
|
222
|
+
|
192
223
|
}
|
224
|
+
|
193
225
|
var _default = PublicPathChangePlugin;
|
194
226
|
exports.default = _default;
|