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