@umijs/bundler-webpack 4.0.5 → 4.0.8
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/{dist → client}/client/client.d.ts +0 -0
- package/client/client/client.js +172 -192
- package/client/constants.d.ts +15 -0
- package/client/constants.js +28 -19
- package/client/utils/formatWebpackMessages.d.ts +12 -0
- package/client/utils/formatWebpackMessages.js +68 -86
- package/dist/build.d.ts +1 -1
- package/dist/build.js +105 -61
- package/dist/cli.js +77 -69
- package/dist/config/_sampleFeature.js +33 -9
- package/dist/config/assetRules.js +45 -36
- package/dist/config/bundleAnalyzerPlugin.js +39 -17
- package/dist/config/compressPlugin.js +113 -95
- package/dist/config/config.d.ts +1 -0
- package/dist/config/config.js +204 -215
- package/dist/config/copyPlugin.js +58 -33
- package/dist/config/cssRules.js +136 -131
- package/dist/config/definePlugin.d.ts +1 -0
- package/dist/config/definePlugin.js +71 -31
- package/dist/config/detectDeadCode.js +120 -108
- package/dist/config/detectDeadCodePlugin.js +78 -63
- package/dist/config/fastRefreshPlugin.js +39 -20
- package/dist/config/forkTSCheckerPlugin.js +38 -19
- package/dist/config/harmonyLinkingErrorPlugin.js +48 -29
- package/dist/config/ignorePlugin.js +38 -14
- package/dist/config/javaScriptRules.js +146 -173
- package/dist/config/manifestPlugin.js +51 -15
- package/dist/config/miniCSSExtractPlugin.js +42 -22
- package/dist/config/nodePolyfill.js +65 -26
- package/dist/config/nodePrefixPlugin.js +36 -12
- package/dist/config/progressPlugin.js +37 -13
- package/dist/config/purgecssWebpackPlugin.js +41 -19
- package/dist/config/speedMeasureWebpackPlugin.js +41 -20
- package/dist/config/ssrPlugin.js +83 -63
- package/dist/config/svgRules.js +74 -46
- package/dist/constants.js +57 -22
- package/dist/dev.d.ts +1 -1
- package/dist/dev.js +170 -129
- package/dist/index.d.ts +0 -2
- package/dist/index.js +22 -35
- package/dist/loader/svgr.js +73 -54
- package/dist/loader/swc.js +110 -69
- package/dist/parcelCSS.d.ts +2 -0
- package/dist/parcelCSS.js +32 -0
- package/dist/plugins/ProgressPlugin.js +66 -43
- package/dist/plugins/RuntimePublicPathPlugin.js +42 -23
- package/dist/plugins/_SamplePlugin.js +39 -14
- package/dist/requireHook.js +37 -27
- package/dist/schema.js +119 -95
- package/dist/server/server.d.ts +0 -1
- package/dist/server/server.js +214 -184
- package/dist/server/ws.d.ts +0 -2
- package/dist/server/ws.js +63 -38
- package/dist/swcPlugins/autoCSSModules.js +50 -31
- package/dist/swcPlugins/changeImportFromString.js +31 -9
- package/dist/swcPlugins/lockCoreJS.js +44 -20
- package/dist/types.js +61 -30
- package/dist/utils/browsersList.js +31 -8
- package/dist/utils/depMatch.js +63 -39
- package/dist/utils/formatWebpackMessages.js +93 -91
- package/dist/utils/getEsBuildTarget.js +32 -10
- package/package.json +9 -11
- package/compiled/fork-ts-checker-webpack-plugin/LICENSE +0 -21
- package/compiled/fork-ts-checker-webpack-plugin/fsevents.node +0 -0
- package/compiled/fork-ts-checker-webpack-plugin/index.js +0 -42
- package/compiled/fork-ts-checker-webpack-plugin/package.json +0 -1
- package/dist/client/client.js +0 -245
package/dist/schema.js
CHANGED
|
@@ -1,98 +1,122 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// schema.ts
|
|
20
|
+
var schema_exports = {};
|
|
21
|
+
__export(schema_exports, {
|
|
22
|
+
getSchemas: () => getSchemas
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(schema_exports);
|
|
25
|
+
var import_types = require("./types");
|
|
26
|
+
var options = [
|
|
27
|
+
"cheap-source-map",
|
|
28
|
+
"cheap-module-source-map",
|
|
29
|
+
"eval",
|
|
30
|
+
"eval-source-map",
|
|
31
|
+
"eval-cheap-source-map",
|
|
32
|
+
"eval-cheap-module-source-map",
|
|
33
|
+
"eval-nosources-cheap-source-map",
|
|
34
|
+
"eval-nosources-cheap-module-source-map",
|
|
35
|
+
"eval-nosources-source-map",
|
|
36
|
+
"source-map",
|
|
37
|
+
"hidden-source-map",
|
|
38
|
+
"hidden-nosources-cheap-source-map",
|
|
39
|
+
"hidden-nosources-cheap-module-source-map",
|
|
40
|
+
"hidden-nosources-source-map",
|
|
41
|
+
"hidden-cheap-source-map",
|
|
42
|
+
"hidden-cheap-module-source-map",
|
|
43
|
+
"inline-source-map",
|
|
44
|
+
"inline-cheap-source-map",
|
|
45
|
+
"inline-cheap-module-source-map",
|
|
46
|
+
"inline-nosources-cheap-source-map",
|
|
47
|
+
"inline-nosources-cheap-module-source-map",
|
|
48
|
+
"inline-nosources-source-map",
|
|
49
|
+
"nosources-source-map",
|
|
50
|
+
"nosources-cheap-source-map",
|
|
51
|
+
"nosources-cheap-module-source-map"
|
|
31
52
|
];
|
|
32
|
-
|
|
33
|
-
'(#@|@|#)?' + // maybe one of the pragmas
|
|
34
|
-
`(${options.join('$|')})`);
|
|
53
|
+
var DEVTOOL_REGEX = new RegExp(`^(#@|@|#)?(${options.join("$|")})`);
|
|
35
54
|
function getSchemas() {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
55
|
+
return {
|
|
56
|
+
alias: (Joi) => Joi.object(),
|
|
57
|
+
autoCSSModules: (Joi) => Joi.boolean(),
|
|
58
|
+
autoprefixer: (Joi) => Joi.object(),
|
|
59
|
+
cacheDirectoryPath: (Joi) => Joi.string(),
|
|
60
|
+
chainWebpack: (Joi) => Joi.function(),
|
|
61
|
+
copy: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.object({
|
|
62
|
+
from: Joi.string(),
|
|
63
|
+
to: Joi.string()
|
|
64
|
+
}), Joi.string())),
|
|
65
|
+
cssLoader: (Joi) => Joi.object(),
|
|
66
|
+
cssLoaderModules: (Joi) => Joi.object(),
|
|
67
|
+
cssMinifier: (Joi) => Joi.string().valid(import_types.CSSMinifier.cssnano, import_types.CSSMinifier.esbuild, import_types.CSSMinifier.parcelCSS, import_types.CSSMinifier.none),
|
|
68
|
+
cssMinifierOptions: (Joi) => Joi.object(),
|
|
69
|
+
deadCode: (Joi) => Joi.object(),
|
|
70
|
+
define: (Joi) => Joi.object(),
|
|
71
|
+
depTranspiler: (Joi) => Joi.string().valid(import_types.Transpiler.babel, import_types.Transpiler.esbuild, import_types.Transpiler.swc, import_types.Transpiler.none),
|
|
72
|
+
devtool: (Joi) => Joi.alternatives().try(Joi.string().regex(DEVTOOL_REGEX), Joi.boolean()),
|
|
73
|
+
esm: (Joi) => Joi.object(),
|
|
74
|
+
externals: (Joi) => Joi.alternatives().try(Joi.object(), Joi.string(), Joi.func()),
|
|
75
|
+
extraBabelIncludes: (Joi) => Joi.array().items(Joi.string()),
|
|
76
|
+
extraBabelPlugins: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.array())),
|
|
77
|
+
extraBabelPresets: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.array())),
|
|
78
|
+
extraPostCSSPlugins: (Joi) => Joi.array(),
|
|
79
|
+
fastRefresh: (Joi) => Joi.boolean(),
|
|
80
|
+
forkTSChecker: (Joi) => Joi.object(),
|
|
81
|
+
hash: (Joi) => Joi.boolean(),
|
|
82
|
+
https: (Joi) => Joi.object(),
|
|
83
|
+
ignoreMomentLocale: (Joi) => Joi.boolean(),
|
|
84
|
+
inlineLimit: (Joi) => Joi.number(),
|
|
85
|
+
jsMinifier: (Joi) => Joi.string().valid(import_types.JSMinifier.esbuild, import_types.JSMinifier.swc, import_types.JSMinifier.terser, import_types.JSMinifier.uglifyJs, import_types.JSMinifier.none),
|
|
86
|
+
jsMinifierOptions: (Joi) => Joi.object(),
|
|
87
|
+
lessLoader: (Joi) => Joi.object(),
|
|
88
|
+
manifest: (Joi) => Joi.object(),
|
|
89
|
+
mdx: (Joi) => Joi.object({
|
|
90
|
+
loader: Joi.string(),
|
|
91
|
+
loaderOptions: Joi.object()
|
|
92
|
+
}),
|
|
93
|
+
mfsu: (Joi) => Joi.alternatives(Joi.object({
|
|
94
|
+
cacheDirectory: Joi.string(),
|
|
95
|
+
chainWebpack: Joi.function(),
|
|
96
|
+
esbuild: Joi.boolean(),
|
|
97
|
+
exclude: Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.object().regex())),
|
|
98
|
+
include: Joi.array().items(Joi.string()),
|
|
99
|
+
mfName: Joi.string(),
|
|
100
|
+
runtimePublicPath: Joi.boolean(),
|
|
101
|
+
strategy: Joi.string().valid("eager", "normal").default("normal")
|
|
102
|
+
}), Joi.boolean()),
|
|
103
|
+
outputPath: (Joi) => Joi.string(),
|
|
104
|
+
postcssLoader: (Joi) => Joi.object(),
|
|
105
|
+
proxy: (Joi) => Joi.alternatives().try(Joi.object(), Joi.array()),
|
|
106
|
+
publicPath: (Joi) => Joi.string(),
|
|
107
|
+
purgeCSS: (Joi) => Joi.object(),
|
|
108
|
+
runtimePublicPath: (Joi) => Joi.object(),
|
|
109
|
+
sassLoader: (Joi) => Joi.object(),
|
|
110
|
+
srcTranspiler: (Joi) => Joi.string().valid(import_types.Transpiler.babel, import_types.Transpiler.esbuild, import_types.Transpiler.swc, import_types.Transpiler.none),
|
|
111
|
+
styleLoader: (Joi) => Joi.object(),
|
|
112
|
+
svgo: (Joi) => Joi.alternatives().try(Joi.object(), Joi.boolean()),
|
|
113
|
+
svgr: (Joi) => Joi.object(),
|
|
114
|
+
targets: (Joi) => Joi.object(),
|
|
115
|
+
theme: (Joi) => Joi.object(),
|
|
116
|
+
writeToDisk: (Joi) => Joi.boolean()
|
|
117
|
+
};
|
|
97
118
|
}
|
|
98
|
-
|
|
119
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
120
|
+
0 && (module.exports = {
|
|
121
|
+
getSchemas
|
|
122
|
+
});
|
package/dist/server/server.d.ts
CHANGED
package/dist/server/server.js
CHANGED
|
@@ -1,196 +1,226 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
|
+
};
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
4
35
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
+
|
|
39
|
+
// server.ts
|
|
40
|
+
var server_exports = {};
|
|
41
|
+
__export(server_exports, {
|
|
42
|
+
createServer: () => createServer
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(server_exports);
|
|
45
|
+
var import_bundler_utils = require("@umijs/bundler-utils");
|
|
46
|
+
var import_express = __toESM(require("@umijs/bundler-utils/compiled/express"));
|
|
47
|
+
var import_http_proxy_middleware = require("@umijs/bundler-webpack/compiled/http-proxy-middleware");
|
|
48
|
+
var import_webpack = __toESM(require("@umijs/bundler-webpack/compiled/webpack"));
|
|
49
|
+
var import_utils = require("@umijs/utils");
|
|
50
|
+
var import_assert = __toESM(require("assert"));
|
|
51
|
+
var import_cors = __toESM(require("cors"));
|
|
52
|
+
var import_fs = require("fs");
|
|
53
|
+
var import_http = __toESM(require("http"));
|
|
54
|
+
var import_path = require("path");
|
|
55
|
+
var import_constants = require("../constants");
|
|
56
|
+
var import_ws = require("./ws");
|
|
18
57
|
async function createServer(opts) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const ext = (0, path_1.extname)(filePath);
|
|
38
|
-
if (ext === '.js' && (0, fs_1.existsSync)(filePath)) {
|
|
39
|
-
res.sendFile(filePath);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
next();
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
// webpack dev middleware
|
|
46
|
-
const configs = Array.isArray(webpackConfig)
|
|
47
|
-
? webpackConfig
|
|
48
|
-
: [webpackConfig];
|
|
49
|
-
const progresses = [];
|
|
50
|
-
if (opts.onProgress) {
|
|
51
|
-
configs.forEach((config) => {
|
|
52
|
-
const progress = {
|
|
53
|
-
percent: 0,
|
|
54
|
-
status: 'waiting',
|
|
55
|
-
};
|
|
56
|
-
progresses.push(progress);
|
|
57
|
-
config.plugins.push(new webpack_1.default.ProgressPlugin((percent, msg) => {
|
|
58
|
-
progress.percent = percent;
|
|
59
|
-
progress.status = msg;
|
|
60
|
-
opts.onProgress({ progresses });
|
|
61
|
-
}));
|
|
62
|
-
});
|
|
58
|
+
const { webpackConfig, userConfig } = opts;
|
|
59
|
+
const { proxy } = userConfig;
|
|
60
|
+
const app = (0, import_express.default)();
|
|
61
|
+
app.use((0, import_cors.default)({
|
|
62
|
+
origin: true,
|
|
63
|
+
methods: ["GET", "HEAD", "PUT", "POST", "PATCH", "DELETE", "OPTIONS"],
|
|
64
|
+
credentials: true
|
|
65
|
+
}));
|
|
66
|
+
app.use(require("@umijs/bundler-webpack/compiled/compression")());
|
|
67
|
+
app.use((req, res, next) => {
|
|
68
|
+
const file = req.path;
|
|
69
|
+
const filePath = (0, import_path.join)(opts.cwd, file);
|
|
70
|
+
const ext = (0, import_path.extname)(filePath);
|
|
71
|
+
if (ext === ".js" && (0, import_fs.existsSync)(filePath)) {
|
|
72
|
+
import_utils.logger.info("[dev]", `${file} is responded with ${filePath}, remove it to use original file`);
|
|
73
|
+
res.sendFile(filePath);
|
|
74
|
+
} else {
|
|
75
|
+
next();
|
|
63
76
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
77
|
+
});
|
|
78
|
+
(opts.beforeMiddlewares || []).forEach((m) => app.use(m));
|
|
79
|
+
const configs = Array.isArray(webpackConfig) ? webpackConfig : [webpackConfig];
|
|
80
|
+
const progresses = [];
|
|
81
|
+
if (opts.onProgress) {
|
|
82
|
+
configs.forEach((config) => {
|
|
83
|
+
const progress = {
|
|
84
|
+
percent: 0,
|
|
85
|
+
status: "waiting"
|
|
86
|
+
};
|
|
87
|
+
progresses.push(progress);
|
|
88
|
+
config.plugins.push(new import_webpack.default.ProgressPlugin((percent, msg) => {
|
|
89
|
+
progress.percent = percent;
|
|
90
|
+
progress.status = msg;
|
|
91
|
+
opts.onProgress({ progresses });
|
|
92
|
+
}));
|
|
71
93
|
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if ((stats.errors && stats.errors.length > 0) ||
|
|
106
|
-
(stats.warnings && stats.warnings.length > 0)) {
|
|
107
|
-
if (stats.warnings && stats.warnings.length > 0) {
|
|
108
|
-
sendMessage(constants_1.MESSAGE_TYPE.warnings, stats.warnings, sender);
|
|
109
|
-
}
|
|
110
|
-
if (stats.errors && stats.errors.length > 0) {
|
|
111
|
-
sendMessage(constants_1.MESSAGE_TYPE.errors, stats.errors, sender);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
sendMessage(constants_1.MESSAGE_TYPE.ok, null, sender);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
function getStats(stats) {
|
|
119
|
-
return stats.toJson({
|
|
120
|
-
all: false,
|
|
121
|
-
hash: true,
|
|
122
|
-
assets: true,
|
|
123
|
-
warnings: true,
|
|
124
|
-
errors: true,
|
|
125
|
-
errorDetails: false,
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
function sendMessage(type, data, sender) {
|
|
129
|
-
(sender || ws).send(JSON.stringify({ type, data }));
|
|
94
|
+
}
|
|
95
|
+
const compiler = (0, import_webpack.default)(configs);
|
|
96
|
+
const webpackDevMiddleware = require("@umijs/bundler-webpack/compiled/webpack-dev-middleware");
|
|
97
|
+
const compilerMiddleware = webpackDevMiddleware(compiler, {
|
|
98
|
+
publicPath: userConfig.publicPath || "/",
|
|
99
|
+
writeToDisk: userConfig.writeToDisk,
|
|
100
|
+
stats: "none"
|
|
101
|
+
});
|
|
102
|
+
app.use(compilerMiddleware);
|
|
103
|
+
let stats;
|
|
104
|
+
let isFirstCompile = true;
|
|
105
|
+
compiler.compilers.forEach(addHooks);
|
|
106
|
+
function addHooks(compiler2) {
|
|
107
|
+
compiler2.hooks.invalid.tap("server", () => {
|
|
108
|
+
sendMessage(import_constants.MESSAGE_TYPE.invalid);
|
|
109
|
+
});
|
|
110
|
+
compiler2.hooks.done.tap("server", (_stats) => {
|
|
111
|
+
var _a;
|
|
112
|
+
stats = _stats;
|
|
113
|
+
sendStats(getStats(stats));
|
|
114
|
+
(_a = opts.onDevCompileDone) == null ? void 0 : _a.call(opts, {
|
|
115
|
+
stats,
|
|
116
|
+
isFirstCompile,
|
|
117
|
+
time: stats.endTime - stats.startTime
|
|
118
|
+
});
|
|
119
|
+
isFirstCompile = false;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function sendStats(stats2, force, sender) {
|
|
123
|
+
const shouldEmit = !force && stats2 && (!stats2.errors || stats2.errors.length === 0) && (!stats2.warnings || stats2.warnings.length === 0) && stats2.assets && stats2.assets.every((asset) => !asset.emitted);
|
|
124
|
+
if (shouldEmit) {
|
|
125
|
+
sendMessage(import_constants.MESSAGE_TYPE.stillOk, null, sender);
|
|
126
|
+
return;
|
|
130
127
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
onProxyRes(proxyRes, req, res) {
|
|
142
|
-
var _a, _b;
|
|
143
|
-
proxyRes.headers['x-real-url'] =
|
|
144
|
-
((_a = new URL(req.url || '', target)) === null || _a === void 0 ? void 0 : _a.href) || '';
|
|
145
|
-
(_b = proxyConfig.onProxyRes) === null || _b === void 0 ? void 0 : _b.call(proxyConfig, proxyRes, req, res);
|
|
146
|
-
},
|
|
147
|
-
}));
|
|
148
|
-
}
|
|
149
|
-
});
|
|
128
|
+
sendMessage(import_constants.MESSAGE_TYPE.hash, stats2.hash, sender);
|
|
129
|
+
if (stats2.errors && stats2.errors.length > 0 || stats2.warnings && stats2.warnings.length > 0) {
|
|
130
|
+
if (stats2.warnings && stats2.warnings.length > 0) {
|
|
131
|
+
sendMessage(import_constants.MESSAGE_TYPE.warnings, stats2.warnings, sender);
|
|
132
|
+
}
|
|
133
|
+
if (stats2.errors && stats2.errors.length > 0) {
|
|
134
|
+
sendMessage(import_constants.MESSAGE_TYPE.errors, stats2.errors, sender);
|
|
135
|
+
}
|
|
136
|
+
} else {
|
|
137
|
+
sendMessage(import_constants.MESSAGE_TYPE.ok, null, sender);
|
|
150
138
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
139
|
+
}
|
|
140
|
+
function getStats(stats2) {
|
|
141
|
+
return stats2.toJson({
|
|
142
|
+
all: false,
|
|
143
|
+
hash: true,
|
|
144
|
+
assets: true,
|
|
145
|
+
warnings: true,
|
|
146
|
+
errors: true,
|
|
147
|
+
errorDetails: false
|
|
155
148
|
});
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
149
|
+
}
|
|
150
|
+
function sendMessage(type, data, sender) {
|
|
151
|
+
(sender || ws).send(JSON.stringify({ type, data }));
|
|
152
|
+
}
|
|
153
|
+
if (proxy) {
|
|
154
|
+
const proxyArr = Array.isArray(proxy) ? proxy : proxy.target ? [proxy] : Object.keys(proxy).map((key) => {
|
|
155
|
+
return __spreadProps(__spreadValues({}, proxy[key]), {
|
|
156
|
+
context: key
|
|
157
|
+
});
|
|
163
158
|
});
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
159
|
+
proxyArr.forEach((proxy2) => {
|
|
160
|
+
let middleware;
|
|
161
|
+
if (proxy2.target) {
|
|
162
|
+
(0, import_assert.default)(typeof proxy2.target === "string", "proxy.target must be string");
|
|
163
|
+
(0, import_assert.default)(proxy2.context, "proxy.context must be supplied");
|
|
164
|
+
middleware = (0, import_http_proxy_middleware.createProxyMiddleware)(proxy2.context, __spreadProps(__spreadValues({}, proxy2), {
|
|
165
|
+
onProxyRes(proxyRes, req, res) {
|
|
166
|
+
var _a, _b;
|
|
167
|
+
proxyRes.headers["x-real-url"] = ((_a = new URL(req.url || "", proxy2.target)) == null ? void 0 : _a.href) || "";
|
|
168
|
+
(_b = proxy2.onProxyRes) == null ? void 0 : _b.call(proxy2, proxyRes, req, res);
|
|
169
|
+
}
|
|
170
|
+
}));
|
|
171
|
+
}
|
|
172
|
+
app.use((req, res, next) => {
|
|
173
|
+
const bypassUrl = typeof proxy2.bypass === "function" ? proxy2.bypass(req, res, proxy2) : null;
|
|
174
|
+
if (typeof bypassUrl === "string") {
|
|
175
|
+
req.url = bypassUrl;
|
|
176
|
+
return next();
|
|
177
|
+
} else if (bypassUrl === false) {
|
|
178
|
+
return res.end(404);
|
|
179
|
+
} else if ((bypassUrl === null || bypassUrl === void 0) && middleware) {
|
|
180
|
+
return middleware(req, res, next);
|
|
181
|
+
} else {
|
|
182
|
+
next();
|
|
174
183
|
}
|
|
184
|
+
});
|
|
175
185
|
});
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
186
|
+
}
|
|
187
|
+
(opts.afterMiddlewares || []).forEach((m) => {
|
|
188
|
+
app.use(m.toString().includes(`{ compiler }`) ? m({ compiler }) : m);
|
|
189
|
+
});
|
|
190
|
+
app.use(require("@umijs/bundler-webpack/compiled/connect-history-api-fallback")({
|
|
191
|
+
index: "/"
|
|
192
|
+
}));
|
|
193
|
+
app.use("/__umi_ping", (_, res) => {
|
|
194
|
+
res.end("pong");
|
|
195
|
+
});
|
|
196
|
+
app.get("/", (_req, res, next) => {
|
|
197
|
+
res.set("Content-Type", "text/html");
|
|
198
|
+
const htmlPath = (0, import_path.join)(opts.cwd, "index.html");
|
|
199
|
+
if ((0, import_fs.existsSync)(htmlPath)) {
|
|
200
|
+
(0, import_fs.createReadStream)(htmlPath).on("error", next).pipe(res);
|
|
201
|
+
} else {
|
|
202
|
+
next();
|
|
181
203
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
204
|
+
});
|
|
205
|
+
const server = userConfig.https ? await (0, import_bundler_utils.createHttpsServer)(app, userConfig.https) : import_http.default.createServer(app);
|
|
206
|
+
if (!server) {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
const ws = (0, import_ws.createWebSocketServer)(server);
|
|
210
|
+
ws.wss.on("connection", (socket) => {
|
|
211
|
+
if (stats) {
|
|
212
|
+
sendStats(getStats(stats), false, socket);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
const protocol = userConfig.https ? "https:" : "http:";
|
|
216
|
+
const port = opts.port || 8e3;
|
|
217
|
+
server.listen(port, () => {
|
|
218
|
+
const host = opts.host && opts.host !== "0.0.0.0" ? opts.host : "localhost";
|
|
219
|
+
import_utils.logger.ready(`App listening at ${import_utils.chalk.green(`${protocol}//${host}:${port}`)}`);
|
|
220
|
+
});
|
|
221
|
+
return server;
|
|
195
222
|
}
|
|
196
|
-
|
|
223
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
224
|
+
0 && (module.exports = {
|
|
225
|
+
createServer
|
|
226
|
+
});
|