@zohodesk/react-cli 0.0.1-beta.99 → 0.0.1-betaa.138.2
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,66 +1,64 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
|
-
var _path = require(
|
3
|
+
var _path = _interopRequireDefault(require("path"));
|
4
4
|
|
5
|
-
var
|
5
|
+
var _loaderUtils = _interopRequireDefault(require("loader-utils"));
|
6
6
|
|
7
|
-
var
|
8
|
-
|
9
|
-
var _loaderUtils2 = _interopRequireDefault(_loaderUtils);
|
10
|
-
|
11
|
-
var _common = require('../common');
|
7
|
+
var _common = require("../common");
|
12
8
|
|
13
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
14
10
|
|
15
11
|
module.exports = function (content) {
|
16
|
-
|
17
|
-
|
12
|
+
let {
|
13
|
+
userRequest
|
14
|
+
} = this._module.issuer;
|
18
15
|
this.cacheable && this.cacheable();
|
16
|
+
|
19
17
|
if (!this.emitFile) {
|
20
18
|
throw new Error('emitFile is required from module system');
|
21
19
|
}
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
// let configKey = query.config || 'fileLoader';
|
21
|
+
let options = _loaderUtils.default.getOptions(this) || {};
|
22
|
+
let query = this.resourceQuery ? _loaderUtils.default.parseQuery(this.resourceQuery) : {}; // let configKey = query.config || 'fileLoader';
|
27
23
|
|
28
|
-
|
24
|
+
let config = {
|
29
25
|
// publicPath: false,
|
30
26
|
useRelativePath: false,
|
31
|
-
name: '[hash].[ext]'
|
32
|
-
|
33
|
-
};
|
27
|
+
name: '[hash].[ext]' // publicPathStrigify: true
|
28
|
+
|
29
|
+
}; // options takes precedence over config
|
34
30
|
|
35
|
-
|
36
|
-
Object.keys(options).forEach(function (attr) {
|
31
|
+
Object.keys(options).forEach(attr => {
|
37
32
|
config[attr] = options[attr];
|
38
|
-
});
|
33
|
+
}); // query takes precedence over config and options
|
39
34
|
|
40
|
-
|
41
|
-
Object.keys(query).forEach(function (attr) {
|
35
|
+
Object.keys(query).forEach(attr => {
|
42
36
|
config[attr] = query[attr];
|
43
37
|
});
|
38
|
+
let context = config.context || options.context;
|
44
39
|
|
45
|
-
|
46
|
-
var url = _loaderUtils2.default.interpolateName(this, config.name, {
|
40
|
+
let url = _loaderUtils.default.interpolateName(this, config.name, {
|
47
41
|
context: context,
|
48
42
|
content: content,
|
49
43
|
regExp: config.regExp
|
50
44
|
});
|
51
45
|
|
52
|
-
|
46
|
+
let outputPath = '';
|
47
|
+
let filePath = this.resourcePath;
|
53
48
|
|
54
|
-
var filePath = this.resourcePath;
|
55
49
|
if (config.useRelativePath) {
|
56
|
-
|
57
|
-
|
58
|
-
|
50
|
+
let issuerContext = this._module && this._module.issuer && this._module.issuer.context || context;
|
51
|
+
|
52
|
+
let relativeUrl = issuerContext && _path.default.relative(issuerContext, filePath).split(_path.default.sep).join('/');
|
53
|
+
|
54
|
+
let relativePath = relativeUrl && `${_path.default.dirname(relativeUrl)}/`;
|
55
|
+
|
59
56
|
if (~relativePath.indexOf('../')) {
|
60
|
-
outputPath =
|
57
|
+
outputPath = _path.default.posix.join(outputPath, relativePath, url);
|
61
58
|
} else {
|
62
59
|
outputPath = relativePath + url;
|
63
60
|
}
|
61
|
+
|
64
62
|
url = relativePath + url;
|
65
63
|
} else if (config.outputPath) {
|
66
64
|
// support functions as outputPath to generate them dynamically
|
@@ -70,9 +68,8 @@ module.exports = function (content) {
|
|
70
68
|
outputPath = url;
|
71
69
|
}
|
72
70
|
|
73
|
-
|
74
|
-
|
75
|
-
// if (config.publicPath !== false) {
|
71
|
+
let requestFromJS = /\.js$/.test(userRequest);
|
72
|
+
let publicPath = requestFromJS ? (0, _common.getPublicPathConfig)(url) : `__webpack_public_path__ + ${JSON.stringify(url)}`; // if (config.publicPath !== false) {
|
76
73
|
// // support functions as publicPath to generate them dynamically
|
77
74
|
// if (config.publicPathStringify) {
|
78
75
|
// publicPath = JSON.Stringify(
|
@@ -91,7 +88,8 @@ module.exports = function (content) {
|
|
91
88
|
if (query.emitFile === undefined || query.emitFile) {
|
92
89
|
this.emitFile(outputPath, content);
|
93
90
|
}
|
94
|
-
|
91
|
+
|
92
|
+
return `module.exports = ${publicPath};`;
|
95
93
|
};
|
96
94
|
|
97
95
|
module.exports.raw = true;
|
@@ -1,18 +1,16 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
|
-
var
|
3
|
+
var esprima = _interopRequireWildcard(require("esprima"));
|
4
4
|
|
5
|
-
var
|
6
|
-
|
7
|
-
var _escodegen = require('escodegen');
|
8
|
-
|
9
|
-
var _escodegen2 = _interopRequireDefault(_escodegen);
|
5
|
+
var _escodegen = _interopRequireDefault(require("escodegen"));
|
10
6
|
|
11
7
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
12
8
|
|
13
|
-
function
|
9
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
14
10
|
|
15
|
-
var
|
11
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
12
|
+
|
13
|
+
let start = {
|
16
14
|
type: 'ExpressionStatement',
|
17
15
|
expression: {
|
18
16
|
type: 'CallExpression',
|
@@ -56,22 +54,28 @@ var start = {
|
|
56
54
|
}
|
57
55
|
};
|
58
56
|
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
let scriptInstrumentLoader = function (source) {
|
58
|
+
let parsed = esprima.parseModule(source, {
|
59
|
+
jsx: true
|
60
|
+
});
|
61
|
+
|
62
|
+
for (let i in parsed.body) {
|
62
63
|
if (parsed.body[i].type === 'FunctionDeclaration' || parsed.body[i].type === 'ExportDefaultDeclaration' || parsed.body[i].type === 'ExportNamedDeclaration') {
|
63
|
-
|
64
|
+
let ParsedTemp;
|
65
|
+
|
64
66
|
if (parsed.body[i].type === 'FunctionDeclaration') {
|
65
67
|
ParsedTemp = parsed.body[i];
|
66
68
|
} else {
|
67
69
|
ParsedTemp = parsed.body[i].declaration;
|
68
70
|
}
|
71
|
+
|
69
72
|
if (ParsedTemp) {
|
70
73
|
if (ParsedTemp.id) {
|
71
|
-
|
74
|
+
let funcname = ParsedTemp.id.name;
|
75
|
+
|
72
76
|
if (funcname !== 'mapStateToProps') {
|
73
77
|
if (!funcname.includes('_')) {
|
74
|
-
|
78
|
+
let startFunc = JSON.parse(JSON.stringify(start));
|
75
79
|
startFunc.expression.arguments[0].value = this.resourcePath;
|
76
80
|
startFunc.expression.arguments[0].raw = this.resourcePath;
|
77
81
|
startFunc.expression.arguments[1].value = funcname;
|
@@ -84,8 +88,7 @@ var scriptInstrumentLoader = function scriptInstrumentLoader(source) {
|
|
84
88
|
}
|
85
89
|
}
|
86
90
|
|
87
|
-
return
|
88
|
-
// function removeDuplicates(arr) {
|
91
|
+
return _escodegen.default.generate(parsed); // function removeDuplicates(arr) {
|
89
92
|
// let uniqueArray = [];
|
90
93
|
// for (let i = 0; i < arr.length; i++) {
|
91
94
|
// if (uniqueArray.indexOf(arr[i]) == -1) {
|
@@ -97,9 +100,7 @@ var scriptInstrumentLoader = function scriptInstrumentLoader(source) {
|
|
97
100
|
// funcArray = removeDuplicates(funcArray);
|
98
101
|
};
|
99
102
|
|
100
|
-
module.exports = scriptInstrumentLoader;
|
101
|
-
|
102
|
-
// let start = {
|
103
|
+
module.exports = scriptInstrumentLoader; // let start = {
|
103
104
|
// type: 'ExpressionStatement',
|
104
105
|
// expression: {
|
105
106
|
// type: 'CallExpression',
|
@@ -0,0 +1,136 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = loader;
|
7
|
+
exports.pitch = pitch;
|
8
|
+
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
10
|
+
|
11
|
+
var _loaderUtils = require("loader-utils");
|
12
|
+
|
13
|
+
var _schemaUtils = _interopRequireDefault(require("schema-utils"));
|
14
|
+
|
15
|
+
var _SingleEntryPlugin = _interopRequireDefault(require("webpack/lib/SingleEntryPlugin"));
|
16
|
+
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
18
|
+
|
19
|
+
/* import WebWorkerTemplatePlugin from 'webpack/lib/webworker/WebWorkerTemplatePlugin';
|
20
|
+
import ExternalsPlugin from 'webpack/lib/ExternalsPlugin'; */
|
21
|
+
const schema = {
|
22
|
+
'type': 'object',
|
23
|
+
'properties': {
|
24
|
+
'publicPath': {
|
25
|
+
'anyOf': [{
|
26
|
+
'type': 'string'
|
27
|
+
}, {
|
28
|
+
'instanceof': 'Function'
|
29
|
+
}]
|
30
|
+
},
|
31
|
+
'filename': {
|
32
|
+
'anyOf': [{
|
33
|
+
'type': 'string',
|
34
|
+
'minLength': 1
|
35
|
+
}, {
|
36
|
+
'instanceof': 'Function'
|
37
|
+
}]
|
38
|
+
},
|
39
|
+
'chunkFilename': {
|
40
|
+
'type': 'string',
|
41
|
+
'minLength': 1
|
42
|
+
},
|
43
|
+
'esModule': {
|
44
|
+
'type': 'boolean'
|
45
|
+
}
|
46
|
+
},
|
47
|
+
'additionalProperties': false
|
48
|
+
}; // eslint-disable-next-line
|
49
|
+
|
50
|
+
function loader() {}
|
51
|
+
|
52
|
+
function getDefaultFilename(filename) {
|
53
|
+
if (typeof filename === 'function') {
|
54
|
+
return filename;
|
55
|
+
}
|
56
|
+
|
57
|
+
return filename.replace(/\.([a-z]+)(\?.+)?$/i, '.worker.$1$2');
|
58
|
+
}
|
59
|
+
|
60
|
+
function getDefaultChunkFilename(chunkFilename) {
|
61
|
+
return chunkFilename.replace(/\.([a-z]+)(\?.+)?$/i, '.worker.$1$2');
|
62
|
+
}
|
63
|
+
|
64
|
+
function pitch(request) {
|
65
|
+
this.cacheable(false);
|
66
|
+
const options = (0, _loaderUtils.getOptions)(this);
|
67
|
+
(0, _schemaUtils.default)(schema, options, {
|
68
|
+
name: 'Worker Loader',
|
69
|
+
baseDataPath: 'options'
|
70
|
+
});
|
71
|
+
const workerContext = {};
|
72
|
+
const compilerOptions = this._compiler.options || {};
|
73
|
+
const filename = options.filename ? options.filename : getDefaultFilename(compilerOptions.output.filename);
|
74
|
+
const chunkFilename = options.chunkFilename ? options.chunkFilename : getDefaultChunkFilename(compilerOptions.output.chunkFilename);
|
75
|
+
const publicPath = options.publicPath ? options.publicPath : compilerOptions.output.publicPath;
|
76
|
+
workerContext.options = {
|
77
|
+
filename,
|
78
|
+
chunkFilename,
|
79
|
+
publicPath,
|
80
|
+
globalObject: 'self'
|
81
|
+
};
|
82
|
+
workerContext.compiler = this._compilation.createChildCompiler(`worker-loader ${request}`, workerContext.options);
|
83
|
+
/*
|
84
|
+
new WebWorkerTemplatePlugin().apply(workerContext.compiler);
|
85
|
+
|
86
|
+
if (compilerOptions.externals) {
|
87
|
+
new ExternalsPlugin(
|
88
|
+
getExternalsType(compilerOptions),
|
89
|
+
compilerOptions.externals
|
90
|
+
).apply(workerContext.compiler);
|
91
|
+
} */
|
92
|
+
|
93
|
+
new _SingleEntryPlugin.default(this.context, `!!${request}`, _path.default.parse(this.resourcePath).name).apply(workerContext.compiler);
|
94
|
+
workerContext.request = request;
|
95
|
+
const cb = this.async();
|
96
|
+
workerContext.compiler.runAsChild((errorArg, entries, compilation) => {
|
97
|
+
let error = errorArg;
|
98
|
+
|
99
|
+
if (!error && compilation.errors && compilation.errors.length) {
|
100
|
+
// eslint-disable-next-line
|
101
|
+
error = compilation.errors[0];
|
102
|
+
}
|
103
|
+
|
104
|
+
const entry = entries && entries[0] && entries[0].files.values().next().value;
|
105
|
+
|
106
|
+
if (!error && !entry) {
|
107
|
+
error = Error(`WorkerPlugin: no entry for ${request}`);
|
108
|
+
}
|
109
|
+
|
110
|
+
if (error) {
|
111
|
+
return cb(error);
|
112
|
+
}
|
113
|
+
|
114
|
+
function workerCode() {
|
115
|
+
let blob;
|
116
|
+
|
117
|
+
try {
|
118
|
+
blob = new Blob([`importScripts('${this.workerUrl}');`], {
|
119
|
+
'type': 'application/javascript'
|
120
|
+
});
|
121
|
+
} catch (e1) {
|
122
|
+
throw new Error(e1);
|
123
|
+
}
|
124
|
+
|
125
|
+
let url = window.URL || window.webkitURL;
|
126
|
+
let blobUrl = url.createObjectURL(blob);
|
127
|
+
let worker = new Worker(blobUrl);
|
128
|
+
return worker;
|
129
|
+
}
|
130
|
+
|
131
|
+
return cb(null, `${options.esModule ? 'export default' : 'module.exports ='} {\n
|
132
|
+
workerUrl: __webpack_public_path__ + ${JSON.stringify(entry)}, \n
|
133
|
+
getInstance: ${workerCode} \n
|
134
|
+
}`);
|
135
|
+
});
|
136
|
+
}
|
@@ -1,35 +1,43 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = HMRMiddleware;
|
7
|
+
|
7
8
|
function pathMatch(url, path) {
|
8
9
|
if (url === path) {
|
9
10
|
return true;
|
10
11
|
}
|
11
|
-
|
12
|
+
|
13
|
+
let q = url.indexOf('?');
|
14
|
+
|
12
15
|
if (q === -1) {
|
13
16
|
return false;
|
14
17
|
}
|
18
|
+
|
15
19
|
return url.substring(0, q) === path;
|
16
20
|
}
|
17
21
|
|
18
22
|
function createEventStream(heartbeat) {
|
19
|
-
|
20
|
-
|
23
|
+
let clientId = 0;
|
24
|
+
let clients = {};
|
25
|
+
|
21
26
|
function everyClient(fn) {
|
22
|
-
Object.keys(clients).forEach(
|
27
|
+
Object.keys(clients).forEach(id => {
|
23
28
|
fn(clients[id]);
|
24
29
|
});
|
25
30
|
}
|
26
|
-
|
27
|
-
|
28
|
-
|
31
|
+
|
32
|
+
setInterval(() => {
|
33
|
+
everyClient(client => {
|
34
|
+
client.write(`data: ${JSON.stringify({
|
35
|
+
type: 'heartbeat'
|
36
|
+
})}\n\n`);
|
29
37
|
});
|
30
38
|
}, heartbeat).unref();
|
31
39
|
return {
|
32
|
-
handler: function
|
40
|
+
handler: function (req, res) {
|
33
41
|
req.socket.setKeepAlive(true);
|
34
42
|
res.writeHead(200, {
|
35
43
|
'Access-Control-Allow-Origin': '*',
|
@@ -38,15 +46,15 @@ function createEventStream(heartbeat) {
|
|
38
46
|
Connection: 'keep-alive'
|
39
47
|
});
|
40
48
|
res.write('\n');
|
41
|
-
|
49
|
+
let id = clientId++;
|
42
50
|
clients[id] = res;
|
43
|
-
req.on('close',
|
51
|
+
req.on('close', () => {
|
44
52
|
delete clients[id];
|
45
53
|
});
|
46
54
|
},
|
47
|
-
publish: function
|
48
|
-
everyClient(
|
49
|
-
client.write(
|
55
|
+
publish: function (payload) {
|
56
|
+
everyClient(client => {
|
57
|
+
client.write(`data: ${JSON.stringify(payload)}\n\n`);
|
50
58
|
});
|
51
59
|
}
|
52
60
|
};
|
@@ -56,25 +64,26 @@ function extractBundles(stats) {
|
|
56
64
|
// Stats has modules, single bundle
|
57
65
|
if (stats.modules) {
|
58
66
|
return [stats];
|
59
|
-
}
|
67
|
+
} // Stats has children, multiple bundles
|
68
|
+
|
60
69
|
|
61
|
-
// Stats has children, multiple bundles
|
62
70
|
if (stats.children && stats.children.length) {
|
63
71
|
return stats.children;
|
64
|
-
}
|
72
|
+
} // Not sure, assume single
|
73
|
+
|
65
74
|
|
66
|
-
// Not sure, assume single
|
67
75
|
return [stats];
|
68
76
|
}
|
69
77
|
|
70
78
|
function publishStats(action, statsResult, eventStream, log) {
|
71
79
|
// For multi-compiler, stats will be an object with a 'children' array of stats
|
72
|
-
|
73
|
-
|
80
|
+
let bundles = extractBundles(statsResult.toJson({
|
81
|
+
errorDetails: false
|
82
|
+
}));
|
83
|
+
bundles.forEach(stats => {
|
74
84
|
if (log) {
|
75
|
-
log(
|
76
|
-
}
|
77
|
-
// if (
|
85
|
+
log(`webpack built ${stats.name ? `${stats.name} ` : ''}${stats.hash} in ${stats.time}ms`);
|
86
|
+
} // if (
|
78
87
|
// // !force &&
|
79
88
|
// action !== 'sync' &&
|
80
89
|
// stats &&
|
@@ -86,6 +95,8 @@ function publishStats(action, statsResult, eventStream, log) {
|
|
86
95
|
// type: 'still-ok'
|
87
96
|
// });
|
88
97
|
// }
|
98
|
+
|
99
|
+
|
89
100
|
eventStream.publish({
|
90
101
|
type: 'hash',
|
91
102
|
data: stats.hash
|
@@ -109,56 +120,54 @@ function publishStats(action, statsResult, eventStream, log) {
|
|
109
120
|
});
|
110
121
|
}
|
111
122
|
|
112
|
-
function HMRMiddleware(compiler) {
|
113
|
-
|
114
|
-
|
115
|
-
opts.log =
|
116
|
-
// eslint-disable-next-line no-console
|
123
|
+
function HMRMiddleware(compiler, opts = {}) {
|
124
|
+
opts.log = // eslint-disable-next-line no-console
|
117
125
|
typeof opts.log === 'undefined' ? console.log.bind(console) : opts.log;
|
118
126
|
opts.path = opts.path || '/__webpack_hmr';
|
119
127
|
opts.heartbeat = opts.heartbeat || 10 * 1000;
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
compiler.hooks.beforeCompile.tap('HMRMiddleware', function (c, callback) {
|
128
|
+
let eventStream = createEventStream(opts.heartbeat);
|
129
|
+
let latestStats = null;
|
130
|
+
let loggedInfo = false;
|
131
|
+
compiler.hooks.beforeCompile.tap('HMRMiddleware', (c, callback) => {
|
126
132
|
if (opts.log && !loggedInfo) {
|
127
133
|
opts.log('webpack compilation starts...');
|
128
134
|
loggedInfo = true;
|
129
135
|
}
|
136
|
+
|
130
137
|
callback && callback();
|
131
138
|
});
|
132
|
-
|
133
|
-
compiler.hooks.compile.tap('HMRMiddleware', function () {
|
139
|
+
compiler.hooks.compile.tap('HMRMiddleware', () => {
|
134
140
|
latestStats = null;
|
141
|
+
|
135
142
|
if (opts.log) {
|
136
143
|
opts.log('webpack building...');
|
137
144
|
}
|
138
|
-
|
145
|
+
|
146
|
+
eventStream.publish({
|
147
|
+
type: 'building'
|
148
|
+
});
|
139
149
|
});
|
140
|
-
compiler.hooks.done.tap('HMRMiddleware',
|
150
|
+
compiler.hooks.done.tap('HMRMiddleware', statsResult => {
|
141
151
|
// Keep hold of latest stats so they can be propagated to new clients
|
142
152
|
latestStats = statsResult;
|
143
|
-
|
144
153
|
publishStats('built', latestStats, eventStream, opts.log);
|
145
154
|
});
|
146
|
-
|
155
|
+
|
156
|
+
let middleware = function (req, res, next) {
|
147
157
|
if (!pathMatch(req.url, opts.path)) {
|
148
158
|
return next();
|
149
159
|
}
|
150
|
-
|
151
|
-
// if (latestStats) {
|
160
|
+
|
161
|
+
eventStream.handler(req, res); // if (latestStats) {
|
152
162
|
// // Explicitly not passing in `log` fn as we don't want to log again on
|
153
163
|
// // the server
|
154
164
|
// // publishStats('sync', latestStats, eventStream);
|
155
165
|
// }
|
156
166
|
};
|
167
|
+
|
157
168
|
middleware.publish = eventStream.publish;
|
158
169
|
return middleware;
|
159
|
-
}
|
160
|
-
|
161
|
-
// function buildModuleMap(modules) {
|
170
|
+
} // function buildModuleMap(modules) {
|
162
171
|
// let map = {};
|
163
172
|
// modules.forEach(function(module) {
|
164
173
|
// map[module.id] = module.name;
|
@@ -1,18 +1,21 @@
|
|
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 _utils = require(
|
8
|
+
var _utils = require("../utils");
|
8
9
|
|
9
10
|
function SSTMiddleware(compiler, callback) {
|
10
|
-
compiler.hooks.done.tap('SSTMiddleware',
|
11
|
+
compiler.hooks.done.tap('SSTMiddleware', stats => {
|
11
12
|
(0, _utils.log)('Compilation finished!');
|
12
13
|
callback(stats.compilation.assets['js/moduleStats.js'].source());
|
13
14
|
});
|
14
|
-
return
|
15
|
+
return (res, req, next) => {
|
15
16
|
next();
|
16
17
|
};
|
17
18
|
}
|
18
|
-
|
19
|
+
|
20
|
+
var _default = SSTMiddleware;
|
21
|
+
exports.default = _default;
|