@rsbuild/core 0.0.26 → 0.0.28
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/cli/commands.js +1 -1
- package/dist/cli/prepare.js +1 -1
- package/dist/plugins/splitChunks.d.ts +0 -2
- package/dist/plugins/splitChunks.js +3 -13
- package/dist/rspack-provider/config.js +1 -0
- package/dist/rspack-provider/core/createCompiler.d.ts +3 -4
- package/dist/rspack-provider/core/createCompiler.js +21 -11
- package/dist/rspack-provider/core/createContext.js +1 -1
- package/dist/rspack-provider/core/initConfigs.d.ts +2 -2
- package/dist/rspack-provider/core/rspackConfig.js +1 -4
- package/dist/server/devServer.d.ts +3 -3
- package/dist/server/devServer.js +11 -7
- package/dist/server/middlewares.d.ts +1 -1
- package/dist/server/middlewares.js +2 -2
- package/dist/server/prodServer.d.ts +2 -1
- package/dist/server/prodServer.js +11 -1
- package/dist/server/proxy.d.ts +3 -4
- package/dist/server/proxy.js +15 -17
- package/package.json +3 -4
package/dist/cli/commands.js
CHANGED
|
@@ -49,7 +49,7 @@ async function init(options) {
|
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
function runCli() {
|
|
52
|
-
import_commander.program.name("rsbuild").usage("<command> [options]").version("0.0.
|
|
52
|
+
import_commander.program.name("rsbuild").usage("<command> [options]").version("0.0.28");
|
|
53
53
|
import_commander.program.command("dev").option(`--open`, "open the page in browser on startup").option(
|
|
54
54
|
"-c --config <config>",
|
|
55
55
|
"specify the configuration file, can be a relative or absolute path"
|
package/dist/cli/prepare.js
CHANGED
|
@@ -34,7 +34,7 @@ function prepareCli() {
|
|
|
34
34
|
if (!npm_execpath || npm_execpath.includes("npx-cli.js")) {
|
|
35
35
|
console.log();
|
|
36
36
|
}
|
|
37
|
-
import_rslog.logger.greet(` ${`Rsbuild v${"0.0.
|
|
37
|
+
import_rslog.logger.greet(` ${`Rsbuild v${"0.0.28"}`}
|
|
38
38
|
`);
|
|
39
39
|
}
|
|
40
40
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,4 +1,2 @@
|
|
|
1
1
|
import type { RsbuildPlugin } from '../types';
|
|
2
|
-
/** Expect to match path just like "./node_modules/react-router/" */
|
|
3
|
-
export declare const createDependenciesRegExp: (...dependencies: (string | RegExp)[]) => RegExp;
|
|
4
2
|
export declare function pluginSplitChunks(): RsbuildPlugin;
|
|
@@ -28,7 +28,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var splitChunks_exports = {};
|
|
30
30
|
__export(splitChunks_exports, {
|
|
31
|
-
createDependenciesRegExp: () => createDependenciesRegExp,
|
|
32
31
|
pluginSplitChunks: () => pluginSplitChunks
|
|
33
32
|
});
|
|
34
33
|
module.exports = __toCommonJS(splitChunks_exports);
|
|
@@ -50,23 +49,15 @@ function getUserDefinedCacheGroups(forceSplitting) {
|
|
|
50
49
|
});
|
|
51
50
|
return cacheGroups;
|
|
52
51
|
}
|
|
53
|
-
const DEPENDENCY_MATCH_TEMPL = /[\\/]node_modules[\\/](<SOURCES>)[\\/]/.source;
|
|
54
|
-
const createDependenciesRegExp = (...dependencies) => {
|
|
55
|
-
const sources = dependencies.map(
|
|
56
|
-
(d) => typeof d === "string" ? d : d.source
|
|
57
|
-
);
|
|
58
|
-
const expr = DEPENDENCY_MATCH_TEMPL.replace("<SOURCES>", sources.join("|"));
|
|
59
|
-
return new RegExp(expr);
|
|
60
|
-
};
|
|
61
52
|
function splitByExperience(ctx) {
|
|
62
53
|
const { override, polyfill, defaultConfig, userDefinedCacheGroups } = ctx;
|
|
63
54
|
const experienceCacheGroup = {};
|
|
64
55
|
const packageRegExps = {
|
|
65
|
-
lodash: createDependenciesRegExp("lodash", "lodash-es"),
|
|
66
|
-
axios: createDependenciesRegExp("axios", /axios-.+/)
|
|
56
|
+
lodash: (0, import_shared.createDependenciesRegExp)("lodash", "lodash-es"),
|
|
57
|
+
axios: (0, import_shared.createDependenciesRegExp)("axios", /axios-.+/)
|
|
67
58
|
};
|
|
68
59
|
if (polyfill === "entry" || polyfill === "usage") {
|
|
69
|
-
packageRegExps.polyfill = createDependenciesRegExp(
|
|
60
|
+
packageRegExps.polyfill = (0, import_shared.createDependenciesRegExp)(
|
|
70
61
|
"tslib",
|
|
71
62
|
"core-js",
|
|
72
63
|
"@babel/runtime",
|
|
@@ -233,6 +224,5 @@ function pluginSplitChunks() {
|
|
|
233
224
|
}
|
|
234
225
|
// Annotate the CommonJS export names for ESM import in node:
|
|
235
226
|
0 && (module.exports = {
|
|
236
|
-
createDependenciesRegExp,
|
|
237
227
|
pluginSplitChunks
|
|
238
228
|
});
|
|
@@ -26,6 +26,7 @@ module.exports = __toCommonJS(config_exports);
|
|
|
26
26
|
var import_shared = require("@rsbuild/shared");
|
|
27
27
|
const createDefaultConfig = () => ({
|
|
28
28
|
dev: (0, import_shared.getDefaultDevConfig)(),
|
|
29
|
+
server: (0, import_shared.getDefaultServerConfig)(),
|
|
29
30
|
html: (0, import_shared.getDefaultHtmlConfig)(),
|
|
30
31
|
source: (0, import_shared.getDefaultSourceConfig)(),
|
|
31
32
|
output: (0, import_shared.getDefaultOutputConfig)(),
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { type RspackConfig } from '@rsbuild/shared';
|
|
2
|
-
import { type RspackCompiler, type RspackMultiCompiler } from '@rsbuild/shared';
|
|
1
|
+
import { type RspackConfig, CreateDevMiddlewareReturns, type RspackCompiler, type RspackMultiCompiler } from '@rsbuild/shared';
|
|
3
2
|
import { type InitConfigsOptions } from './initConfigs';
|
|
4
3
|
import type { Context } from '../../types';
|
|
5
4
|
export declare function createCompiler({
|
|
@@ -8,5 +7,5 @@ export declare function createCompiler({
|
|
|
8
7
|
}: {
|
|
9
8
|
context: Context;
|
|
10
9
|
rspackConfigs: RspackConfig[];
|
|
11
|
-
}): Promise<
|
|
12
|
-
export declare function createDevMiddleware(options: InitConfigsOptions, customCompiler?: RspackCompiler | RspackMultiCompiler): Promise<
|
|
10
|
+
}): Promise<RspackCompiler | RspackMultiCompiler>;
|
|
11
|
+
export declare function createDevMiddleware(options: InitConfigsOptions, customCompiler?: RspackCompiler | RspackMultiCompiler): Promise<CreateDevMiddlewareReturns>;
|
|
@@ -44,7 +44,7 @@ async function createCompiler({
|
|
|
44
44
|
bundlerConfigs: rspackConfigs
|
|
45
45
|
});
|
|
46
46
|
const { rspack } = await Promise.resolve().then(() => __toESM(require("@rspack/core")));
|
|
47
|
-
const compiler = rspack(rspackConfigs);
|
|
47
|
+
const compiler = rspackConfigs.length === 1 ? rspack(rspackConfigs[0]) : rspack(rspackConfigs);
|
|
48
48
|
let isFirstCompile = true;
|
|
49
49
|
compiler.hooks.watchRun.tap("rsbuild:compiling", () => {
|
|
50
50
|
import_shared.logger.start("Compiling...");
|
|
@@ -54,15 +54,22 @@ async function createCompiler({
|
|
|
54
54
|
all: false,
|
|
55
55
|
timings: true
|
|
56
56
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
57
|
+
const printTime = (c, index) => {
|
|
58
|
+
if (c.time) {
|
|
59
|
+
const time = (0, import_shared.prettyTime)(c.time / 1e3);
|
|
60
|
+
const target = Array.isArray(context.target) ? context.target[index] : context.target;
|
|
61
|
+
const name = import_shared.TARGET_ID_MAP[target || "web"];
|
|
62
|
+
import_shared.logger.ready(`${name} compiled in ${time}`);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
if (!stats.hasErrors()) {
|
|
66
|
+
if (obj.children) {
|
|
67
|
+
obj.children.forEach((c, index) => {
|
|
68
|
+
printTime(c, index);
|
|
69
|
+
});
|
|
70
|
+
} else {
|
|
71
|
+
printTime(obj, 0);
|
|
72
|
+
}
|
|
66
73
|
}
|
|
67
74
|
const { message, level } = (0, import_shared.formatStats)(stats);
|
|
68
75
|
if (level === "error") {
|
|
@@ -93,7 +100,10 @@ async function createDevMiddleware(options, customCompiler) {
|
|
|
93
100
|
rspackConfigs
|
|
94
101
|
});
|
|
95
102
|
}
|
|
96
|
-
return
|
|
103
|
+
return {
|
|
104
|
+
devMiddleware: (0, import_devMiddleware.getDevMiddleware)(compiler),
|
|
105
|
+
compiler
|
|
106
|
+
};
|
|
97
107
|
}
|
|
98
108
|
// Annotate the CommonJS export names for ESM import in node:
|
|
99
109
|
0 && (module.exports = {
|
|
@@ -64,7 +64,7 @@ function createContextByConfig(options, bundlerType, sourceConfig = {}, outputCo
|
|
|
64
64
|
entry: sourceConfig.entry || // TODO: remove sourceConfig.entries in v0.2.0
|
|
65
65
|
// compat with previous config
|
|
66
66
|
sourceConfig.entries || getDefaultEntry(rootPath),
|
|
67
|
-
version: "0.0.
|
|
67
|
+
version: "0.0.28",
|
|
68
68
|
target,
|
|
69
69
|
rootPath,
|
|
70
70
|
distPath,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type PluginStore, type CreateRsbuildOptions } from '@rsbuild/shared';
|
|
1
|
+
import { type PluginStore, type RspackConfig, type CreateRsbuildOptions } from '@rsbuild/shared';
|
|
2
2
|
import type { Context } from '../../types';
|
|
3
3
|
export type InitConfigsOptions = {
|
|
4
4
|
context: Context;
|
|
@@ -10,5 +10,5 @@ export declare function initConfigs({
|
|
|
10
10
|
pluginStore,
|
|
11
11
|
rsbuildOptions
|
|
12
12
|
}: InitConfigsOptions): Promise<{
|
|
13
|
-
rspackConfigs:
|
|
13
|
+
rspackConfigs: RspackConfig[];
|
|
14
14
|
}>;
|
|
@@ -104,9 +104,6 @@ async function getChainUtils(target) {
|
|
|
104
104
|
HtmlPlugin
|
|
105
105
|
};
|
|
106
106
|
}
|
|
107
|
-
const convertToRspackConfig = (config) => {
|
|
108
|
-
return config;
|
|
109
|
-
};
|
|
110
107
|
async function generateRspackConfig({
|
|
111
108
|
target,
|
|
112
109
|
context
|
|
@@ -121,7 +118,7 @@ async function generateRspackConfig({
|
|
|
121
118
|
ProvidePlugin
|
|
122
119
|
}
|
|
123
120
|
});
|
|
124
|
-
let rspackConfig =
|
|
121
|
+
let rspackConfig = chain.toConfig();
|
|
125
122
|
rspackConfig = await modifyRspackConfig(
|
|
126
123
|
context,
|
|
127
124
|
rspackConfig,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/// <reference types="node" />
|
|
4
4
|
import { Server } from 'http';
|
|
5
5
|
import type { ListenOptions } from 'net';
|
|
6
|
-
import { RsbuildDevServerOptions,
|
|
6
|
+
import { RsbuildDevServerOptions, CreateDevMiddlewareReturns, DevServerContext, StartDevServerOptions, StartServerResult } from '@rsbuild/shared';
|
|
7
7
|
import connect from '@rsbuild/shared/connect';
|
|
8
8
|
export declare class RsbuildDevServer {
|
|
9
9
|
private readonly dev;
|
|
@@ -22,9 +22,9 @@ export declare class RsbuildDevServer {
|
|
|
22
22
|
}
|
|
23
23
|
export declare function startDevServer<Options extends {
|
|
24
24
|
context: DevServerContext;
|
|
25
|
-
}>(options: Options, createDevMiddleware: (options: Options, compiler: StartDevServerOptions['compiler']) => Promise<
|
|
25
|
+
}>(options: Options, createDevMiddleware: (options: Options, compiler: StartDevServerOptions['compiler']) => Promise<CreateDevMiddlewareReturns>, {
|
|
26
26
|
open,
|
|
27
|
-
compiler,
|
|
27
|
+
compiler: customCompiler,
|
|
28
28
|
printURLs,
|
|
29
29
|
strictPort,
|
|
30
30
|
logger: customLogger,
|
package/dist/server/devServer.js
CHANGED
|
@@ -105,18 +105,18 @@ class RsbuildDevServer {
|
|
|
105
105
|
next();
|
|
106
106
|
});
|
|
107
107
|
if (dev.proxy) {
|
|
108
|
-
const { middlewares
|
|
109
|
-
app && handleUpgrade(app);
|
|
108
|
+
const { middlewares } = (0, import_proxy.createProxyMiddleware)(dev.proxy, app);
|
|
110
109
|
middlewares.forEach((middleware) => {
|
|
111
110
|
this.middlewares.use(middleware);
|
|
112
111
|
});
|
|
113
112
|
}
|
|
114
113
|
devMiddleware.init(app);
|
|
115
114
|
devMiddleware.middleware && this.middlewares.use(devMiddleware.middleware);
|
|
115
|
+
const { distPath } = this.output;
|
|
116
116
|
this.middlewares.use(
|
|
117
117
|
(0, import_middlewares.getHtmlFallbackMiddleware)({
|
|
118
|
-
distPath: (0, import_path.join)(this.pwd,
|
|
119
|
-
|
|
118
|
+
distPath: (0, import_path.isAbsolute)(distPath) ? distPath : (0, import_path.join)(this.pwd, distPath),
|
|
119
|
+
publicPath: this.output.publicPath,
|
|
120
120
|
callback: devMiddleware.middleware
|
|
121
121
|
})
|
|
122
122
|
);
|
|
@@ -159,7 +159,7 @@ class RsbuildDevServer {
|
|
|
159
159
|
}
|
|
160
160
|
async function startDevServer(options, createDevMiddleware, {
|
|
161
161
|
open,
|
|
162
|
-
compiler,
|
|
162
|
+
compiler: customCompiler,
|
|
163
163
|
printURLs = true,
|
|
164
164
|
strictPort = false,
|
|
165
165
|
logger: customLogger,
|
|
@@ -189,14 +189,18 @@ async function startDevServer(options, createDevMiddleware, {
|
|
|
189
189
|
(_c = (_b = rsbuildConfig.output) == null ? void 0 : _b.distPath) == null ? void 0 : _c.html
|
|
190
190
|
);
|
|
191
191
|
(0, import_shared.debug)("create dev server");
|
|
192
|
-
const devMiddleware = await createDevMiddleware(
|
|
192
|
+
const { devMiddleware, compiler } = await createDevMiddleware(
|
|
193
|
+
options,
|
|
194
|
+
customCompiler
|
|
195
|
+
);
|
|
196
|
+
const publicPath = compiler.compilers ? (0, import_shared.getPublicPathFromCompiler)(compiler.compilers[0]) : (0, import_shared.getPublicPathFromCompiler)(compiler);
|
|
193
197
|
const server = new RsbuildDevServer({
|
|
194
198
|
pwd: options.context.rootPath,
|
|
195
199
|
devMiddleware,
|
|
196
200
|
dev: devServerConfig,
|
|
197
201
|
output: {
|
|
198
202
|
distPath: ((_e = (_d = rsbuildConfig.output) == null ? void 0 : _d.distPath) == null ? void 0 : _e.root) || import_shared.ROOT_DIST_DIR,
|
|
199
|
-
|
|
203
|
+
publicPath
|
|
200
204
|
}
|
|
201
205
|
});
|
|
202
206
|
(0, import_shared.debug)("create dev server done");
|
|
@@ -3,6 +3,6 @@ export declare const faviconFallbackMiddleware: Middleware;
|
|
|
3
3
|
export declare const notFoundMiddleware: Middleware;
|
|
4
4
|
export declare const getHtmlFallbackMiddleware: (params: {
|
|
5
5
|
distPath: string;
|
|
6
|
-
|
|
6
|
+
publicPath: string;
|
|
7
7
|
callback?: Middleware;
|
|
8
8
|
}) => Middleware;
|
|
@@ -48,7 +48,7 @@ const notFoundMiddleware = (_req, res, _next) => {
|
|
|
48
48
|
res.statusCode = 404;
|
|
49
49
|
res.end();
|
|
50
50
|
};
|
|
51
|
-
const getHtmlFallbackMiddleware = ({
|
|
51
|
+
const getHtmlFallbackMiddleware = ({ publicPath, distPath, callback }) => {
|
|
52
52
|
return (req, res, next) => {
|
|
53
53
|
if (
|
|
54
54
|
// Only accept GET or HEAD
|
|
@@ -69,7 +69,7 @@ const getHtmlFallbackMiddleware = ({ assetPrefix, distPath, callback }) => {
|
|
|
69
69
|
const tryRewrite = (filePath, newUrl) => {
|
|
70
70
|
var _a;
|
|
71
71
|
if (outputFileSystem.existsSync(filePath) && callback) {
|
|
72
|
-
newUrl = (0, import_shared.urlJoin)(
|
|
72
|
+
newUrl = (0, import_shared.urlJoin)(publicPath, newUrl);
|
|
73
73
|
(_a = import_shared.debug) == null ? void 0 : _a(`Rewriting ${req.method} ${req.url} to ${newUrl}`);
|
|
74
74
|
req.url = newUrl;
|
|
75
75
|
return callback(req, res, (...args) => {
|
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
import type { ListenOptions } from 'net';
|
|
4
4
|
import { Server } from 'http';
|
|
5
5
|
import connect from '@rsbuild/shared/connect';
|
|
6
|
-
import { Context, RsbuildConfig, StartServerResult, PreviewServerOptions } from '@rsbuild/shared';
|
|
6
|
+
import { Context, RsbuildConfig, StartServerResult, PreviewServerOptions, ServerConfig } from '@rsbuild/shared';
|
|
7
7
|
type RsbuildProdServerOptions = {
|
|
8
8
|
pwd: string;
|
|
9
9
|
output: {
|
|
10
10
|
path: string;
|
|
11
11
|
assetPrefix?: string;
|
|
12
12
|
};
|
|
13
|
+
serverConfig: ServerConfig;
|
|
13
14
|
};
|
|
14
15
|
export declare class RsbuildProdServer {
|
|
15
16
|
private app;
|
|
@@ -49,6 +49,15 @@ class RsbuildProdServer {
|
|
|
49
49
|
await this.applyDefaultMiddlewares();
|
|
50
50
|
}
|
|
51
51
|
async applyDefaultMiddlewares() {
|
|
52
|
+
const { headers } = this.options.serverConfig;
|
|
53
|
+
if (headers) {
|
|
54
|
+
this.middlewares.use((_req, res, next) => {
|
|
55
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
56
|
+
res.setHeader(key, value);
|
|
57
|
+
}
|
|
58
|
+
next();
|
|
59
|
+
});
|
|
60
|
+
}
|
|
52
61
|
this.applyStaticAssetMiddleware();
|
|
53
62
|
this.middlewares.use(import_middlewares.faviconFallbackMiddleware);
|
|
54
63
|
}
|
|
@@ -103,7 +112,8 @@ async function startProdServer(context, rsbuildConfig, { printURLs = true } = {}
|
|
|
103
112
|
output: {
|
|
104
113
|
path: ((_c = (_b = rsbuildConfig.output) == null ? void 0 : _b.distPath) == null ? void 0 : _c.root) || import_shared.ROOT_DIST_DIR,
|
|
105
114
|
assetPrefix: (_d = rsbuildConfig.output) == null ? void 0 : _d.assetPrefix
|
|
106
|
-
}
|
|
115
|
+
},
|
|
116
|
+
serverConfig: rsbuildConfig.server || {}
|
|
107
117
|
});
|
|
108
118
|
const httpServer = await server.createHTTPServer();
|
|
109
119
|
await server.onInit(httpServer);
|
package/dist/server/proxy.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import http from 'http';
|
|
2
|
-
import { RequestHandler } from 'http-proxy-middleware';
|
|
3
|
-
import { ProxyDetail, RequestHandler as Middleware, RsbuildProxyOptions } from '@rsbuild/shared';
|
|
2
|
+
import { RequestHandler } from '@rsbuild/shared/http-proxy-middleware';
|
|
3
|
+
import { type ProxyDetail, type RequestHandler as Middleware, type RsbuildProxyOptions } from '@rsbuild/shared';
|
|
4
4
|
export declare function formatProxyOptions(proxyOptions: RsbuildProxyOptions): ProxyDetail[];
|
|
5
5
|
export type HttpUpgradeHandler = NonNullable<RequestHandler['upgrade']>;
|
|
6
|
-
export declare const createProxyMiddleware: (proxyOptions: RsbuildProxyOptions) => {
|
|
6
|
+
export declare const createProxyMiddleware: (proxyOptions: RsbuildProxyOptions, app: http.Server) => {
|
|
7
7
|
middlewares: Middleware[];
|
|
8
|
-
handleUpgrade: (server: http.Server) => void;
|
|
9
8
|
};
|
package/dist/server/proxy.js
CHANGED
|
@@ -22,7 +22,8 @@ __export(proxy_exports, {
|
|
|
22
22
|
formatProxyOptions: () => formatProxyOptions
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(proxy_exports);
|
|
25
|
-
var
|
|
25
|
+
var import_http_proxy_middleware = require("@rsbuild/shared/http-proxy-middleware");
|
|
26
|
+
var import_shared = require("@rsbuild/shared");
|
|
26
27
|
function formatProxyOptions(proxyOptions) {
|
|
27
28
|
var _a;
|
|
28
29
|
const ret = [];
|
|
@@ -45,45 +46,42 @@ function formatProxyOptions(proxyOptions) {
|
|
|
45
46
|
ret.push(opts);
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
|
-
const handleError = (err
|
|
49
|
-
console.error(err);
|
|
50
|
-
};
|
|
49
|
+
const handleError = (err) => import_shared.logger.error(err);
|
|
51
50
|
for (const opts of ret) {
|
|
52
51
|
(_a = opts.onError) != null ? _a : opts.onError = handleError;
|
|
53
52
|
}
|
|
54
53
|
return ret;
|
|
55
54
|
}
|
|
56
|
-
const createProxyMiddleware = (proxyOptions) => {
|
|
55
|
+
const createProxyMiddleware = (proxyOptions, app) => {
|
|
57
56
|
const formattedOptionsList = formatProxyOptions(proxyOptions);
|
|
58
|
-
const
|
|
57
|
+
const proxyMiddlewares = [];
|
|
59
58
|
const middlewares = [];
|
|
60
59
|
for (const opts of formattedOptionsList) {
|
|
61
|
-
const
|
|
60
|
+
const proxyMiddleware = (0, import_http_proxy_middleware.createProxyMiddleware)(opts.context, opts);
|
|
62
61
|
const middleware = async (req, res, next) => {
|
|
63
62
|
const bypassUrl = typeof opts.bypass === "function" ? opts.bypass(req, res, opts) : null;
|
|
64
|
-
if (
|
|
63
|
+
if (bypassUrl === false) {
|
|
65
64
|
res.statusCode = 404;
|
|
66
65
|
next();
|
|
67
66
|
} else if (typeof bypassUrl === "string") {
|
|
68
67
|
req.url = bypassUrl;
|
|
69
68
|
next();
|
|
70
69
|
} else {
|
|
71
|
-
|
|
70
|
+
proxyMiddleware(req, res, next);
|
|
72
71
|
}
|
|
73
72
|
};
|
|
74
|
-
proxies.push(proxy);
|
|
75
73
|
middlewares.push(middleware);
|
|
74
|
+
proxyMiddlewares.push(proxyMiddleware);
|
|
76
75
|
}
|
|
77
|
-
const handleUpgrade = (
|
|
78
|
-
for (const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
server.on("upgrade", raw.handleUpgrade);
|
|
82
|
-
raw.wsInternalSubscribed = true;
|
|
76
|
+
const handleUpgrade = (req, socket, head) => {
|
|
77
|
+
for (const middleware of proxyMiddlewares) {
|
|
78
|
+
if (typeof middleware.upgrade === "function") {
|
|
79
|
+
middleware.upgrade(req, socket, head);
|
|
83
80
|
}
|
|
84
81
|
}
|
|
85
82
|
};
|
|
86
|
-
|
|
83
|
+
app.on("upgrade", handleUpgrade);
|
|
84
|
+
return { middlewares };
|
|
87
85
|
};
|
|
88
86
|
// Annotate the CommonJS export names for ESM import in node:
|
|
89
87
|
0 && (module.exports = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.28",
|
|
4
4
|
"description": "Unleash the power of Rspack with the out-of-the-box build tool.",
|
|
5
5
|
"homepage": "https://rsbuild.dev",
|
|
6
6
|
"bugs": {
|
|
@@ -60,12 +60,11 @@
|
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@rspack/core": "0.3.14",
|
|
62
62
|
"core-js": "~3.32.2",
|
|
63
|
-
"html-webpack-plugin": "npm:html-rspack-plugin@5.5.
|
|
64
|
-
"http-proxy-middleware": "^2.0.1",
|
|
63
|
+
"html-webpack-plugin": "npm:html-rspack-plugin@5.5.7",
|
|
65
64
|
"postcss": "8.4.31",
|
|
66
65
|
"semver": "^7.5.4",
|
|
67
66
|
"ws": "^8.2.0",
|
|
68
|
-
"@rsbuild/shared": "0.0.
|
|
67
|
+
"@rsbuild/shared": "0.0.28"
|
|
69
68
|
},
|
|
70
69
|
"devDependencies": {
|
|
71
70
|
"@types/node": "^16",
|