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