@umijs/bundler-webpack 4.0.0-canary.20220718.2 → 4.0.0-canary.20220729.1
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/client/client/client.d.ts +1 -0
- package/client/client/client.js +295 -194
- 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 -2
- package/dist/build.js +105 -68
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +77 -69
- package/dist/config/_sampleFeature.d.ts +0 -1
- package/dist/config/_sampleFeature.js +33 -9
- package/dist/config/assetRules.d.ts +0 -1
- package/dist/config/assetRules.js +45 -36
- package/dist/config/bundleAnalyzerPlugin.d.ts +0 -1
- package/dist/config/bundleAnalyzerPlugin.js +39 -17
- package/dist/config/compressPlugin.d.ts +0 -1
- package/dist/config/compressPlugin.js +113 -95
- package/dist/config/config.d.ts +1 -1
- package/dist/config/config.js +204 -218
- package/dist/config/copyPlugin.d.ts +0 -1
- package/dist/config/copyPlugin.js +59 -40
- package/dist/config/cssRules.d.ts +0 -1
- package/dist/config/cssRules.js +136 -131
- package/dist/config/definePlugin.d.ts +0 -1
- package/dist/config/definePlugin.js +71 -35
- package/dist/config/detectDeadCode.d.ts +0 -1
- package/dist/config/detectDeadCode.js +120 -108
- package/dist/config/detectDeadCodePlugin.d.ts +0 -1
- package/dist/config/detectDeadCodePlugin.js +78 -63
- package/dist/config/fastRefreshPlugin.d.ts +0 -1
- package/dist/config/fastRefreshPlugin.js +39 -20
- package/dist/config/forkTSCheckerPlugin.d.ts +0 -1
- package/dist/config/forkTSCheckerPlugin.js +38 -18
- package/dist/config/harmonyLinkingErrorPlugin.d.ts +0 -1
- package/dist/config/harmonyLinkingErrorPlugin.js +48 -29
- package/dist/config/ignorePlugin.d.ts +0 -1
- package/dist/config/ignorePlugin.js +38 -14
- package/dist/config/javaScriptRules.d.ts +0 -1
- package/dist/config/javaScriptRules.js +147 -175
- package/dist/config/manifestPlugin.d.ts +0 -1
- package/dist/config/manifestPlugin.js +51 -15
- package/dist/config/miniCSSExtractPlugin.d.ts +0 -1
- package/dist/config/miniCSSExtractPlugin.js +42 -22
- package/dist/config/nodePolyfill.d.ts +0 -1
- package/dist/config/nodePolyfill.js +65 -26
- package/dist/config/nodePrefixPlugin.d.ts +0 -1
- package/dist/config/nodePrefixPlugin.js +36 -12
- package/dist/config/progressPlugin.d.ts +0 -1
- package/dist/config/progressPlugin.js +37 -13
- package/dist/config/purgecssWebpackPlugin.d.ts +0 -1
- package/dist/config/purgecssWebpackPlugin.js +41 -19
- package/dist/config/speedMeasureWebpackPlugin.d.ts +0 -1
- package/dist/config/speedMeasureWebpackPlugin.js +41 -20
- package/dist/config/ssrPlugin.d.ts +0 -1
- package/dist/config/ssrPlugin.js +83 -63
- package/dist/config/svgRules.d.ts +0 -1
- package/dist/config/svgRules.js +74 -46
- package/dist/constants.d.ts +0 -1
- package/dist/constants.js +57 -22
- package/dist/dev.d.ts +1 -2
- package/dist/dev.js +174 -135
- package/dist/index.d.ts +0 -1
- package/dist/index.js +22 -20
- package/dist/loader/svgr.d.ts +0 -1
- package/dist/loader/svgr.js +73 -54
- package/dist/loader/swc.d.ts +0 -1
- package/dist/loader/swc.js +110 -69
- package/dist/parcelCSS.d.ts +0 -1
- package/dist/parcelCSS.js +31 -27
- package/dist/plugins/ProgressPlugin.d.ts +0 -1
- package/dist/plugins/ProgressPlugin.js +66 -43
- package/dist/plugins/RuntimePublicPathPlugin.d.ts +0 -1
- package/dist/plugins/RuntimePublicPathPlugin.js +42 -25
- package/dist/plugins/_SamplePlugin.d.ts +0 -1
- package/dist/plugins/_SamplePlugin.js +39 -14
- package/dist/requireHook.d.ts +0 -1
- package/dist/requireHook.js +37 -27
- package/dist/schema.d.ts +0 -1
- package/dist/schema.js +123 -97
- package/dist/server/server.d.ts +0 -2
- package/dist/server/server.js +214 -184
- package/dist/server/ws.d.ts +0 -3
- package/dist/server/ws.js +63 -38
- package/dist/swcPlugins/autoCSSModules.d.ts +0 -1
- package/dist/swcPlugins/autoCSSModules.js +50 -31
- package/dist/swcPlugins/changeImportFromString.d.ts +0 -1
- package/dist/swcPlugins/changeImportFromString.js +31 -9
- package/dist/swcPlugins/lockCoreJS.d.ts +0 -1
- package/dist/swcPlugins/lockCoreJS.js +44 -20
- package/dist/types.d.ts +2 -2
- package/dist/types.js +61 -30
- package/dist/utils/browsersList.d.ts +0 -1
- package/dist/utils/browsersList.js +31 -8
- package/dist/utils/depMatch.d.ts +0 -1
- package/dist/utils/depMatch.js +63 -39
- package/dist/utils/formatWebpackMessages.d.ts +0 -1
- package/dist/utils/formatWebpackMessages.js +93 -91
- package/dist/utils/getEsBuildTarget.d.ts +0 -1
- package/dist/utils/getEsBuildTarget.js +32 -10
- package/package.json +10 -15
- package/compiled/react-refresh/LICENSE +0 -21
- package/compiled/react-refresh/index.js +0 -21
- package/compiled/react-refresh/package.json +0 -1
- package/dist/build.d.ts.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/client/client.d.ts +0 -2
- package/dist/client/client.d.ts.map +0 -1
- package/dist/client/client.js +0 -245
- package/dist/config/_sampleFeature.d.ts.map +0 -1
- package/dist/config/assetRules.d.ts.map +0 -1
- package/dist/config/bundleAnalyzerPlugin.d.ts.map +0 -1
- package/dist/config/compressPlugin.d.ts.map +0 -1
- package/dist/config/config.d.ts.map +0 -1
- package/dist/config/copyPlugin.d.ts.map +0 -1
- package/dist/config/cssRules.d.ts.map +0 -1
- package/dist/config/definePlugin.d.ts.map +0 -1
- package/dist/config/detectDeadCode.d.ts.map +0 -1
- package/dist/config/detectDeadCodePlugin.d.ts.map +0 -1
- package/dist/config/fastRefreshPlugin.d.ts.map +0 -1
- package/dist/config/forkTSCheckerPlugin.d.ts.map +0 -1
- package/dist/config/harmonyLinkingErrorPlugin.d.ts.map +0 -1
- package/dist/config/ignorePlugin.d.ts.map +0 -1
- package/dist/config/javaScriptRules.d.ts.map +0 -1
- package/dist/config/manifestPlugin.d.ts.map +0 -1
- package/dist/config/miniCSSExtractPlugin.d.ts.map +0 -1
- package/dist/config/nodePolyfill.d.ts.map +0 -1
- package/dist/config/nodePrefixPlugin.d.ts.map +0 -1
- package/dist/config/progressPlugin.d.ts.map +0 -1
- package/dist/config/purgecssWebpackPlugin.d.ts.map +0 -1
- package/dist/config/speedMeasureWebpackPlugin.d.ts.map +0 -1
- package/dist/config/ssrPlugin.d.ts.map +0 -1
- package/dist/config/svgRules.d.ts.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/dev.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/loader/svgr.d.ts.map +0 -1
- package/dist/loader/swc.d.ts.map +0 -1
- package/dist/parcelCSS.d.ts.map +0 -1
- package/dist/plugins/ProgressPlugin.d.ts.map +0 -1
- package/dist/plugins/RuntimePublicPathPlugin.d.ts.map +0 -1
- package/dist/plugins/_SamplePlugin.d.ts.map +0 -1
- package/dist/requireHook.d.ts.map +0 -1
- package/dist/schema.d.ts.map +0 -1
- package/dist/server/server.d.ts.map +0 -1
- package/dist/server/ws.d.ts.map +0 -1
- package/dist/swcPlugins/autoCSSModules.d.ts.map +0 -1
- package/dist/swcPlugins/changeImportFromString.d.ts.map +0 -1
- package/dist/swcPlugins/lockCoreJS.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/utils/browsersList.d.ts.map +0 -1
- package/dist/utils/depMatch.d.ts.map +0 -1
- package/dist/utils/formatWebpackMessages.d.ts.map +0 -1
- package/dist/utils/getEsBuildTarget.d.ts.map +0 -1
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
|
+
// src/server/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
|
-
res.sendFile(filePath);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
next();
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
// before middlewares
|
|
44
|
-
(opts.beforeMiddlewares || []).forEach((m) => app.use(m));
|
|
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
|
+
});
|
package/dist/server/ws.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
/// <reference types="node" />
|
|
4
2
|
import type { SpdyServer as Server } from '@umijs/bundler-utils';
|
|
5
3
|
import { Server as HttpServer } from 'http';
|
|
6
4
|
import { Http2Server } from 'http2';
|
|
@@ -11,4 +9,3 @@ export declare function createWebSocketServer(server: HttpServer | HttpsServer |
|
|
|
11
9
|
wss: WebSocket.Server;
|
|
12
10
|
close(): void;
|
|
13
11
|
};
|
|
14
|
-
//# sourceMappingURL=ws.d.ts.map
|
package/dist/server/ws.js
CHANGED
|
@@ -1,42 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
4
10
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
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));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// src/server/ws.ts
|
|
23
|
+
var ws_exports = {};
|
|
24
|
+
__export(ws_exports, {
|
|
25
|
+
createWebSocketServer: () => createWebSocketServer
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(ws_exports);
|
|
28
|
+
var import_utils = require("@umijs/utils");
|
|
29
|
+
var import_ws = __toESM(require("../../compiled/ws"));
|
|
9
30
|
function createWebSocketServer(server) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
const wss = new import_ws.default.Server({
|
|
32
|
+
noServer: true
|
|
33
|
+
});
|
|
34
|
+
server.on("upgrade", (req, socket, head) => {
|
|
35
|
+
if (req.headers["sec-websocket-protocol"] === "webpack-hmr") {
|
|
36
|
+
wss.handleUpgrade(req, socket, head, (ws) => {
|
|
37
|
+
wss.emit("connection", ws, req);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
wss.on("connection", (socket) => {
|
|
42
|
+
socket.send(JSON.stringify({ type: "connected" }));
|
|
43
|
+
});
|
|
44
|
+
wss.on("error", (e) => {
|
|
45
|
+
if (e.code !== "EADDRINUSE") {
|
|
46
|
+
console.error(import_utils.chalk.red(`WebSocket server error:
|
|
47
|
+
${e.stack || e.message}`));
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
send(message) {
|
|
52
|
+
wss.clients.forEach((client) => {
|
|
53
|
+
if (client.readyState === import_ws.default.OPEN) {
|
|
54
|
+
client.send(message);
|
|
26
55
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
},
|
|
36
|
-
wss,
|
|
37
|
-
close() {
|
|
38
|
-
wss.close();
|
|
39
|
-
},
|
|
40
|
-
};
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
wss,
|
|
59
|
+
close() {
|
|
60
|
+
wss.close();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
41
63
|
}
|
|
42
|
-
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
createWebSocketServer
|
|
67
|
+
});
|
|
@@ -1,34 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
4
10
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
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));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// src/swcPlugins/autoCSSModules.ts
|
|
23
|
+
var autoCSSModules_exports = {};
|
|
24
|
+
__export(autoCSSModules_exports, {
|
|
25
|
+
default: () => autoCSSModules_default
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(autoCSSModules_exports);
|
|
28
|
+
var import_Visitor = __toESM(require("@swc/core/Visitor"));
|
|
29
|
+
var import_utils = require("@umijs/utils");
|
|
30
|
+
var import_changeImportFromString = require("./changeImportFromString");
|
|
31
|
+
var AutoCSSModule = class extends import_Visitor.default {
|
|
32
|
+
visitTsType(expression) {
|
|
33
|
+
return expression;
|
|
34
|
+
}
|
|
35
|
+
visitModuleItem(n) {
|
|
36
|
+
if (n.type === "ImportDeclaration") {
|
|
37
|
+
return this.visitImportDeclaration(n);
|
|
23
38
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
39
|
+
return n;
|
|
40
|
+
}
|
|
41
|
+
visitImportDeclaration(expression) {
|
|
42
|
+
const { specifiers, source } = expression;
|
|
43
|
+
const { value } = source;
|
|
44
|
+
if (specifiers.length && (0, import_utils.isStyleFile)({ filename: value })) {
|
|
45
|
+
const newImportFrom = `${value}?modules`;
|
|
46
|
+
(0, import_changeImportFromString.changeImportFromString)(expression, newImportFrom);
|
|
32
47
|
}
|
|
33
|
-
|
|
34
|
-
|
|
48
|
+
return expression;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var autoCSSModules_default = AutoCSSModule;
|
|
52
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
53
|
+
0 && (module.exports = {});
|