@rsbuild/core 0.2.3 → 0.2.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/dist/cli/commands.js +2 -3
- package/dist/cli/config.d.ts +1 -7
- package/dist/cli/prepare.js +1 -1
- package/dist/createRsbuild.d.ts +2 -9
- package/dist/createRsbuild.js +5 -7
- package/dist/plugins/html.js +1 -1
- package/dist/provider/core/createContext.js +1 -1
- package/dist/provider/plugins/css.js +3 -2
- package/dist/provider/plugins/sass.js +1 -0
- package/dist/provider/plugins/swc.js +2 -2
- package/dist/provider/provider.d.ts +1 -6
- package/dist/provider/provider.js +79 -83
- package/dist/rspack/HtmlAppIconPlugin.js +4 -7
- package/dist/rspack/HtmlBasicPlugin.d.ts +0 -1
- package/dist/rspack/HtmlBasicPlugin.js +2 -3
- package/dist/server/compilerDevMiddleware.d.ts +5 -5
- package/dist/server/compilerDevMiddleware.js +4 -6
- package/dist/server/devServer.js +40 -18
- package/dist/server/getDevMiddlewares.d.ts +9 -1
- package/dist/server/getDevMiddlewares.js +19 -18
- package/dist/server/socketServer.d.ts +2 -2
- package/package.json +2 -2
package/dist/cli/commands.js
CHANGED
|
@@ -72,8 +72,7 @@ async function init({
|
|
|
72
72
|
}
|
|
73
73
|
return await createRsbuild({
|
|
74
74
|
cwd: root,
|
|
75
|
-
rsbuildConfig: config
|
|
76
|
-
provider: config.provider
|
|
75
|
+
rsbuildConfig: config
|
|
77
76
|
});
|
|
78
77
|
} catch (err) {
|
|
79
78
|
if (isRestart) {
|
|
@@ -84,7 +83,7 @@ async function init({
|
|
|
84
83
|
}
|
|
85
84
|
}
|
|
86
85
|
function runCli() {
|
|
87
|
-
import_commander.program.name("rsbuild").usage("<command> [options]").version("0.2.
|
|
86
|
+
import_commander.program.name("rsbuild").usage("<command> [options]").version("0.2.5");
|
|
88
87
|
import_commander.program.command("dev").option("--open", "open the page in browser on startup").option(
|
|
89
88
|
"--port <port>",
|
|
90
89
|
"specify a port number for Rsbuild Server to listen"
|
package/dist/cli/config.d.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import { type RsbuildConfig
|
|
2
|
-
export type RsbuildConfig = BaseRsbuildConfig & {
|
|
3
|
-
/**
|
|
4
|
-
* @private only for testing
|
|
5
|
-
*/
|
|
6
|
-
provider?: any;
|
|
7
|
-
};
|
|
1
|
+
import { type RsbuildConfig } from '@rsbuild/shared';
|
|
8
2
|
export type ConfigParams = {
|
|
9
3
|
env: string;
|
|
10
4
|
command: string;
|
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.2.
|
|
37
|
+
import_rslog.logger.greet(` ${`Rsbuild v${"0.2.5"}`}
|
|
38
38
|
`);
|
|
39
39
|
}
|
|
40
40
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/createRsbuild.d.ts
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
import { type RsbuildInstance, type
|
|
2
|
-
|
|
3
|
-
export declare function createRsbuild(options: CreateRsbuildOptions & {
|
|
4
|
-
provider?: ({
|
|
5
|
-
rsbuildConfig
|
|
6
|
-
}: {
|
|
7
|
-
rsbuildConfig: RsbuildConfig;
|
|
8
|
-
}) => RsbuildProvider;
|
|
9
|
-
}): Promise<RsbuildInstance>;
|
|
1
|
+
import { type RsbuildInstance, type CreateRsbuildOptions } from '@rsbuild/shared';
|
|
2
|
+
export declare function createRsbuild(options: CreateRsbuildOptions): Promise<RsbuildInstance>;
|
package/dist/createRsbuild.js
CHANGED
|
@@ -33,15 +33,13 @@ __export(createRsbuild_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(createRsbuild_exports);
|
|
34
34
|
var import_shared = require("@rsbuild/shared");
|
|
35
35
|
var import_plugins = require("./plugins");
|
|
36
|
-
const getRspackProvider = async (
|
|
36
|
+
const getRspackProvider = async () => {
|
|
37
37
|
const { rspackProvider } = await Promise.resolve().then(() => __toESM(require("./provider")));
|
|
38
|
-
return rspackProvider
|
|
39
|
-
rsbuildConfig
|
|
40
|
-
});
|
|
38
|
+
return rspackProvider;
|
|
41
39
|
};
|
|
42
40
|
async function createRsbuild(options) {
|
|
43
41
|
const { rsbuildConfig = {} } = options;
|
|
44
|
-
const provider =
|
|
42
|
+
const provider = rsbuildConfig.provider || await getRspackProvider();
|
|
45
43
|
const rsbuildOptions = {
|
|
46
44
|
cwd: process.cwd(),
|
|
47
45
|
rsbuildConfig,
|
|
@@ -60,9 +58,9 @@ async function createRsbuild(options) {
|
|
|
60
58
|
startDevServer,
|
|
61
59
|
applyDefaultPlugins
|
|
62
60
|
} = await provider({
|
|
61
|
+
plugins: import_plugins.plugins,
|
|
63
62
|
pluginStore,
|
|
64
|
-
rsbuildOptions
|
|
65
|
-
plugins: import_plugins.plugins
|
|
63
|
+
rsbuildOptions
|
|
66
64
|
});
|
|
67
65
|
(0, import_shared.debug)("add default plugins");
|
|
68
66
|
await applyDefaultPlugins(pluginStore);
|
package/dist/plugins/html.js
CHANGED
|
@@ -59,7 +59,7 @@ function createContextByConfig(options, bundlerType, config = {}) {
|
|
|
59
59
|
const context = {
|
|
60
60
|
entry: config.source?.entry || getDefaultEntry(rootPath),
|
|
61
61
|
targets: config.output?.targets || [],
|
|
62
|
-
version: "0.2.
|
|
62
|
+
version: "0.2.5",
|
|
63
63
|
rootPath,
|
|
64
64
|
distPath,
|
|
65
65
|
cachePath,
|
|
@@ -96,9 +96,10 @@ async function applyBaseCSSRule({
|
|
|
96
96
|
rule.type("css");
|
|
97
97
|
}
|
|
98
98
|
if (!isServer && !isWebWorker) {
|
|
99
|
-
const postcssLoaderOptions = (0, import_shared.
|
|
99
|
+
const postcssLoaderOptions = await (0, import_shared.getPostcssLoaderOptions)({
|
|
100
100
|
browserslist,
|
|
101
|
-
config
|
|
101
|
+
config,
|
|
102
|
+
root: context.rootPath
|
|
102
103
|
});
|
|
103
104
|
rule.use(CHAIN_ID.USE.POSTCSS).loader((0, import_shared.getSharedPkgCompiledPath)("postcss-loader")).options(postcssLoaderOptions).end();
|
|
104
105
|
}
|
|
@@ -45,6 +45,7 @@ function pluginSass() {
|
|
|
45
45
|
const { excludes, options } = (0, import_shared.getSassLoaderOptions)(
|
|
46
46
|
config.tools.sass,
|
|
47
47
|
// source-maps required for loaders preceding resolve-url-loader
|
|
48
|
+
// otherwise the resolve-url-loader will throw an error
|
|
48
49
|
true
|
|
49
50
|
);
|
|
50
51
|
const rule = chain.module.rule(utils.CHAIN_ID.RULE.SASS).test(import_shared.SASS_REGEX);
|
|
@@ -33,7 +33,7 @@ __export(swc_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(swc_exports);
|
|
35
35
|
var import_shared = require("@rsbuild/shared");
|
|
36
|
-
var
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
37
|
const builtinSwcLoaderName = "builtin:swc-loader";
|
|
38
38
|
async function getDefaultSwcConfig(config, rootPath, target) {
|
|
39
39
|
return {
|
|
@@ -106,7 +106,7 @@ const pluginSwc = () => ({
|
|
|
106
106
|
async function applyCoreJs(swcConfig, chain, polyfillMode) {
|
|
107
107
|
const coreJsPath = require.resolve("core-js/package.json");
|
|
108
108
|
const version = (0, import_shared.getCoreJsVersion)(coreJsPath);
|
|
109
|
-
const coreJsDir =
|
|
109
|
+
const coreJsDir = import_path.default.dirname(coreJsPath);
|
|
110
110
|
swcConfig.env.coreJs = version;
|
|
111
111
|
if (polyfillMode === "usage") {
|
|
112
112
|
swcConfig.env.shippedProposals = true;
|
|
@@ -1,7 +1,2 @@
|
|
|
1
1
|
import { type RsbuildProvider } from '@rsbuild/shared';
|
|
2
|
-
|
|
3
|
-
export declare function rspackProvider({
|
|
4
|
-
rsbuildConfig: originalRsbuildConfig
|
|
5
|
-
}: {
|
|
6
|
-
rsbuildConfig: RsbuildConfig;
|
|
7
|
-
}): RsbuildProvider;
|
|
2
|
+
export declare const rspackProvider: RsbuildProvider;
|
|
@@ -36,90 +36,86 @@ var import_createContext = require("./core/createContext");
|
|
|
36
36
|
var import_initConfigs = require("./core/initConfigs");
|
|
37
37
|
var import_initPlugins = require("./core/initPlugins");
|
|
38
38
|
var import_shared2 = require("./shared");
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
inspectOptions
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
};
|
|
39
|
+
const rspackProvider = async ({
|
|
40
|
+
pluginStore,
|
|
41
|
+
rsbuildOptions,
|
|
42
|
+
plugins
|
|
43
|
+
}) => {
|
|
44
|
+
const rsbuildConfig = (0, import_shared.pickRsbuildConfig)(rsbuildOptions.rsbuildConfig);
|
|
45
|
+
const context = await (0, import_createContext.createContext)(rsbuildOptions, rsbuildConfig, "rspack");
|
|
46
|
+
const pluginAPI = (0, import_initPlugins.getPluginAPI)({ context, pluginStore });
|
|
47
|
+
context.pluginAPI = pluginAPI;
|
|
48
|
+
return {
|
|
49
|
+
bundler: "rspack",
|
|
50
|
+
pluginAPI,
|
|
51
|
+
publicContext: (0, import_createContext.createPublicContext)(context),
|
|
52
|
+
async applyDefaultPlugins() {
|
|
53
|
+
pluginStore.addPlugins(await (0, import_shared2.applyDefaultPlugins)(plugins));
|
|
54
|
+
},
|
|
55
|
+
async createCompiler() {
|
|
56
|
+
const { createCompiler } = await Promise.resolve().then(() => __toESM(require("./core/createCompiler")));
|
|
57
|
+
const { rspackConfigs } = await (0, import_initConfigs.initConfigs)({
|
|
58
|
+
context,
|
|
59
|
+
pluginStore,
|
|
60
|
+
rsbuildOptions
|
|
61
|
+
});
|
|
62
|
+
return createCompiler({
|
|
63
|
+
context,
|
|
64
|
+
rspackConfigs
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
async getServerAPIs(options) {
|
|
68
|
+
const { getServerAPIs } = await Promise.resolve().then(() => __toESM(require("../server/devServer")));
|
|
69
|
+
const { createDevMiddleware } = await Promise.resolve().then(() => __toESM(require("./core/createCompiler")));
|
|
70
|
+
await (0, import_initConfigs.initRsbuildConfig)({ context, pluginStore });
|
|
71
|
+
return getServerAPIs(
|
|
72
|
+
{ context, pluginStore, rsbuildOptions },
|
|
73
|
+
createDevMiddleware,
|
|
74
|
+
options
|
|
75
|
+
);
|
|
76
|
+
},
|
|
77
|
+
async startDevServer(options) {
|
|
78
|
+
const { startDevServer } = await Promise.resolve().then(() => __toESM(require("../server/devServer")));
|
|
79
|
+
const { createDevMiddleware } = await Promise.resolve().then(() => __toESM(require("./core/createCompiler")));
|
|
80
|
+
await (0, import_initConfigs.initRsbuildConfig)({ context, pluginStore });
|
|
81
|
+
return startDevServer(
|
|
82
|
+
{ context, pluginStore, rsbuildOptions },
|
|
83
|
+
createDevMiddleware,
|
|
84
|
+
options
|
|
85
|
+
);
|
|
86
|
+
},
|
|
87
|
+
async preview(options) {
|
|
88
|
+
const { startProdServer } = await Promise.resolve().then(() => __toESM(require("../server/prodServer")));
|
|
89
|
+
await (0, import_initConfigs.initRsbuildConfig)({ context, pluginStore });
|
|
90
|
+
return startProdServer(context, context.config, options);
|
|
91
|
+
},
|
|
92
|
+
async build(options) {
|
|
93
|
+
const { build: buildImpl, rspackBuild } = await Promise.resolve().then(() => __toESM(require("./core/build")));
|
|
94
|
+
return buildImpl(
|
|
95
|
+
{ context, pluginStore, rsbuildOptions },
|
|
96
|
+
options,
|
|
97
|
+
rspackBuild
|
|
98
|
+
);
|
|
99
|
+
},
|
|
100
|
+
async initConfigs() {
|
|
101
|
+
const { rspackConfigs } = await (0, import_initConfigs.initConfigs)({
|
|
102
|
+
context,
|
|
103
|
+
pluginStore,
|
|
104
|
+
rsbuildOptions
|
|
105
|
+
});
|
|
106
|
+
return rspackConfigs;
|
|
107
|
+
},
|
|
108
|
+
async inspectConfig(inspectOptions) {
|
|
109
|
+
const { inspectConfig } = await Promise.resolve().then(() => __toESM(require("./core/inspectConfig")));
|
|
110
|
+
return inspectConfig({
|
|
111
|
+
context,
|
|
112
|
+
pluginStore,
|
|
113
|
+
rsbuildOptions,
|
|
114
|
+
inspectOptions
|
|
115
|
+
});
|
|
116
|
+
}
|
|
121
117
|
};
|
|
122
|
-
}
|
|
118
|
+
};
|
|
123
119
|
// Annotate the CommonJS export names for ESM import in node:
|
|
124
120
|
0 && (module.exports = {
|
|
125
121
|
rspackProvider
|
|
@@ -32,7 +32,7 @@ __export(HtmlAppIconPlugin_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(HtmlAppIconPlugin_exports);
|
|
34
34
|
var import_fs = __toESM(require("fs"));
|
|
35
|
-
var import_path =
|
|
35
|
+
var import_path = require("path");
|
|
36
36
|
var import_html_webpack_plugin = __toESM(require("html-webpack-plugin"));
|
|
37
37
|
var import_webpack_sources = __toESM(require("@rsbuild/shared/webpack-sources"));
|
|
38
38
|
var import_shared = require("@rsbuild/shared");
|
|
@@ -48,22 +48,19 @@ class HtmlAppIconPlugin {
|
|
|
48
48
|
`[${this.name}] Can not find the app icon, please check if the '${this.iconPath}' file exists'.`
|
|
49
49
|
);
|
|
50
50
|
}
|
|
51
|
-
const iconRelativePath = import_path.
|
|
52
|
-
this.distDir,
|
|
53
|
-
import_path.default.basename(this.iconPath)
|
|
54
|
-
);
|
|
51
|
+
const iconRelativePath = import_path.posix.join(this.distDir, (0, import_path.basename)(this.iconPath));
|
|
55
52
|
compiler.hooks.compilation.tap(this.name, (compilation) => {
|
|
56
53
|
import_html_webpack_plugin.default.getHooks(compilation).alterAssetTagGroups.tap(
|
|
57
54
|
this.name,
|
|
58
55
|
(data) => {
|
|
59
|
-
const
|
|
56
|
+
const publicPath = (0, import_shared.getPublicPathFromCompiler)(compiler);
|
|
60
57
|
data.headTags.unshift({
|
|
61
58
|
tagName: "link",
|
|
62
59
|
voidTag: true,
|
|
63
60
|
attributes: {
|
|
64
61
|
rel: "apple-touch-icon",
|
|
65
62
|
sizes: "180*180",
|
|
66
|
-
href:
|
|
63
|
+
href: (0, import_shared.withPublicPath)(iconRelativePath, publicPath)
|
|
67
64
|
},
|
|
68
65
|
meta: {}
|
|
69
66
|
});
|
|
@@ -40,8 +40,7 @@ class HtmlBasicPlugin {
|
|
|
40
40
|
this.options = options;
|
|
41
41
|
}
|
|
42
42
|
apply(compiler) {
|
|
43
|
-
const addTitleTag = (headTags,
|
|
44
|
-
const { title } = this.options.info[entryName];
|
|
43
|
+
const addTitleTag = (headTags, title) => {
|
|
45
44
|
if (title) {
|
|
46
45
|
headTags.unshift({
|
|
47
46
|
tagName: "title",
|
|
@@ -77,7 +76,7 @@ class HtmlBasicPlugin {
|
|
|
77
76
|
const { headTags } = data;
|
|
78
77
|
const { templateContent } = this.options.info[entryName];
|
|
79
78
|
if (!hasTitle(templateContent)) {
|
|
80
|
-
addTitleTag(headTags,
|
|
79
|
+
addTitleTag(headTags, data.plugin.options?.title);
|
|
81
80
|
}
|
|
82
81
|
addFavicon(headTags, entryName);
|
|
83
82
|
return data;
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import type { IncomingMessage } from 'http';
|
|
4
4
|
import type { Socket } from 'net';
|
|
5
|
-
import type {
|
|
5
|
+
import type { DevMiddlewaresConfig, DevMiddlewareAPI, DevMiddleware as CustomDevMiddleware } from '@rsbuild/shared';
|
|
6
6
|
type Options = {
|
|
7
7
|
publicPaths: string[];
|
|
8
|
-
dev:
|
|
9
|
-
devMiddleware
|
|
8
|
+
dev: DevMiddlewaresConfig;
|
|
9
|
+
devMiddleware: CustomDevMiddleware;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
12
|
* Setup compiler-related logic:
|
|
@@ -14,9 +14,9 @@ type Options = {
|
|
|
14
14
|
* 2. establish webSocket connect
|
|
15
15
|
*/
|
|
16
16
|
export declare class CompilerDevMiddleware {
|
|
17
|
-
middleware
|
|
17
|
+
middleware: DevMiddlewareAPI;
|
|
18
18
|
private devOptions;
|
|
19
|
-
private devMiddleware
|
|
19
|
+
private devMiddleware;
|
|
20
20
|
private publicPaths;
|
|
21
21
|
private socketServer;
|
|
22
22
|
constructor({
|
|
@@ -50,12 +50,10 @@ class CompilerDevMiddleware {
|
|
|
50
50
|
this.devMiddleware = devMiddleware;
|
|
51
51
|
}
|
|
52
52
|
init() {
|
|
53
|
-
|
|
54
|
-
this.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
);
|
|
58
|
-
}
|
|
53
|
+
this.middleware = this.setupDevMiddleware(
|
|
54
|
+
this.devMiddleware,
|
|
55
|
+
this.publicPaths
|
|
56
|
+
);
|
|
59
57
|
this.socketServer.prepare();
|
|
60
58
|
}
|
|
61
59
|
upgrade(req, sock, head) {
|
package/dist/server/devServer.js
CHANGED
|
@@ -60,11 +60,6 @@ async function getServerAPIs(options, createDevMiddleware, {
|
|
|
60
60
|
port,
|
|
61
61
|
https
|
|
62
62
|
};
|
|
63
|
-
const { devMiddleware, compiler } = await createDevMiddleware(
|
|
64
|
-
options,
|
|
65
|
-
customCompiler
|
|
66
|
-
);
|
|
67
|
-
const publicPaths = compiler.compilers ? compiler.compilers.map(import_shared.getPublicPathFromCompiler) : [(0, import_shared.getPublicPathFromCompiler)(compiler)];
|
|
68
63
|
return {
|
|
69
64
|
config: { devServerConfig, port, host, https, defaultRoutes },
|
|
70
65
|
beforeStart: async () => {
|
|
@@ -76,18 +71,42 @@ async function getServerAPIs(options, createDevMiddleware, {
|
|
|
76
71
|
routes: params.routes || defaultRoutes
|
|
77
72
|
});
|
|
78
73
|
},
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
74
|
+
startCompile: async () => {
|
|
75
|
+
const { devMiddleware, compiler } = await createDevMiddleware(
|
|
76
|
+
options,
|
|
77
|
+
customCompiler
|
|
78
|
+
);
|
|
79
|
+
const { CompilerDevMiddleware } = await Promise.resolve().then(() => __toESM(require("./compilerDevMiddleware")));
|
|
80
|
+
const publicPaths = compiler.compilers ? compiler.compilers.map(
|
|
81
|
+
import_shared.getPublicPathFromCompiler
|
|
82
|
+
) : [(0, import_shared.getPublicPathFromCompiler)(compiler)];
|
|
83
|
+
const compilerDevMiddleware = new CompilerDevMiddleware({
|
|
84
|
+
dev: devServerConfig,
|
|
85
|
+
publicPaths,
|
|
86
|
+
devMiddleware
|
|
87
|
+
});
|
|
88
|
+
compilerDevMiddleware.init();
|
|
89
|
+
return {
|
|
90
|
+
middleware: compilerDevMiddleware.middleware,
|
|
91
|
+
sockWrite: (...args) => compilerDevMiddleware.sockWrite(...args),
|
|
92
|
+
onUpgrade: (...args) => compilerDevMiddleware.upgrade(...args),
|
|
93
|
+
close: () => compilerDevMiddleware?.close()
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
getMiddlewares: async (params = {}) => {
|
|
97
|
+
const { compileMiddlewareAPI, overrides = {} } = params;
|
|
98
|
+
return (0, import_getDevMiddlewares.getMiddlewares)({
|
|
99
|
+
pwd: options.context.rootPath,
|
|
100
|
+
compileMiddlewareAPI,
|
|
101
|
+
dev: {
|
|
102
|
+
...devServerConfig,
|
|
103
|
+
...overrides
|
|
104
|
+
},
|
|
105
|
+
output: {
|
|
106
|
+
distPath: rsbuildConfig.output?.distPath?.root || import_shared.ROOT_DIST_DIR
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
91
110
|
};
|
|
92
111
|
}
|
|
93
112
|
async function startDevServer(options, createDevMiddleware, {
|
|
@@ -125,7 +144,10 @@ async function startDevServer(options, createDevMiddleware, {
|
|
|
125
144
|
}
|
|
126
145
|
(0, import_shared.printServerURLs)(urls, defaultRoutes, logger);
|
|
127
146
|
}
|
|
128
|
-
const
|
|
147
|
+
const compileMiddlewareAPI = await serverAPIs.startCompile();
|
|
148
|
+
const devMiddlewares = await serverAPIs.getMiddlewares({
|
|
149
|
+
compileMiddlewareAPI
|
|
150
|
+
});
|
|
129
151
|
devMiddlewares.middlewares.forEach((m) => middlewares.use(m));
|
|
130
152
|
middlewares.use(import_middlewares.notFoundMiddleware);
|
|
131
153
|
(0, import_shared.debug)("listen dev server");
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import type { UpgradeEvent, RequestHandler,
|
|
1
|
+
import type { UpgradeEvent, RequestHandler, DevMiddlewaresConfig, CompileMiddlewareAPI } from '@rsbuild/shared';
|
|
2
|
+
export type RsbuildDevMiddlewareOptions = {
|
|
3
|
+
pwd: string;
|
|
4
|
+
dev: DevMiddlewaresConfig;
|
|
5
|
+
compileMiddlewareAPI?: CompileMiddlewareAPI;
|
|
6
|
+
output: {
|
|
7
|
+
distPath: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
2
10
|
export declare const getMiddlewares: (options: RsbuildDevMiddlewareOptions) => Promise<{
|
|
3
11
|
close: () => Promise<void>;
|
|
4
12
|
onUpgrade: UpgradeEvent;
|
|
@@ -32,13 +32,12 @@ __export(getDevMiddlewares_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(getDevMiddlewares_exports);
|
|
34
34
|
var import_url = __toESM(require("url"));
|
|
35
|
-
var import_compilerDevMiddleware = require("./compilerDevMiddleware");
|
|
36
35
|
var import_middlewares = require("./middlewares");
|
|
37
36
|
var import_path = require("path");
|
|
38
|
-
const applySetupMiddlewares = (dev,
|
|
37
|
+
const applySetupMiddlewares = (dev, compileMiddlewareAPI) => {
|
|
39
38
|
const setupMiddlewares = dev.setupMiddlewares || [];
|
|
40
39
|
const serverOptions = {
|
|
41
|
-
sockWrite: (type, data) =>
|
|
40
|
+
sockWrite: (type, data) => compileMiddlewareAPI?.sockWrite(type, data)
|
|
42
41
|
};
|
|
43
42
|
const before = [];
|
|
44
43
|
const after = [];
|
|
@@ -56,7 +55,7 @@ const applySetupMiddlewares = (dev, devMiddleware) => {
|
|
|
56
55
|
const applyDefaultMiddlewares = async ({
|
|
57
56
|
middlewares,
|
|
58
57
|
dev,
|
|
59
|
-
|
|
58
|
+
compileMiddlewareAPI,
|
|
60
59
|
output,
|
|
61
60
|
pwd
|
|
62
61
|
}) => {
|
|
@@ -94,9 +93,12 @@ const applyDefaultMiddlewares = async ({
|
|
|
94
93
|
middlewares.push(middleware);
|
|
95
94
|
});
|
|
96
95
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
if (compileMiddlewareAPI) {
|
|
97
|
+
middlewares.push(compileMiddlewareAPI.middleware);
|
|
98
|
+
upgradeEvents.push(
|
|
99
|
+
compileMiddlewareAPI.onUpgrade.bind(compileMiddlewareAPI)
|
|
100
|
+
);
|
|
101
|
+
}
|
|
100
102
|
if (dev.publicDir && dev.publicDir.name) {
|
|
101
103
|
const { default: sirv } = await Promise.resolve().then(() => __toESM(require("../../compiled/sirv")));
|
|
102
104
|
const { name } = dev.publicDir;
|
|
@@ -108,10 +110,10 @@ const applyDefaultMiddlewares = async ({
|
|
|
108
110
|
middlewares.push(assetMiddleware);
|
|
109
111
|
}
|
|
110
112
|
const { distPath } = output;
|
|
111
|
-
middlewares.push(
|
|
113
|
+
compileMiddlewareAPI && middlewares.push(
|
|
112
114
|
(0, import_middlewares.getHtmlFallbackMiddleware)({
|
|
113
115
|
distPath: (0, import_path.isAbsolute)(distPath) ? distPath : (0, import_path.join)(pwd, distPath),
|
|
114
|
-
callback:
|
|
116
|
+
callback: compileMiddlewareAPI.middleware,
|
|
115
117
|
htmlFallback: dev.htmlFallback
|
|
116
118
|
})
|
|
117
119
|
);
|
|
@@ -121,7 +123,7 @@ const applyDefaultMiddlewares = async ({
|
|
|
121
123
|
dev.historyApiFallback === true ? {} : dev.historyApiFallback
|
|
122
124
|
);
|
|
123
125
|
middlewares.push(historyApiFallbackMiddleware);
|
|
124
|
-
|
|
126
|
+
compileMiddlewareAPI?.middleware && middlewares.push(compileMiddlewareAPI.middleware);
|
|
125
127
|
}
|
|
126
128
|
middlewares.push(import_middlewares.faviconFallbackMiddleware);
|
|
127
129
|
return {
|
|
@@ -132,24 +134,23 @@ const applyDefaultMiddlewares = async ({
|
|
|
132
134
|
};
|
|
133
135
|
const getMiddlewares = async (options) => {
|
|
134
136
|
const middlewares = [];
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const { before, after } = applySetupMiddlewares(options.dev, devMiddleware);
|
|
137
|
+
const { compileMiddlewareAPI } = options;
|
|
138
|
+
const { before, after } = applySetupMiddlewares(
|
|
139
|
+
options.dev,
|
|
140
|
+
compileMiddlewareAPI
|
|
141
|
+
);
|
|
141
142
|
before.forEach((fn) => middlewares.push(fn));
|
|
142
143
|
const { onUpgrade } = await applyDefaultMiddlewares({
|
|
143
144
|
middlewares,
|
|
144
145
|
dev: options.dev,
|
|
145
|
-
|
|
146
|
+
compileMiddlewareAPI,
|
|
146
147
|
output: options.output,
|
|
147
148
|
pwd: options.pwd
|
|
148
149
|
});
|
|
149
150
|
after.forEach((fn) => middlewares.push(fn));
|
|
150
151
|
return {
|
|
151
152
|
close: async () => {
|
|
152
|
-
|
|
153
|
+
compileMiddlewareAPI?.close();
|
|
153
154
|
},
|
|
154
155
|
onUpgrade,
|
|
155
156
|
middlewares
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
import type { IncomingMessage } from 'http';
|
|
4
4
|
import type { Socket } from 'net';
|
|
5
5
|
import ws from '../../compiled/ws';
|
|
6
|
-
import { type Stats, type
|
|
6
|
+
import { type Stats, type DevMiddlewaresConfig } from '@rsbuild/shared';
|
|
7
7
|
export declare class SocketServer {
|
|
8
8
|
private wsServer;
|
|
9
9
|
private readonly sockets;
|
|
10
10
|
private readonly options;
|
|
11
11
|
private stats?;
|
|
12
12
|
private timer;
|
|
13
|
-
constructor(options:
|
|
13
|
+
constructor(options: DevMiddlewaresConfig);
|
|
14
14
|
upgrade(req: IncomingMessage, sock: Socket, head: any): void;
|
|
15
15
|
prepare(): void;
|
|
16
16
|
updateStats(stats: Stats): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
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,7 +60,7 @@
|
|
|
60
60
|
"core-js": "~3.32.2",
|
|
61
61
|
"html-webpack-plugin": "npm:html-rspack-plugin@5.5.7",
|
|
62
62
|
"postcss": "8.4.31",
|
|
63
|
-
"@rsbuild/shared": "0.2.
|
|
63
|
+
"@rsbuild/shared": "0.2.5"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@types/node": "16.x",
|