@doracli/webpack 0.0.3 → 0.0.4
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/README.md +1 -2
- package/lib/cjs/index.js +815 -106
- package/lib/esm/index.js +801 -108
- package/lib/type/index.d.ts +137 -26
- package/package.json +16 -16
package/lib/cjs/index.js
CHANGED
|
@@ -13,23 +13,9 @@ var TerserPlugin = require('terser-webpack-plugin');
|
|
|
13
13
|
var HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
14
14
|
var WebpackBundleAnalyzer = require('webpack-bundle-analyzer');
|
|
15
15
|
var WebpackBarPlugin = require('webpackbar');
|
|
16
|
+
var utils = require('@cclr/utils');
|
|
16
17
|
|
|
17
18
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
18
|
-
var build = function build(options) {
|
|
19
|
-
return new Promise(function (resolve, reject) {
|
|
20
|
-
try {
|
|
21
|
-
webpack(options, function (err, stats) {
|
|
22
|
-
resolve({
|
|
23
|
-
err: err,
|
|
24
|
-
stats: stats
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
} catch (error) {
|
|
28
|
-
reject(error);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
|
|
33
19
|
function _arrayLikeToArray(r, a) {
|
|
34
20
|
(null == a || a > r.length) && (a = r.length);
|
|
35
21
|
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
@@ -340,14 +326,14 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
340
326
|
}
|
|
341
327
|
}
|
|
342
328
|
|
|
343
|
-
var _excluded$
|
|
329
|
+
var _excluded$2 = ["output"],
|
|
344
330
|
_excluded2 = ["output"],
|
|
345
331
|
_excluded3 = ["static", "headers"];
|
|
346
332
|
var mergeWebpackConfig = function mergeWebpackConfig(first, second) {
|
|
347
333
|
if (!first) return second;
|
|
348
334
|
if (!second) return first;
|
|
349
335
|
var firstOutput = first.output,
|
|
350
|
-
restFirst = _objectWithoutProperties(first, _excluded$
|
|
336
|
+
restFirst = _objectWithoutProperties(first, _excluded$2);
|
|
351
337
|
var secondOutput = second.output,
|
|
352
338
|
restSecond = _objectWithoutProperties(second, _excluded2);
|
|
353
339
|
var output = firstOutput || secondOutput;
|
|
@@ -403,15 +389,16 @@ var Compiler = /*#__PURE__*/function (_CompilerBase) {
|
|
|
403
389
|
return _regenerator().w(function (_context2) {
|
|
404
390
|
while (1) switch (_context2.n) {
|
|
405
391
|
case 0:
|
|
406
|
-
compiler = webpack
|
|
392
|
+
compiler = webpack(mergeWebpackConfig(_this.initOptions, webpackConfig));
|
|
407
393
|
return _context2.a(2, {
|
|
394
|
+
compiler: compiler,
|
|
408
395
|
rebuild: function rebuild() {
|
|
409
396
|
return new Promise(function (resolve, reject) {
|
|
410
397
|
compiler.run(function (err, stats) {
|
|
411
398
|
if (err) return reject(err);
|
|
412
399
|
resolve({
|
|
413
|
-
|
|
414
|
-
|
|
400
|
+
err: err,
|
|
401
|
+
stats: stats
|
|
415
402
|
});
|
|
416
403
|
});
|
|
417
404
|
});
|
|
@@ -430,7 +417,10 @@ var Compiler = /*#__PURE__*/function (_CompilerBase) {
|
|
|
430
417
|
return _cancel.apply(this, arguments);
|
|
431
418
|
}
|
|
432
419
|
return cancel;
|
|
433
|
-
}()
|
|
420
|
+
}(),
|
|
421
|
+
server: function server(serverOptions, webpackConfig) {
|
|
422
|
+
return _this.server(serverOptions, webpackConfig, compiler);
|
|
423
|
+
}
|
|
434
424
|
});
|
|
435
425
|
}
|
|
436
426
|
}, _callee2);
|
|
@@ -494,11 +484,11 @@ var Compiler = /*#__PURE__*/function (_CompilerBase) {
|
|
|
494
484
|
while (1) switch (_context5.n) {
|
|
495
485
|
case 0:
|
|
496
486
|
return _context5.a(2, new Promise(function (resolve, reject) {
|
|
497
|
-
webpack
|
|
487
|
+
webpack(mergeWebpackConfig(_this.initOptions, webpackConfig), function (err, stats) {
|
|
498
488
|
if (err) return reject(err);
|
|
499
489
|
resolve({
|
|
500
|
-
|
|
501
|
-
|
|
490
|
+
err: err,
|
|
491
|
+
stats: stats
|
|
502
492
|
});
|
|
503
493
|
});
|
|
504
494
|
}));
|
|
@@ -511,16 +501,16 @@ var Compiler = /*#__PURE__*/function (_CompilerBase) {
|
|
|
511
501
|
}());
|
|
512
502
|
_defineProperty(_this, "watch", function (watchOptions, webpackConfig) {
|
|
513
503
|
var cb = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : lang.noop;
|
|
514
|
-
var compiler = webpack
|
|
504
|
+
var compiler = webpack(mergeWebpackConfig(_this.initOptions, webpackConfig));
|
|
515
505
|
return compiler.watch(watchOptions || {}, cb);
|
|
516
506
|
});
|
|
517
507
|
_defineProperty(_this, "server", /*#__PURE__*/function () {
|
|
518
|
-
var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(serverOptions, webpackConfig) {
|
|
508
|
+
var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(serverOptions, webpackConfig, userCompiler) {
|
|
519
509
|
var compiler, tempSrvConfig, open, port, host, devServer;
|
|
520
510
|
return _regenerator().w(function (_context6) {
|
|
521
511
|
while (1) switch (_context6.n) {
|
|
522
512
|
case 0:
|
|
523
|
-
compiler = webpack
|
|
513
|
+
compiler = userCompiler || webpack(mergeWebpackConfig(_this.initOptions, webpackConfig));
|
|
524
514
|
tempSrvConfig = mergeServerConfig(serverOptions, _this.initOptions.devServer);
|
|
525
515
|
open = tempSrvConfig.open, port = tempSrvConfig.port, host = tempSrvConfig.host;
|
|
526
516
|
devServer = new WebpackDevServer(mergeServerConfig(_objectSpread2(_objectSpread2({}, tempSrvConfig), {}, {
|
|
@@ -536,7 +526,7 @@ var Compiler = /*#__PURE__*/function (_CompilerBase) {
|
|
|
536
526
|
}
|
|
537
527
|
}, _callee6);
|
|
538
528
|
}));
|
|
539
|
-
return function (_x5, _x6) {
|
|
529
|
+
return function (_x5, _x6, _x7) {
|
|
540
530
|
return _ref7.apply(this, arguments);
|
|
541
531
|
};
|
|
542
532
|
}());
|
|
@@ -546,22 +536,19 @@ var Compiler = /*#__PURE__*/function (_CompilerBase) {
|
|
|
546
536
|
return _createClass(Compiler);
|
|
547
537
|
}(helper.CompilerBase);
|
|
548
538
|
|
|
549
|
-
var _excluded$2 = ["port"];
|
|
550
539
|
var getDevServer = function getDevServer(serviceConfig) {
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
var host = '127.0.0.1';
|
|
554
|
-
return _objectSpread2(_objectSpread2({
|
|
555
|
-
host: host,
|
|
540
|
+
return _objectSpread2({
|
|
541
|
+
host: '127.0.0.1',
|
|
556
542
|
// 地址
|
|
543
|
+
port: '7777',
|
|
544
|
+
hot: true,
|
|
545
|
+
// 开启热更新
|
|
557
546
|
open: false,
|
|
558
547
|
// 是否自动打开,关闭
|
|
559
548
|
setupExitSignals: true,
|
|
560
549
|
// 允许在 SIGINT 和 SIGTERM 信号时关闭开发服务器和退出进程。
|
|
561
550
|
compress: false,
|
|
562
551
|
// gzip压缩,开发环境不开启,提升热更新速度
|
|
563
|
-
hot: true,
|
|
564
|
-
// 开启热更新
|
|
565
552
|
historyApiFallback: true,
|
|
566
553
|
// 解决history路由404问题
|
|
567
554
|
// 托管静态资源public文件夹
|
|
@@ -573,9 +560,7 @@ var getDevServer = function getDevServer(serviceConfig) {
|
|
|
573
560
|
headers: {
|
|
574
561
|
'Access-Control-Allow-Origin': '*'
|
|
575
562
|
}
|
|
576
|
-
},
|
|
577
|
-
port: configPort || '7777'
|
|
578
|
-
});
|
|
563
|
+
}, serviceConfig);
|
|
579
564
|
};
|
|
580
565
|
|
|
581
566
|
var getDevtool = function getDevtool(envParams, devtoolConfig) {
|
|
@@ -765,10 +750,11 @@ var getOutput = function getOutput(envParams, output) {
|
|
|
765
750
|
}, extOutput);
|
|
766
751
|
};
|
|
767
752
|
|
|
768
|
-
var _excluded = ["minimize", "template"];
|
|
753
|
+
var _excluded = ["minimize", "template", "publicPath"];
|
|
769
754
|
var getHtmlWebpackPlugin = function getHtmlWebpackPlugin(params) {
|
|
770
755
|
var minimize = params.minimize,
|
|
771
756
|
template = params.template,
|
|
757
|
+
publicPath = params.publicPath,
|
|
772
758
|
extParams = _objectWithoutProperties(params, _excluded);
|
|
773
759
|
return new HtmlWebpackPlugin(_objectSpread2({
|
|
774
760
|
title: 'webpack5-react-ts',
|
|
@@ -777,6 +763,7 @@ var getHtmlWebpackPlugin = function getHtmlWebpackPlugin(params) {
|
|
|
777
763
|
template: template || presetHtmlTemplate,
|
|
778
764
|
inject: true,
|
|
779
765
|
// 自动注入静态资源
|
|
766
|
+
publicPath: publicPath || '/',
|
|
780
767
|
hash: true,
|
|
781
768
|
cache: false,
|
|
782
769
|
// 压缩html资源
|
|
@@ -873,14 +860,7 @@ var getReactPluginsPreset = function getReactPluginsPreset(envParams, options) {
|
|
|
873
860
|
var action = envParams.action;
|
|
874
861
|
var isDevelopment = action === 'server';
|
|
875
862
|
var WebpackBundleAnalyzerOptions = options.WebpackBundleAnalyzerOptions,
|
|
876
|
-
|
|
877
|
-
minimize = options.minimize;
|
|
878
|
-
|
|
879
|
-
// html入口文件路径
|
|
880
|
-
var rightFile = filePro.lookupFile(htmlEntryList);
|
|
881
|
-
if (!rightFile) {
|
|
882
|
-
helper.cLog.warn('init', 'not_found', '未找到 html 入口文件,将使用预设配置');
|
|
883
|
-
}
|
|
863
|
+
cssFilename = options.cssFilename;
|
|
884
864
|
var plugins = [getTsconfigPlugin(envParams)];
|
|
885
865
|
if (!isDevelopment) {
|
|
886
866
|
plugins.push(new ProgressPlugin({
|
|
@@ -894,15 +874,9 @@ var getReactPluginsPreset = function getReactPluginsPreset(envParams, options) {
|
|
|
894
874
|
percentBy: 'entries'
|
|
895
875
|
}));
|
|
896
876
|
}
|
|
897
|
-
if (action !== 'lib') {
|
|
898
|
-
plugins.push(getHtmlWebpackPlugin(_objectSpread2({
|
|
899
|
-
minimize: minimize,
|
|
900
|
-
template: rightFile || undefined
|
|
901
|
-
}, HtmlWebpackPluginOptions)));
|
|
902
|
-
}
|
|
903
877
|
if (!isDevelopment) {
|
|
904
878
|
plugins.push(new WebpackBarPlugin(), new MiniCssExtractPlugin({
|
|
905
|
-
filename: 'css/main.[contenthash].css'
|
|
879
|
+
filename: cssFilename || 'css/main.[contenthash].css'
|
|
906
880
|
}));
|
|
907
881
|
}
|
|
908
882
|
if (WebpackBundleAnalyzerOptions) {
|
|
@@ -931,10 +905,489 @@ var getResolveLoader = function getResolveLoader() {
|
|
|
931
905
|
};
|
|
932
906
|
};
|
|
933
907
|
|
|
934
|
-
|
|
935
|
-
|
|
908
|
+
/**
|
|
909
|
+
* webpack dev server 配置 中间件
|
|
910
|
+
* @returns
|
|
911
|
+
*/
|
|
912
|
+
var webpackDevServerMw = function webpackDevServerMw() {
|
|
913
|
+
return function (ctx) {
|
|
914
|
+
return function (next) {
|
|
915
|
+
return function () {
|
|
916
|
+
var _ctx$getDoraConfigSer = ctx.getDoraConfigServiceConfig(),
|
|
917
|
+
allowedHosts = _ctx$getDoraConfigSer.allowedHosts,
|
|
918
|
+
host = _ctx$getDoraConfigSer.host,
|
|
919
|
+
openBrowser = _ctx$getDoraConfigSer.openBrowser,
|
|
920
|
+
port = _ctx$getDoraConfigSer.port,
|
|
921
|
+
staticCfg = _ctx$getDoraConfigSer.static;
|
|
922
|
+
ctx.updateDevServerConfig(getDevServer({
|
|
923
|
+
allowedHosts: allowedHosts,
|
|
924
|
+
host: host,
|
|
925
|
+
port: port,
|
|
926
|
+
open: openBrowser,
|
|
927
|
+
static: Object.entries(staticCfg || {}).map(function (_ref) {
|
|
928
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
929
|
+
directory = _ref2[0],
|
|
930
|
+
publicPath = _ref2[1];
|
|
931
|
+
return {
|
|
932
|
+
directory: directory,
|
|
933
|
+
publicPath: publicPath
|
|
934
|
+
};
|
|
935
|
+
})
|
|
936
|
+
}));
|
|
937
|
+
return next();
|
|
938
|
+
};
|
|
939
|
+
};
|
|
940
|
+
};
|
|
941
|
+
};
|
|
942
|
+
|
|
943
|
+
/**
|
|
944
|
+
* webpack dev server 配置 中间件
|
|
945
|
+
* @returns
|
|
946
|
+
*/
|
|
947
|
+
var webpackDevtoolMw = function webpackDevtoolMw() {
|
|
948
|
+
return function (ctx) {
|
|
949
|
+
return function (next) {
|
|
950
|
+
return function () {
|
|
951
|
+
var devtool = getDevtool(ctx.envParams, ctx.geTDoraConfigWebpack().devtool);
|
|
952
|
+
ctx.updateWebpackConfig({
|
|
953
|
+
devtool: devtool
|
|
954
|
+
});
|
|
955
|
+
return next();
|
|
956
|
+
};
|
|
957
|
+
};
|
|
958
|
+
};
|
|
959
|
+
};
|
|
960
|
+
|
|
961
|
+
var envParamsMw = function envParamsMw(envParams) {
|
|
962
|
+
return function (ctx) {
|
|
963
|
+
return function (next) {
|
|
964
|
+
return /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
965
|
+
return _regenerator().w(function (_context) {
|
|
966
|
+
while (1) switch (_context.n) {
|
|
967
|
+
case 0:
|
|
968
|
+
ctx.updateEnvParams(envParams);
|
|
969
|
+
return _context.a(2, next());
|
|
970
|
+
}
|
|
971
|
+
}, _callee);
|
|
972
|
+
}));
|
|
973
|
+
};
|
|
974
|
+
};
|
|
975
|
+
};
|
|
976
|
+
|
|
977
|
+
/**
|
|
978
|
+
* webpack dev server 配置 中间件
|
|
979
|
+
* @returns
|
|
980
|
+
*/
|
|
981
|
+
var webpackExternalsMw = function webpackExternalsMw() {
|
|
982
|
+
return function (ctx) {
|
|
983
|
+
return function (next) {
|
|
984
|
+
return function () {
|
|
985
|
+
var _ctx$getDoraConfig = ctx.getDoraConfig(),
|
|
986
|
+
userExternals = _ctx$getDoraConfig.externals;
|
|
987
|
+
var externals = getExternals(userExternals);
|
|
988
|
+
ctx.updateWebpackConfig({
|
|
989
|
+
externals: externals
|
|
990
|
+
});
|
|
991
|
+
return next();
|
|
992
|
+
};
|
|
993
|
+
};
|
|
994
|
+
};
|
|
995
|
+
};
|
|
996
|
+
|
|
997
|
+
/**
|
|
998
|
+
* webpack dev server 配置 中间件
|
|
999
|
+
* @returns
|
|
1000
|
+
*/
|
|
1001
|
+
var webpackEntryWholeMw = function webpackEntryWholeMw() {
|
|
1002
|
+
return function (ctx) {
|
|
1003
|
+
return function (next) {
|
|
1004
|
+
return function () {
|
|
1005
|
+
var _ctx$getDoraConfig = ctx.getDoraConfig(),
|
|
1006
|
+
input = _ctx$getDoraConfig.input;
|
|
1007
|
+
if (!input) {
|
|
1008
|
+
var pList = scriptEntryList.reduce(function (pre, f) {
|
|
1009
|
+
scriptFileTypeList.forEach(function (e) {
|
|
1010
|
+
pre.push('./' + f + e);
|
|
1011
|
+
});
|
|
1012
|
+
return pre;
|
|
1013
|
+
}, []);
|
|
1014
|
+
input = filePro.lookupFile(pList, ctx.envParams.workRootDir);
|
|
1015
|
+
}
|
|
1016
|
+
if (!input) {
|
|
1017
|
+
helper.cLog.warn('dora-wr', 'getEntry', '需要有一个入口文件 index 或者 src/index');
|
|
1018
|
+
process.exit();
|
|
1019
|
+
}
|
|
1020
|
+
ctx.updateWebpackConfig({
|
|
1021
|
+
entry: input
|
|
1022
|
+
});
|
|
1023
|
+
return next();
|
|
1024
|
+
};
|
|
1025
|
+
};
|
|
1026
|
+
};
|
|
1027
|
+
};
|
|
1028
|
+
|
|
1029
|
+
/**
|
|
1030
|
+
* 处理 multiple
|
|
1031
|
+
* - 1. multiple 变成多入口,多出口 的 entry格式
|
|
1032
|
+
* - 2. 上下文一定要拆分过
|
|
1033
|
+
*/
|
|
1034
|
+
var multipleToInOutMw = function multipleToInOutMw() {
|
|
1035
|
+
return function (ctx) {
|
|
1036
|
+
return function (next) {
|
|
1037
|
+
return function () {
|
|
1038
|
+
var _ctx$configCtx$getDor;
|
|
1039
|
+
var _ctx$getDoraConfig = ctx.getDoraConfig(),
|
|
1040
|
+
multiple = _ctx$getDoraConfig.multiple;
|
|
1041
|
+
if (!multiple || !multiple.length) return next();
|
|
1042
|
+
var entry = {};
|
|
1043
|
+
var output = {
|
|
1044
|
+
// 使用 hash 避免冲突
|
|
1045
|
+
filename: '[name]/[chunkhash].js',
|
|
1046
|
+
path: path.join(ctx.envParams.workRootDir, ((_ctx$configCtx$getDor = ctx.configCtx.getDoraConfig().output) === null || _ctx$configCtx$getDor === void 0 ? void 0 : _ctx$configCtx$getDor.path) || 'dist')
|
|
1047
|
+
};
|
|
1048
|
+
multiple.forEach(function (module) {
|
|
1049
|
+
if (!module.name) {
|
|
1050
|
+
helper.cLog.warn('init', 'undefined', 'multiple 配置必须有 name 字段');
|
|
1051
|
+
return;
|
|
1052
|
+
}
|
|
1053
|
+
entry[module.name] = module.input;
|
|
1054
|
+
});
|
|
1055
|
+
ctx.updateWebpackConfig({
|
|
1056
|
+
entry: entry,
|
|
1057
|
+
output: output
|
|
1058
|
+
});
|
|
1059
|
+
return next();
|
|
1060
|
+
};
|
|
1061
|
+
};
|
|
1062
|
+
};
|
|
1063
|
+
};
|
|
1064
|
+
|
|
1065
|
+
/**
|
|
1066
|
+
* webpack dev server 配置 中间件
|
|
1067
|
+
* @returns
|
|
1068
|
+
*/
|
|
1069
|
+
var webpackOutputMw = function webpackOutputMw() {
|
|
1070
|
+
return function (ctx) {
|
|
1071
|
+
return function (next) {
|
|
1072
|
+
return function () {
|
|
1073
|
+
var _ctx$getDoraConfig = ctx.getDoraConfig(),
|
|
1074
|
+
userOutput = _ctx$getDoraConfig.output,
|
|
1075
|
+
clear = _ctx$getDoraConfig.clear;
|
|
1076
|
+
// const { publicPath } = ctx.geTDoraConfigWebpack();
|
|
1077
|
+
var output = getOutput(ctx.envParams, {
|
|
1078
|
+
filename: userOutput.file,
|
|
1079
|
+
path: userOutput.path,
|
|
1080
|
+
clean: clear
|
|
1081
|
+
// publicPath,
|
|
1082
|
+
});
|
|
1083
|
+
ctx.updateWebpackConfig({
|
|
1084
|
+
output: output
|
|
1085
|
+
});
|
|
1086
|
+
return next();
|
|
1087
|
+
};
|
|
1088
|
+
};
|
|
1089
|
+
};
|
|
1090
|
+
};
|
|
1091
|
+
|
|
1092
|
+
var CompilerStatusPlugin = /*#__PURE__*/function () {
|
|
1093
|
+
function CompilerStatusPlugin() {
|
|
1094
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1095
|
+
_classCallCheck(this, CompilerStatusPlugin);
|
|
1096
|
+
this.options = options;
|
|
1097
|
+
}
|
|
1098
|
+
return _createClass(CompilerStatusPlugin, [{
|
|
1099
|
+
key: "apply",
|
|
1100
|
+
value: function apply(compiler) {
|
|
1101
|
+
var _this = this;
|
|
1102
|
+
var startTime = 0;
|
|
1103
|
+
var lastHash;
|
|
1104
|
+
compiler.hooks.compile.tap('CompilerStatusPlugin', function () {
|
|
1105
|
+
startTime = Date.now();
|
|
1106
|
+
helper.cLog.log('pack', 'start', 'compiling...');
|
|
1107
|
+
});
|
|
1108
|
+
compiler.hooks.invalid.tap('CompilerStatusPlugin', function (file) {
|
|
1109
|
+
var rel = file ? path.relative(filePro.getCwd(), file) : 'unknown';
|
|
1110
|
+
helper.cLog.log('file', 'change', "\u27A9 ".concat(rel));
|
|
1111
|
+
startTime = Date.now();
|
|
1112
|
+
});
|
|
1113
|
+
compiler.hooks.done.tap('CompilerStatusPlugin', function (stats) {
|
|
1114
|
+
var time = Date.now() - startTime;
|
|
1115
|
+
var hasErrors = stats.hasErrors();
|
|
1116
|
+
var curHash = stats.hash;
|
|
1117
|
+
if (_this.options.silentOnDoneWhenNoChange && lastHash && curHash === lastHash && !hasErrors) {
|
|
1118
|
+
return;
|
|
1119
|
+
}
|
|
1120
|
+
lastHash = curHash;
|
|
1121
|
+
if (hasErrors) {
|
|
1122
|
+
var _json$errors;
|
|
1123
|
+
var json = stats.toJson({
|
|
1124
|
+
errors: true
|
|
1125
|
+
});
|
|
1126
|
+
helper.cLog.error('pack', 'failed', "(".concat(((_json$errors = json.errors) === null || _json$errors === void 0 ? void 0 : _json$errors.length) || 0, " errors, ").concat(time, " ms)"));
|
|
1127
|
+
} else {
|
|
1128
|
+
var _json$warnings;
|
|
1129
|
+
var _json = stats.toJson({
|
|
1130
|
+
warnings: true
|
|
1131
|
+
});
|
|
1132
|
+
var warnCount = ((_json$warnings = _json.warnings) === null || _json$warnings === void 0 ? void 0 : _json$warnings.length) || 0;
|
|
1133
|
+
if (warnCount > 0) {
|
|
1134
|
+
helper.cLog.warn('pack', 'warn', "(".concat(warnCount, " warnings, ").concat(time, " ms)"));
|
|
1135
|
+
} else {
|
|
1136
|
+
helper.cLog.info('pack', 'done', "build complete (".concat(time, " ms)"));
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
});
|
|
1140
|
+
compiler.hooks.failed.tap('CompilerStatusPlugin', function () {
|
|
1141
|
+
helper.cLog.error('pack', 'error', 'find error');
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
}]);
|
|
1145
|
+
}();
|
|
1146
|
+
|
|
1147
|
+
var statsLevelMap = {
|
|
1148
|
+
none: 'none',
|
|
1149
|
+
error: 'errors-only',
|
|
1150
|
+
warn: 'errors-warnings',
|
|
1151
|
+
log: 'minimal',
|
|
1152
|
+
info: 'normal',
|
|
1153
|
+
verbose: 'normal'
|
|
1154
|
+
};
|
|
1155
|
+
|
|
1156
|
+
/**
|
|
1157
|
+
* webpack dev server 配置 中间件
|
|
1158
|
+
* @returns
|
|
1159
|
+
*/
|
|
1160
|
+
var webpackLogLevelMw = function webpackLogLevelMw(logLevel) {
|
|
1161
|
+
return function (ctx) {
|
|
1162
|
+
return function (next) {
|
|
1163
|
+
return /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
1164
|
+
var _ctx$webpackConfig$pl;
|
|
1165
|
+
return _regenerator().w(function (_context) {
|
|
1166
|
+
while (1) switch (_context.n) {
|
|
1167
|
+
case 0:
|
|
1168
|
+
_context.n = 1;
|
|
1169
|
+
return next();
|
|
1170
|
+
case 1:
|
|
1171
|
+
// 关闭构建统计与基础设施日志
|
|
1172
|
+
ctx.updateWebpackConfig({
|
|
1173
|
+
stats: statsLevelMap[logLevel || 'warn'],
|
|
1174
|
+
infrastructureLogging: {
|
|
1175
|
+
level: logLevel
|
|
1176
|
+
},
|
|
1177
|
+
plugins: (_ctx$webpackConfig$pl = ctx.webpackConfig.plugins) === null || _ctx$webpackConfig$pl === void 0 ? void 0 : _ctx$webpackConfig$pl.concat([new CompilerStatusPlugin()])
|
|
1178
|
+
});
|
|
1179
|
+
ctx.updateDevServerConfig(helper.deepMergeObject({
|
|
1180
|
+
devMiddleware: {
|
|
1181
|
+
stats: 'errors-only'
|
|
1182
|
+
},
|
|
1183
|
+
client: {
|
|
1184
|
+
overlay: false
|
|
1185
|
+
}
|
|
1186
|
+
}, ctx.devServerConfig));
|
|
1187
|
+
case 2:
|
|
1188
|
+
return _context.a(2);
|
|
1189
|
+
}
|
|
1190
|
+
}, _callee);
|
|
1191
|
+
}));
|
|
1192
|
+
};
|
|
1193
|
+
};
|
|
1194
|
+
};
|
|
1195
|
+
|
|
1196
|
+
/**
|
|
1197
|
+
* webpack dev server 配置 中间件
|
|
1198
|
+
* @returns
|
|
1199
|
+
*/
|
|
1200
|
+
var webpackReactModuleMw = function webpackReactModuleMw() {
|
|
1201
|
+
return function (ctx) {
|
|
1202
|
+
return function (next) {
|
|
1203
|
+
return function () {
|
|
1204
|
+
var _ctx$geTDoraConfigWeb = ctx.geTDoraConfigWebpack(),
|
|
1205
|
+
loaderOptions = _ctx$geTDoraConfigWeb.loaderOptions;
|
|
1206
|
+
var module = getReactModulePreset(ctx.envParams, {
|
|
1207
|
+
postcssPluginExtra: loaderOptions === null || loaderOptions === void 0 ? void 0 : loaderOptions.postcssPluginExtra
|
|
1208
|
+
});
|
|
1209
|
+
ctx.updateWebpackConfig({
|
|
1210
|
+
module: module
|
|
1211
|
+
});
|
|
1212
|
+
return next();
|
|
1213
|
+
};
|
|
1214
|
+
};
|
|
1215
|
+
};
|
|
1216
|
+
};
|
|
1217
|
+
|
|
1218
|
+
/**
|
|
1219
|
+
* webpack dev server 配置 中间件
|
|
1220
|
+
* @returns
|
|
1221
|
+
*/
|
|
1222
|
+
var webpackPlainMw = function webpackPlainMw() {
|
|
1223
|
+
return function (ctx) {
|
|
1224
|
+
return function (next) {
|
|
1225
|
+
return function () {
|
|
1226
|
+
var _ctx$geTDoraConfigWeb = ctx.geTDoraConfigWebpack(),
|
|
1227
|
+
experiments = _ctx$geTDoraConfigWeb.experiments;
|
|
1228
|
+
var _ctx$getDoraConfig = ctx.getDoraConfig(),
|
|
1229
|
+
minimize = _ctx$getDoraConfig.minimize;
|
|
1230
|
+
var mode = getMode(ctx.envParams);
|
|
1231
|
+
var optimization = getOptimization({
|
|
1232
|
+
minimize: minimize
|
|
1233
|
+
});
|
|
1234
|
+
var devtool = getDevtool(ctx.envParams);
|
|
1235
|
+
ctx.updateWebpackConfig({
|
|
1236
|
+
devtool: devtool,
|
|
1237
|
+
mode: mode,
|
|
1238
|
+
experiments: experiments,
|
|
1239
|
+
optimization: optimization,
|
|
1240
|
+
plugins: [],
|
|
1241
|
+
module: {
|
|
1242
|
+
rules: []
|
|
1243
|
+
}
|
|
1244
|
+
});
|
|
1245
|
+
ctx.updateDevServerConfig({});
|
|
1246
|
+
return next();
|
|
1247
|
+
};
|
|
1248
|
+
};
|
|
1249
|
+
};
|
|
1250
|
+
};
|
|
1251
|
+
|
|
1252
|
+
/**
|
|
1253
|
+
* 替换 React 相关的插件配置
|
|
1254
|
+
* @returns
|
|
1255
|
+
*/
|
|
1256
|
+
var webpackReactPluginMw = function webpackReactPluginMw(options) {
|
|
1257
|
+
return function (ctx) {
|
|
1258
|
+
return function (next) {
|
|
1259
|
+
return /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
1260
|
+
var plugins;
|
|
1261
|
+
return _regenerator().w(function (_context) {
|
|
1262
|
+
while (1) switch (_context.n) {
|
|
1263
|
+
case 0:
|
|
1264
|
+
plugins = getReactPluginsPreset(ctx.envParams, options || {});
|
|
1265
|
+
ctx.updateWebpackConfig({
|
|
1266
|
+
plugins: plugins
|
|
1267
|
+
});
|
|
1268
|
+
return _context.a(2, next());
|
|
1269
|
+
}
|
|
1270
|
+
}, _callee);
|
|
1271
|
+
}));
|
|
1272
|
+
};
|
|
1273
|
+
};
|
|
1274
|
+
};
|
|
1275
|
+
|
|
1276
|
+
/**
|
|
1277
|
+
* 替换 React 相关的插件配置
|
|
1278
|
+
* @returns
|
|
1279
|
+
*/
|
|
1280
|
+
var webpackMultipleReactPluginMw = function webpackMultipleReactPluginMw() {
|
|
1281
|
+
return function (ctx) {
|
|
1282
|
+
return function (next) {
|
|
1283
|
+
return /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
1284
|
+
var plugins;
|
|
1285
|
+
return _regenerator().w(function (_context2) {
|
|
1286
|
+
while (1) switch (_context2.n) {
|
|
1287
|
+
case 0:
|
|
1288
|
+
plugins = getReactPluginsPreset(ctx.envParams, {
|
|
1289
|
+
cssFilename: '[name]/[chunkhash].css'
|
|
1290
|
+
});
|
|
1291
|
+
ctx.updateWebpackConfig({
|
|
1292
|
+
plugins: plugins
|
|
1293
|
+
});
|
|
1294
|
+
return _context2.a(2, next());
|
|
1295
|
+
}
|
|
1296
|
+
}, _callee2);
|
|
1297
|
+
}));
|
|
1298
|
+
};
|
|
1299
|
+
};
|
|
1300
|
+
};
|
|
1301
|
+
|
|
1302
|
+
/**
|
|
1303
|
+
* 添加 HtmlWebpackPlugin 插件配置
|
|
1304
|
+
* @returns
|
|
1305
|
+
*/
|
|
1306
|
+
var webpackHtmlPluginMw = function webpackHtmlPluginMw() {
|
|
1307
|
+
return function (ctx) {
|
|
1308
|
+
return function (next) {
|
|
1309
|
+
return /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
|
|
1310
|
+
var cdnConfig, action, _ctx$getDoraConfig, minimize, plugins, pluginsRes, rightFile;
|
|
1311
|
+
return _regenerator().w(function (_context3) {
|
|
1312
|
+
while (1) switch (_context3.n) {
|
|
1313
|
+
case 0:
|
|
1314
|
+
cdnConfig = ctx.configCtx.getCdnConfig();
|
|
1315
|
+
action = ctx.envParams.action;
|
|
1316
|
+
_ctx$getDoraConfig = ctx.getDoraConfig(), minimize = _ctx$getDoraConfig.minimize;
|
|
1317
|
+
plugins = ctx.webpackConfig.plugins;
|
|
1318
|
+
pluginsRes = plugins ? plugins : []; // html入口文件路径
|
|
1319
|
+
rightFile = filePro.lookupFile(htmlEntryList);
|
|
1320
|
+
if (!rightFile) {
|
|
1321
|
+
helper.cLog.warn('init', 'not_found', '未找到 html 入口文件,将使用预设配置');
|
|
1322
|
+
}
|
|
1323
|
+
if (action !== 'lib') {
|
|
1324
|
+
pluginsRes.push(getHtmlWebpackPlugin(_objectSpread2({
|
|
1325
|
+
minimize: minimize,
|
|
1326
|
+
template: rightFile || undefined
|
|
1327
|
+
}, cdnConfig)));
|
|
1328
|
+
}
|
|
1329
|
+
ctx.updateWebpackConfig({
|
|
1330
|
+
plugins: pluginsRes
|
|
1331
|
+
});
|
|
1332
|
+
return _context3.a(2, next());
|
|
1333
|
+
}
|
|
1334
|
+
}, _callee3);
|
|
1335
|
+
}));
|
|
1336
|
+
};
|
|
1337
|
+
};
|
|
1338
|
+
};
|
|
1339
|
+
|
|
1340
|
+
/**
|
|
1341
|
+
* webpack dev server 配置 中间件
|
|
1342
|
+
* @returns
|
|
1343
|
+
*/
|
|
1344
|
+
var webpackResolveMw = function webpackResolveMw() {
|
|
1345
|
+
return function (ctx) {
|
|
1346
|
+
return function (next) {
|
|
1347
|
+
return function () {
|
|
1348
|
+
var tsConfig = ctx.configCtx.getTsConfig();
|
|
1349
|
+
var _ctx$geTDoraConfigWeb = ctx.geTDoraConfigWebpack(),
|
|
1350
|
+
userConfigResolve = _ctx$geTDoraConfigWeb.resolve;
|
|
1351
|
+
var injectAlias = lang.get(userConfigResolve, 'alias', {});
|
|
1352
|
+
var injectExtensions = lang.get(userConfigResolve, 'extensions', []);
|
|
1353
|
+
var tsAlias = helper.getTsPathAlias(tsConfig);
|
|
1354
|
+
var resolveObj = {
|
|
1355
|
+
extensions: Array.from(new Set(['.ts', '.tsx', '.js', '.jsx'].concat(_toConsumableArray(injectExtensions)))),
|
|
1356
|
+
alias: _objectSpread2(_objectSpread2({
|
|
1357
|
+
'@src': path.resolve('src'),
|
|
1358
|
+
'@': path.resolve('src')
|
|
1359
|
+
}, tsAlias), injectAlias)
|
|
1360
|
+
};
|
|
1361
|
+
ctx.updateWebpackConfig({
|
|
1362
|
+
resolve: resolveObj
|
|
1363
|
+
});
|
|
1364
|
+
return next();
|
|
1365
|
+
};
|
|
1366
|
+
};
|
|
1367
|
+
};
|
|
936
1368
|
};
|
|
937
1369
|
|
|
1370
|
+
/**
|
|
1371
|
+
* webpack dev server 配置 中间件
|
|
1372
|
+
* @returns
|
|
1373
|
+
*/
|
|
1374
|
+
var webpackResolveLoaderMw = function webpackResolveLoaderMw() {
|
|
1375
|
+
return function (ctx) {
|
|
1376
|
+
return function (next) {
|
|
1377
|
+
return function () {
|
|
1378
|
+
var resolveLoader = getResolveLoader();
|
|
1379
|
+
ctx.updateWebpackConfig({
|
|
1380
|
+
resolveLoader: resolveLoader
|
|
1381
|
+
});
|
|
1382
|
+
return next();
|
|
1383
|
+
};
|
|
1384
|
+
};
|
|
1385
|
+
};
|
|
1386
|
+
};
|
|
1387
|
+
|
|
1388
|
+
/**
|
|
1389
|
+
* 单任务上下文
|
|
1390
|
+
*/
|
|
938
1391
|
var Ctx = /*#__PURE__*/function () {
|
|
939
1392
|
function Ctx(configCtx) {
|
|
940
1393
|
_classCallCheck(this, Ctx);
|
|
@@ -972,70 +1425,310 @@ var Ctx = /*#__PURE__*/function () {
|
|
|
972
1425
|
value: function geTDoraConfigWebpack() {
|
|
973
1426
|
return this.configCtx.getDoraConfig().webpackConfig || {};
|
|
974
1427
|
}
|
|
1428
|
+
}, {
|
|
1429
|
+
key: "getDoraConfigServiceConfig",
|
|
1430
|
+
value: function getDoraConfigServiceConfig() {
|
|
1431
|
+
return this.configCtx.getDoraConfig().serviceConfig || {};
|
|
1432
|
+
}
|
|
975
1433
|
}]);
|
|
976
1434
|
}();
|
|
977
1435
|
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1436
|
+
function collectAssetUrls(compiler, onChange, options) {
|
|
1437
|
+
var _ref = options || {},
|
|
1438
|
+
hostname = _ref.hostname,
|
|
1439
|
+
port = _ref.port;
|
|
1440
|
+
var urls = {};
|
|
1441
|
+
compiler.hooks.done.tap('CollectAssetUrls', function (stats) {
|
|
1442
|
+
var _compiler$options$out;
|
|
1443
|
+
urls = {};
|
|
1444
|
+
var json = stats.toJson({
|
|
1445
|
+
assets: true,
|
|
1446
|
+
entrypoints: true
|
|
1447
|
+
});
|
|
1448
|
+
// 处理 publicPath
|
|
1449
|
+
var publicPath = ((_compiler$options$out = compiler.options.output) === null || _compiler$options$out === void 0 ? void 0 : _compiler$options$out.publicPath) || '/';
|
|
1450
|
+
if (!publicPath || publicPath === 'auto') publicPath = '/';
|
|
1451
|
+
publicPath = publicPath.endsWith('/') ? publicPath.slice(0, -1) : publicPath;
|
|
1452
|
+
Object.entries(json.entrypoints || {}).forEach(function (_ref2) {
|
|
1453
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
1454
|
+
entry = _ref3[1];
|
|
1455
|
+
var moduleName = entry.name || 'unknown';
|
|
1456
|
+
urls[moduleName] = urls[moduleName] || {
|
|
1457
|
+
runtimeChunks: [],
|
|
1458
|
+
name: moduleName,
|
|
1459
|
+
scripts: [],
|
|
1460
|
+
styles: []
|
|
1461
|
+
};
|
|
1462
|
+
(entry.assets || []).forEach(function (a) {
|
|
1463
|
+
var name = a.name || a;
|
|
1464
|
+
if (typeof name !== 'string') return;
|
|
1465
|
+
var link = utils.uri.combine({
|
|
1466
|
+
protocol: hostname ? 'http:' : undefined,
|
|
1467
|
+
hostname: hostname,
|
|
1468
|
+
port: port,
|
|
1469
|
+
pathname: utils.uri.pathJoin(publicPath, name)
|
|
1470
|
+
});
|
|
1471
|
+
if (name.includes('.hot-update.')) {
|
|
1472
|
+
urls[moduleName].runtimeChunks.push(link);
|
|
1473
|
+
return;
|
|
1474
|
+
}
|
|
1475
|
+
if (name.endsWith('.js')) urls[moduleName].scripts.push(link);
|
|
1476
|
+
if (name.endsWith('.css')) urls[moduleName].styles.push(link);
|
|
1477
|
+
});
|
|
1478
|
+
});
|
|
1479
|
+
onChange === null || onChange === void 0 || onChange(urls);
|
|
1480
|
+
});
|
|
1481
|
+
return function () {
|
|
1482
|
+
return urls;
|
|
1483
|
+
}; // 返回一个 getter
|
|
1484
|
+
}
|
|
1000
1485
|
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options, compiler) {
|
|
1008
|
-
var tempSrvConfig, open, port, host, devServer;
|
|
1009
|
-
return _regenerator().w(function (_context) {
|
|
1010
|
-
while (1) switch (_context.n) {
|
|
1486
|
+
var htmlRouteGeneratorMw = /*#__PURE__*/function () {
|
|
1487
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(htmlAssetManager, configCtx) {
|
|
1488
|
+
var _cdnConfig$headAfterS, _cdnConfig$headAfterS2, _cdnConfig$bodyAfterS;
|
|
1489
|
+
var defaultHtml, htmlManage, cdnConfig;
|
|
1490
|
+
return _regenerator().w(function (_context2) {
|
|
1491
|
+
while (1) switch (_context2.n) {
|
|
1011
1492
|
case 0:
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
devServer = new WebpackDevServer(mergeServerConfig(_objectSpread2(_objectSpread2({}, tempSrvConfig), {}, {
|
|
1015
|
-
open: false
|
|
1016
|
-
})), compiler);
|
|
1017
|
-
_context.n = 1;
|
|
1018
|
-
return devServer.start();
|
|
1493
|
+
_context2.n = 1;
|
|
1494
|
+
return helper.getDefaultHtml(configCtx.getWorkRoot());
|
|
1019
1495
|
case 1:
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1496
|
+
defaultHtml = _context2.v;
|
|
1497
|
+
htmlManage = new helper.HtmlManage(helper.HtmlManage.parseHtml(defaultHtml));
|
|
1498
|
+
cdnConfig = configCtx.getCdnConfig();
|
|
1499
|
+
htmlManage.addHeads((_cdnConfig$headAfterS = cdnConfig.headAfterScript) === null || _cdnConfig$headAfterS === void 0 ? void 0 : _cdnConfig$headAfterS.map(function (script) {
|
|
1500
|
+
return {
|
|
1501
|
+
tagName: 'script',
|
|
1502
|
+
attrs: [{
|
|
1503
|
+
name: 'src',
|
|
1504
|
+
value: script
|
|
1505
|
+
}]
|
|
1506
|
+
};
|
|
1507
|
+
}));
|
|
1508
|
+
htmlManage.addHeads((_cdnConfig$headAfterS2 = cdnConfig.headAfterStyle) === null || _cdnConfig$headAfterS2 === void 0 ? void 0 : _cdnConfig$headAfterS2.map(function (style) {
|
|
1509
|
+
return {
|
|
1510
|
+
tagName: 'link',
|
|
1511
|
+
attrs: [{
|
|
1512
|
+
name: 'href',
|
|
1513
|
+
value: style
|
|
1514
|
+
}, {
|
|
1515
|
+
name: 'rel',
|
|
1516
|
+
value: 'stylesheet'
|
|
1517
|
+
}]
|
|
1518
|
+
};
|
|
1519
|
+
}));
|
|
1520
|
+
htmlManage.addBodys((_cdnConfig$bodyAfterS = cdnConfig.bodyAfterScript) === null || _cdnConfig$bodyAfterS === void 0 ? void 0 : _cdnConfig$bodyAfterS.map(function (script) {
|
|
1521
|
+
return {
|
|
1522
|
+
tagName: 'script',
|
|
1523
|
+
attrs: [{
|
|
1524
|
+
name: 'src',
|
|
1525
|
+
value: script
|
|
1526
|
+
}]
|
|
1527
|
+
};
|
|
1528
|
+
}));
|
|
1529
|
+
return _context2.a(2, /*#__PURE__*/function () {
|
|
1530
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(req, res, next) {
|
|
1531
|
+
var targetModuleName, moduleAsset, moduleHtmlManage, htmlStr, dynamicHtml;
|
|
1532
|
+
return _regenerator().w(function (_context) {
|
|
1533
|
+
while (1) switch (_context.n) {
|
|
1534
|
+
case 0:
|
|
1535
|
+
/**
|
|
1536
|
+
* 1. 页面路由
|
|
1537
|
+
* - 单页面应用会拦截到 index
|
|
1538
|
+
*/
|
|
1539
|
+
targetModuleName = htmlAssetManager.assetList.find(function (moduleName) {
|
|
1540
|
+
return new RegExp("^".concat(utils.uri.pathJoin(htmlAssetManager.publicPath, moduleName === 'index' ? '' : moduleName), "(/)?")).test(req.url || '');
|
|
1541
|
+
});
|
|
1542
|
+
if (!targetModuleName) {
|
|
1543
|
+
_context.n = 2;
|
|
1544
|
+
break;
|
|
1545
|
+
}
|
|
1546
|
+
_context.n = 1;
|
|
1547
|
+
return htmlAssetManager.getModuleHtml(targetModuleName);
|
|
1548
|
+
case 1:
|
|
1549
|
+
moduleAsset = htmlAssetManager.getModuleAsset(targetModuleName);
|
|
1550
|
+
moduleHtmlManage = htmlManage.copy();
|
|
1551
|
+
moduleHtmlManage.addHeads(moduleAsset.styles.map(function (style) {
|
|
1552
|
+
return {
|
|
1553
|
+
tagName: 'link',
|
|
1554
|
+
attrs: [{
|
|
1555
|
+
name: 'href',
|
|
1556
|
+
value: style
|
|
1557
|
+
}, {
|
|
1558
|
+
name: 'rel',
|
|
1559
|
+
value: 'stylesheet'
|
|
1560
|
+
}]
|
|
1561
|
+
};
|
|
1562
|
+
}));
|
|
1563
|
+
moduleHtmlManage.addBodys(moduleAsset.scripts.map(function (script) {
|
|
1564
|
+
return {
|
|
1565
|
+
tagName: 'script',
|
|
1566
|
+
attrs: [{
|
|
1567
|
+
name: 'src',
|
|
1568
|
+
value: script
|
|
1569
|
+
}]
|
|
1570
|
+
};
|
|
1571
|
+
}));
|
|
1572
|
+
htmlStr = moduleHtmlManage.generateHtml();
|
|
1573
|
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
1574
|
+
res.end(htmlStr);
|
|
1575
|
+
return _context.a(2);
|
|
1576
|
+
case 2:
|
|
1577
|
+
if (!new RegExp("^".concat(utils.uri.pathJoin(htmlAssetManager.publicPath, 'assetMap'), "(/)?$")).test(req.url || '')) {
|
|
1578
|
+
_context.n = 3;
|
|
1579
|
+
break;
|
|
1580
|
+
}
|
|
1581
|
+
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
1582
|
+
res.end(JSON.stringify(htmlAssetManager.getAssetMap()));
|
|
1583
|
+
return _context.a(2);
|
|
1584
|
+
case 3:
|
|
1585
|
+
if (!new RegExp("^".concat(utils.uri.pathJoin(htmlAssetManager.publicPath), "(/)?$")).test(req.url || '')) {
|
|
1586
|
+
_context.n = 4;
|
|
1587
|
+
break;
|
|
1588
|
+
}
|
|
1589
|
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
1590
|
+
dynamicHtml = new helper.DynamicHtml();
|
|
1591
|
+
dynamicHtml.addHeadTags(["\n <style>\n .item {\n margin: 8px 0;\n background-color: #6790ff;\n border-radius: 4px;\n }\n .item a {\n display: block;\n padding: 4px 8px;\n color: #fff;\n font-size: 18px;\n text-decoration: none;\n }\n </style>\n "]);
|
|
1592
|
+
dynamicHtml.addBodyTags(htmlAssetManager.assetList.map(function (name) {
|
|
1593
|
+
return "<div class=\"item\">\n <a href=\"".concat(utils.uri.pathJoin(htmlAssetManager.publicPath, name), "\">\n ").concat(name, "\n </a>\n </div>");
|
|
1594
|
+
}));
|
|
1595
|
+
dynamicHtml.addBodyTags(["<div class=\"item\"><a href=\"".concat(utils.uri.pathJoin(htmlAssetManager.publicPath, 'assetMap'), "\">\u8D44\u6E90</a></div>")]);
|
|
1596
|
+
res.end(dynamicHtml.generateHtmlTemplate('server 页面'));
|
|
1597
|
+
return _context.a(2);
|
|
1598
|
+
case 4:
|
|
1599
|
+
next();
|
|
1600
|
+
case 5:
|
|
1601
|
+
return _context.a(2);
|
|
1602
|
+
}
|
|
1603
|
+
}, _callee);
|
|
1604
|
+
}));
|
|
1605
|
+
return function (_x3, _x4, _x5) {
|
|
1606
|
+
return _ref2.apply(this, arguments);
|
|
1607
|
+
};
|
|
1608
|
+
}());
|
|
1025
1609
|
}
|
|
1026
|
-
},
|
|
1610
|
+
}, _callee2);
|
|
1027
1611
|
}));
|
|
1028
|
-
return function
|
|
1612
|
+
return function htmlRouteGeneratorMw(_x, _x2) {
|
|
1029
1613
|
return _ref.apply(this, arguments);
|
|
1030
1614
|
};
|
|
1031
1615
|
}();
|
|
1032
1616
|
|
|
1617
|
+
var ignorCompareKeys = ['name', 'input', 'output'];
|
|
1618
|
+
/**
|
|
1619
|
+
* 根据配置分组
|
|
1620
|
+
* @param multiple
|
|
1621
|
+
* @returns
|
|
1622
|
+
*/
|
|
1623
|
+
var splitDoraConfigMultiple = function splitDoraConfigMultiple(multiple) {
|
|
1624
|
+
var res = [];
|
|
1625
|
+
|
|
1626
|
+
// 初步分组
|
|
1627
|
+
var groupCatch = {};
|
|
1628
|
+
multiple.forEach(function (item) {
|
|
1629
|
+
var split = item.split,
|
|
1630
|
+
output = item.output;
|
|
1631
|
+
/** 环境隔离的单独放置 */
|
|
1632
|
+
if (split || output !== null && output !== void 0 && output.file) {
|
|
1633
|
+
res.push([item]);
|
|
1634
|
+
return;
|
|
1635
|
+
}
|
|
1636
|
+
// 按照配置的key 进行初步分组
|
|
1637
|
+
var key = Object.keys(item).join('--') + ((output === null || output === void 0 ? void 0 : output.path) || '');
|
|
1638
|
+
groupCatch[key] || (groupCatch[key] = {
|
|
1639
|
+
configs: []
|
|
1640
|
+
});
|
|
1641
|
+
groupCatch[key].configs.push(item);
|
|
1642
|
+
});
|
|
1643
|
+
|
|
1644
|
+
// 细化比较分组
|
|
1645
|
+
Object.values(groupCatch).forEach(function (_ref) {
|
|
1646
|
+
var configs = _ref.configs;
|
|
1647
|
+
var list = [];
|
|
1648
|
+
configs.forEach(function (config) {
|
|
1649
|
+
var isAdded = false;
|
|
1650
|
+
for (var i = 0; i < list.length; i++) {
|
|
1651
|
+
var group = list[i] || [];
|
|
1652
|
+
// 判断configs与哪个分组相等
|
|
1653
|
+
if (checkIsSameConfig(group[0], config)) {
|
|
1654
|
+
group.push(config);
|
|
1655
|
+
isAdded = true;
|
|
1656
|
+
break;
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
// 没有匹配到相等的分组,则新建一个分组
|
|
1660
|
+
if (!isAdded) {
|
|
1661
|
+
list.push([config]);
|
|
1662
|
+
}
|
|
1663
|
+
});
|
|
1664
|
+
res.push.apply(res, list);
|
|
1665
|
+
});
|
|
1666
|
+
return res;
|
|
1667
|
+
};
|
|
1668
|
+
|
|
1669
|
+
/**
|
|
1670
|
+
* 判断配置是否相等
|
|
1671
|
+
* @param a
|
|
1672
|
+
* @param b
|
|
1673
|
+
* @returns
|
|
1674
|
+
*/
|
|
1675
|
+
var checkIsSameConfig = function checkIsSameConfig(a, b) {
|
|
1676
|
+
if (!a || !b) return false;
|
|
1677
|
+
var aKeys = Object.keys(a).filter(function (key) {
|
|
1678
|
+
return !ignorCompareKeys.includes(key);
|
|
1679
|
+
});
|
|
1680
|
+
var bKeys = Object.keys(b).filter(function (key) {
|
|
1681
|
+
return !ignorCompareKeys.includes(key);
|
|
1682
|
+
});
|
|
1683
|
+
if (aKeys.length !== bKeys.length) {
|
|
1684
|
+
return false;
|
|
1685
|
+
}
|
|
1686
|
+
for (var i = 0; i < aKeys.length; i++) {
|
|
1687
|
+
var key = aKeys[i];
|
|
1688
|
+
if (!utils.deepCompareJson(a[key], b[key])) {
|
|
1689
|
+
return false;
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
return true;
|
|
1693
|
+
};
|
|
1694
|
+
|
|
1695
|
+
/**
|
|
1696
|
+
* 把配置拆分成多个标准的配置上下文,使用于webpack
|
|
1697
|
+
* - 主要是拆分成不同的入口输出分组
|
|
1698
|
+
* @param configCtx
|
|
1699
|
+
*/
|
|
1700
|
+
var splitDoraConfig = function splitDoraConfig(configCtx) {
|
|
1701
|
+
var doraConfig = configCtx.getDoraConfig();
|
|
1702
|
+
var multipleConfigList = doraConfig.multiple || [];
|
|
1703
|
+
|
|
1704
|
+
// 1. 单模块格式化成多模块形式
|
|
1705
|
+
if (!multipleConfigList.length) {
|
|
1706
|
+
multipleConfigList.push({
|
|
1707
|
+
name: 'index',
|
|
1708
|
+
input: doraConfig.input,
|
|
1709
|
+
output: doraConfig.output
|
|
1710
|
+
});
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
// 2. multiple 按照一定规则分组
|
|
1714
|
+
var multipleGroups = splitDoraConfigMultiple(multipleConfigList);
|
|
1715
|
+
|
|
1716
|
+
// 3. 分组后合并公共配置,生成多个标准配置上下文
|
|
1717
|
+
return multipleGroups.map(function (group) {
|
|
1718
|
+
var newConfigCtx = configCtx.copy();
|
|
1719
|
+
newConfigCtx.setDoraConfig(_objectSpread2(_objectSpread2(_objectSpread2({}, doraConfig), lang.obj.omit(group[0], ['input', 'output'])), {}, {
|
|
1720
|
+
multiple: group
|
|
1721
|
+
}));
|
|
1722
|
+
return newConfigCtx;
|
|
1723
|
+
});
|
|
1724
|
+
};
|
|
1725
|
+
|
|
1033
1726
|
exports.Compiler = Compiler;
|
|
1034
1727
|
exports.Ctx = Ctx;
|
|
1035
1728
|
exports.babelLoader = babelLoader;
|
|
1036
|
-
exports.
|
|
1037
|
-
exports.createCompiler = createCompiler;
|
|
1729
|
+
exports.collectAssetUrls = collectAssetUrls;
|
|
1038
1730
|
exports.cssLoader = cssLoader;
|
|
1731
|
+
exports.envParamsMw = envParamsMw;
|
|
1039
1732
|
exports.getBabelConfig = getBabelConfig;
|
|
1040
1733
|
exports.getCssBaseLoader = getCssBaseLoader;
|
|
1041
1734
|
exports.getDevServer = getDevServer;
|
|
@@ -1051,11 +1744,27 @@ exports.getReactPluginsPreset = getReactPluginsPreset;
|
|
|
1051
1744
|
exports.getResolve = getResolve;
|
|
1052
1745
|
exports.getResolveLoader = getResolveLoader;
|
|
1053
1746
|
exports.getTsconfigPlugin = getTsconfigPlugin;
|
|
1747
|
+
exports.htmlRouteGeneratorMw = htmlRouteGeneratorMw;
|
|
1054
1748
|
exports.lessLoader = lessLoader;
|
|
1055
1749
|
exports.mergeServerConfig = mergeServerConfig;
|
|
1056
1750
|
exports.mergeWebpackConfig = mergeWebpackConfig;
|
|
1751
|
+
exports.multipleToInOutMw = multipleToInOutMw;
|
|
1057
1752
|
exports.postcssLoader = postcssLoader;
|
|
1058
1753
|
exports.postcssPresetEnv = postcssPresetEnv;
|
|
1059
1754
|
exports.sassLoader = sassLoader;
|
|
1060
|
-
exports.
|
|
1755
|
+
exports.splitDoraConfig = splitDoraConfig;
|
|
1756
|
+
exports.splitDoraConfigMultiple = splitDoraConfigMultiple;
|
|
1061
1757
|
exports.styleLoader = styleLoader;
|
|
1758
|
+
exports.webpackDevServerMw = webpackDevServerMw;
|
|
1759
|
+
exports.webpackDevtoolMw = webpackDevtoolMw;
|
|
1760
|
+
exports.webpackEntryWholeMw = webpackEntryWholeMw;
|
|
1761
|
+
exports.webpackExternalsMw = webpackExternalsMw;
|
|
1762
|
+
exports.webpackHtmlPluginMw = webpackHtmlPluginMw;
|
|
1763
|
+
exports.webpackLogLevelMw = webpackLogLevelMw;
|
|
1764
|
+
exports.webpackMultipleReactPluginMw = webpackMultipleReactPluginMw;
|
|
1765
|
+
exports.webpackOutputMw = webpackOutputMw;
|
|
1766
|
+
exports.webpackPlainMw = webpackPlainMw;
|
|
1767
|
+
exports.webpackReactModuleMw = webpackReactModuleMw;
|
|
1768
|
+
exports.webpackReactPluginMw = webpackReactPluginMw;
|
|
1769
|
+
exports.webpackResolveLoaderMw = webpackResolveLoaderMw;
|
|
1770
|
+
exports.webpackResolveMw = webpackResolveMw;
|