@rsbuild/core 0.0.16 → 0.0.18
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.d.ts +3 -0
- package/dist/cli/commands.js +4 -2
- package/dist/cli/config.d.ts +4 -0
- package/dist/cli/index.js +2 -1
- package/dist/plugins/define.js +15 -27
- package/dist/plugins/html.d.ts +7 -1
- package/dist/plugins/html.js +72 -48
- package/dist/plugins/index.js +0 -1
- package/dist/plugins/nodeAddons.js +10 -17
- package/dist/plugins/startUrl.js +12 -16
- package/dist/rspack-plugins/HtmlBasicPlugin.d.ts +19 -0
- package/dist/rspack-plugins/HtmlBasicPlugin.js +87 -0
- package/dist/rspack-provider/core/createCompiler.js +7 -5
- package/dist/rspack-provider/core/devMiddleware.d.ts +2 -4
- package/dist/rspack-provider/core/startDevServer.d.ts +1 -2
- package/dist/rspack-provider/core/startDevServer.js +6 -31
- package/dist/rspack-provider/plugins/css.js +2 -2
- package/dist/rspack-provider/plugins/less.js +1 -1
- package/dist/rspack-provider/plugins/progress.js +5 -1
- package/dist/rspack-provider/plugins/resolve.js +1 -2
- package/dist/rspack-provider/plugins/sass.js +2 -2
- package/dist/rspack-provider/plugins/swc.js +5 -8
- package/dist/rspack-provider/provider.js +5 -3
- package/dist/rspack-provider/shared/plugin.js +0 -1
- package/dist/server/constants.d.ts +6 -0
- package/dist/server/constants.js +49 -0
- package/dist/server/dev-middleware/hmr-client/createSocketUrl.d.ts +16 -0
- package/dist/server/dev-middleware/hmr-client/createSocketUrl.js +68 -0
- package/dist/server/dev-middleware/hmr-client/index.d.ts +1 -0
- package/dist/server/dev-middleware/hmr-client/index.js +164 -0
- package/dist/server/dev-middleware/index.d.ts +22 -0
- package/dist/server/dev-middleware/index.js +90 -0
- package/dist/server/dev-middleware/socketServer.d.ts +22 -0
- package/dist/server/dev-middleware/socketServer.js +167 -0
- package/dist/server/devServer.d.ts +23 -0
- package/dist/server/devServer.js +172 -0
- package/dist/server/https.d.ts +6 -0
- package/dist/server/https.js +50 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +31 -0
- package/dist/server/prodServer.d.ts +26 -0
- package/dist/server/prodServer.js +133 -0
- package/package.json +32 -6
- package/static/template.html +7 -0
- package/types.d.ts +130 -0
- package/dist/plugins/assetsRetry.d.ts +0 -2
- package/dist/plugins/assetsRetry.js +0 -66
- package/dist/utils/generateMetaTags.d.ts +0 -0
- package/dist/utils/generateMetaTags.js +0 -1
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,27 +15,18 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var startDevServer_exports = {};
|
|
30
20
|
__export(startDevServer_exports, {
|
|
31
|
-
createDevServer: () => createDevServer
|
|
32
|
-
startDevServer: () => startDevServer
|
|
21
|
+
createDevServer: () => createDevServer
|
|
33
22
|
});
|
|
34
23
|
module.exports = __toCommonJS(startDevServer_exports);
|
|
35
24
|
var import_shared = require("@rsbuild/shared");
|
|
36
25
|
var import_createCompiler = require("./createCompiler");
|
|
37
26
|
var import_devMiddleware = require("./devMiddleware");
|
|
38
27
|
var import_initConfigs = require("./initConfigs");
|
|
28
|
+
var import_server = require("../../server");
|
|
39
29
|
async function createDevServer(options, port, serverOptions, customCompiler) {
|
|
40
|
-
const { Server } = await Promise.resolve().then(() => __toESM(require("@modern-js/server")));
|
|
41
30
|
let compiler;
|
|
42
31
|
if (customCompiler) {
|
|
43
32
|
compiler = customCompiler;
|
|
@@ -50,35 +39,21 @@ async function createDevServer(options, port, serverOptions, customCompiler) {
|
|
|
50
39
|
}
|
|
51
40
|
(0, import_shared.debug)("create dev server");
|
|
52
41
|
const rsbuildConfig = options.context.config;
|
|
53
|
-
const {
|
|
42
|
+
const { devConfig } = await (0, import_shared.getDevServerOptions)({
|
|
54
43
|
rsbuildConfig,
|
|
55
44
|
serverOptions,
|
|
56
45
|
port
|
|
57
46
|
});
|
|
58
|
-
const server =
|
|
47
|
+
const server = await (0, import_server.createDevServer)({
|
|
59
48
|
pwd: options.context.rootPath,
|
|
60
49
|
devMiddleware: (0, import_devMiddleware.getDevMiddleware)(compiler),
|
|
61
50
|
...serverOptions,
|
|
62
|
-
dev: devConfig
|
|
63
|
-
config
|
|
51
|
+
dev: devConfig
|
|
64
52
|
});
|
|
65
53
|
(0, import_shared.debug)("create dev server done");
|
|
66
54
|
return server;
|
|
67
55
|
}
|
|
68
|
-
async function startDevServer(options, startDevServerOptions = {}) {
|
|
69
|
-
return (0, import_shared.startDevServer)(
|
|
70
|
-
options,
|
|
71
|
-
(options2, port, serverOptions, compiler) => createDevServer(
|
|
72
|
-
options2,
|
|
73
|
-
port,
|
|
74
|
-
serverOptions,
|
|
75
|
-
compiler
|
|
76
|
-
),
|
|
77
|
-
startDevServerOptions
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
56
|
// Annotate the CommonJS export names for ESM import in node:
|
|
81
57
|
0 && (module.exports = {
|
|
82
|
-
createDevServer
|
|
83
|
-
startDevServer
|
|
58
|
+
createDevServer
|
|
84
59
|
});
|
|
@@ -56,7 +56,7 @@ async function applyBaseCSSRule({
|
|
|
56
56
|
const enableCssMinify = !enableExtractCSS && isProd;
|
|
57
57
|
if (!enableNativeCss(config)) {
|
|
58
58
|
const localIdentName = (0, import_shared.getCssModuleLocalIdentName)(config, isProd);
|
|
59
|
-
const cssLoaderOptions =
|
|
59
|
+
const cssLoaderOptions = (0, import_shared.getCssLoaderOptions)({
|
|
60
60
|
config,
|
|
61
61
|
enableSourceMap,
|
|
62
62
|
importLoaders,
|
|
@@ -110,7 +110,7 @@ async function applyBaseCSSRule({
|
|
|
110
110
|
rule.type("css");
|
|
111
111
|
}
|
|
112
112
|
if (!isServer && !isWebWorker) {
|
|
113
|
-
const postcssLoaderOptions =
|
|
113
|
+
const postcssLoaderOptions = (0, import_shared.getPostcssConfig)({
|
|
114
114
|
enableSourceMap,
|
|
115
115
|
browserslist,
|
|
116
116
|
config,
|
|
@@ -47,7 +47,7 @@ function pluginLess() {
|
|
|
47
47
|
context: api.context,
|
|
48
48
|
importLoaders: 2
|
|
49
49
|
});
|
|
50
|
-
const { excludes, options } =
|
|
50
|
+
const { excludes, options } = (0, import_shared.getLessLoaderOptions)(
|
|
51
51
|
config.tools.less,
|
|
52
52
|
(0, import_shared.isUseCssSourceMap)(config)
|
|
53
53
|
);
|
|
@@ -36,8 +36,12 @@ const pluginProgress = () => ({
|
|
|
36
36
|
name: "plugin-progress",
|
|
37
37
|
setup(api) {
|
|
38
38
|
api.modifyBundlerChain(async (chain, { target, CHAIN_ID }) => {
|
|
39
|
+
var _a;
|
|
39
40
|
const config = api.getNormalizedConfig();
|
|
40
|
-
const options = config.dev.progressBar
|
|
41
|
+
const options = (_a = config.dev.progressBar) != null ? _a : (
|
|
42
|
+
// enable progress bar in production by default
|
|
43
|
+
(0, import_shared.isProd)()
|
|
44
|
+
);
|
|
41
45
|
if (!options) {
|
|
42
46
|
return;
|
|
43
47
|
}
|
|
@@ -27,8 +27,7 @@ const pluginResolve = () => ({
|
|
|
27
27
|
setup(api) {
|
|
28
28
|
(0, import_shared.applyResolvePlugin)(api);
|
|
29
29
|
api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
|
|
30
|
-
|
|
31
|
-
if (chain.module.rules.get(CHAIN_ID.RULE.JS_DATA_URI) && config.source.compileJsDataURI) {
|
|
30
|
+
if (chain.module.rules.get(CHAIN_ID.RULE.JS_DATA_URI)) {
|
|
32
31
|
chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).resolve.set("fullySpecified", false);
|
|
33
32
|
}
|
|
34
33
|
});
|
|
@@ -35,14 +35,14 @@ var import_shared = require("@rsbuild/shared");
|
|
|
35
35
|
function pluginSass() {
|
|
36
36
|
return {
|
|
37
37
|
name: "plugin-sass",
|
|
38
|
-
|
|
38
|
+
setup(api) {
|
|
39
39
|
api.onAfterCreateCompiler(({ compiler }) => {
|
|
40
40
|
(0, import_shared.patchCompilerGlobalLocation)(compiler);
|
|
41
41
|
});
|
|
42
42
|
api.modifyBundlerChain(async (chain, utils) => {
|
|
43
43
|
const config = api.getNormalizedConfig();
|
|
44
44
|
const { applyBaseCSSRule } = await Promise.resolve().then(() => __toESM(require("./css")));
|
|
45
|
-
const { excludes, options } =
|
|
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
48
|
true
|
|
@@ -44,11 +44,10 @@ async function getDefaultSwcConfig(config, rootPath, target) {
|
|
|
44
44
|
tsx: true,
|
|
45
45
|
syntax: "typescript",
|
|
46
46
|
decorators: true
|
|
47
|
-
}
|
|
48
|
-
// TODO: Enabling it will cause performance degradation
|
|
47
|
+
},
|
|
49
48
|
// Avoid the webpack magic comment to be removed
|
|
50
49
|
// https://github.com/swc-project/swc/issues/6403
|
|
51
|
-
|
|
50
|
+
preserveAllComments: true
|
|
52
51
|
},
|
|
53
52
|
isModule: "unknown",
|
|
54
53
|
minify: false,
|
|
@@ -98,11 +97,9 @@ const pluginSwc = () => ({
|
|
|
98
97
|
}
|
|
99
98
|
}
|
|
100
99
|
rule.use(CHAIN_ID.USE.SWC).loader(builtinSwcLoaderName).options(swcConfig);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}).use(CHAIN_ID.USE.SWC).loader(builtinSwcLoaderName).options((0, import_lodash.cloneDeep)(swcConfig));
|
|
105
|
-
}
|
|
100
|
+
chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).mimetype({
|
|
101
|
+
or: ["text/javascript", "application/javascript"]
|
|
102
|
+
}).use(CHAIN_ID.USE.SWC).loader(builtinSwcLoaderName).options((0, import_lodash.cloneDeep)(swcConfig));
|
|
106
103
|
}
|
|
107
104
|
);
|
|
108
105
|
api.modifyRspackConfig(async (config) => {
|
|
@@ -37,6 +37,7 @@ var import_initConfigs = require("./core/initConfigs");
|
|
|
37
37
|
var import_initPlugins = require("./core/initPlugins");
|
|
38
38
|
var import_plugin = require("./shared/plugin");
|
|
39
39
|
var import_rspackVersion = require("./shared/rspackVersion");
|
|
40
|
+
var import_server = require("../server");
|
|
40
41
|
function rspackProvider({
|
|
41
42
|
rsbuildConfig: originalRsbuildConfig
|
|
42
43
|
}) {
|
|
@@ -72,14 +73,15 @@ function rspackProvider({
|
|
|
72
73
|
});
|
|
73
74
|
},
|
|
74
75
|
async startDevServer(options) {
|
|
75
|
-
const {
|
|
76
|
-
return startDevServer(
|
|
76
|
+
const { createDevServer } = await Promise.resolve().then(() => __toESM(require("./core/startDevServer")));
|
|
77
|
+
return (0, import_shared.startDevServer)(
|
|
77
78
|
{ context, pluginStore, rsbuildOptions },
|
|
79
|
+
createDevServer,
|
|
78
80
|
options
|
|
79
81
|
);
|
|
80
82
|
},
|
|
81
83
|
async preview() {
|
|
82
|
-
return (0,
|
|
84
|
+
return (0, import_server.startProdServer)(context, context.config);
|
|
83
85
|
},
|
|
84
86
|
async build(options) {
|
|
85
87
|
const { build: buildImpl, rspackBuild } = await Promise.resolve().then(() => __toESM(require("./core/build")));
|
|
@@ -68,7 +68,6 @@ const applyDefaultPlugins = (plugins) => (0, import_shared.awaitableGetter)([
|
|
|
68
68
|
plugins.startUrl(),
|
|
69
69
|
plugins.inlineChunk(),
|
|
70
70
|
plugins.bundleAnalyzer(),
|
|
71
|
-
plugins.assetsRetry(),
|
|
72
71
|
plugins.networkPerformance(),
|
|
73
72
|
plugins.preloadOrPrefetch(),
|
|
74
73
|
plugins.performance(),
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var constants_exports = {};
|
|
20
|
+
__export(constants_exports, {
|
|
21
|
+
HMR_SOCK_PATH: () => HMR_SOCK_PATH,
|
|
22
|
+
getDefaultDevOptions: () => getDefaultDevOptions
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(constants_exports);
|
|
25
|
+
const HMR_SOCK_PATH = "/webpack-hmr";
|
|
26
|
+
const getDefaultDevOptions = () => {
|
|
27
|
+
return {
|
|
28
|
+
client: {
|
|
29
|
+
path: HMR_SOCK_PATH,
|
|
30
|
+
// By default it is set to the port number of the dev server
|
|
31
|
+
port: "",
|
|
32
|
+
// By default it is set to "location.hostname"
|
|
33
|
+
host: "",
|
|
34
|
+
// By default it is set to "location.protocol === 'https:' ? 'wss' : 'ws'""
|
|
35
|
+
protocol: ""
|
|
36
|
+
},
|
|
37
|
+
https: false,
|
|
38
|
+
devMiddleware: { writeToDisk: true },
|
|
39
|
+
watch: true,
|
|
40
|
+
hot: true,
|
|
41
|
+
compress: true,
|
|
42
|
+
liveReload: true
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
HMR_SOCK_PATH,
|
|
48
|
+
getDefaultDevOptions
|
|
49
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hmr socket connect path
|
|
3
|
+
*/
|
|
4
|
+
export declare const HMR_SOCK_PATH = "/webpack-hmr";
|
|
5
|
+
export declare function createSocketUrl(resourceQuery: string): string;
|
|
6
|
+
export declare function formatURL({
|
|
7
|
+
port,
|
|
8
|
+
protocol,
|
|
9
|
+
hostname,
|
|
10
|
+
pathname
|
|
11
|
+
}: {
|
|
12
|
+
port: string;
|
|
13
|
+
protocol: string;
|
|
14
|
+
hostname: string;
|
|
15
|
+
pathname: string;
|
|
16
|
+
}): string;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var createSocketUrl_exports = {};
|
|
20
|
+
__export(createSocketUrl_exports, {
|
|
21
|
+
HMR_SOCK_PATH: () => HMR_SOCK_PATH,
|
|
22
|
+
createSocketUrl: () => createSocketUrl,
|
|
23
|
+
formatURL: () => formatURL
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(createSocketUrl_exports);
|
|
26
|
+
const HMR_SOCK_PATH = "/webpack-hmr";
|
|
27
|
+
function createSocketUrl(resourceQuery) {
|
|
28
|
+
const searchParams = resourceQuery.substr(1).split("&");
|
|
29
|
+
const options = {};
|
|
30
|
+
for (const pair of searchParams) {
|
|
31
|
+
const ary = pair.split("=");
|
|
32
|
+
options[ary[0]] = decodeURIComponent(ary[1]);
|
|
33
|
+
}
|
|
34
|
+
const currentLocation = self.location;
|
|
35
|
+
return getSocketUrl(options, currentLocation);
|
|
36
|
+
}
|
|
37
|
+
function formatURL({
|
|
38
|
+
port,
|
|
39
|
+
protocol,
|
|
40
|
+
hostname,
|
|
41
|
+
pathname
|
|
42
|
+
}) {
|
|
43
|
+
if (window.URL) {
|
|
44
|
+
const url = new URL("http://localhost");
|
|
45
|
+
url.port = port;
|
|
46
|
+
url.hostname = hostname;
|
|
47
|
+
url.protocol = protocol;
|
|
48
|
+
url.pathname = pathname;
|
|
49
|
+
return url.toString();
|
|
50
|
+
}
|
|
51
|
+
const colon = protocol.indexOf(":") === -1 ? ":" : "";
|
|
52
|
+
return `${protocol}${colon}//${hostname}:${port}${pathname}`;
|
|
53
|
+
}
|
|
54
|
+
function getSocketUrl(urlParts, location) {
|
|
55
|
+
const { host, port, path, protocol } = urlParts;
|
|
56
|
+
return formatURL({
|
|
57
|
+
protocol: protocol || (location.protocol === "https:" ? "wss" : "ws"),
|
|
58
|
+
hostname: host || location.hostname,
|
|
59
|
+
port: port || location.port,
|
|
60
|
+
pathname: path || HMR_SOCK_PATH
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
HMR_SOCK_PATH,
|
|
66
|
+
createSocketUrl,
|
|
67
|
+
formatURL
|
|
68
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var import_strip_ansi = __toESM(require("strip-ansi"));
|
|
25
|
+
var import_format_stats = require("@rsbuild/shared/format-stats");
|
|
26
|
+
var import_createSocketUrl = require("./createSocketUrl");
|
|
27
|
+
const hadRuntimeError = false;
|
|
28
|
+
const socketUrl = (0, import_createSocketUrl.createSocketUrl)(__resourceQuery);
|
|
29
|
+
const connection = new WebSocket(socketUrl);
|
|
30
|
+
connection.onopen = function() {
|
|
31
|
+
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
32
|
+
console.info("[HMR] connected.");
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
connection.onclose = function() {
|
|
36
|
+
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
37
|
+
console.info("[HMR] disconnected. Refresh the page if necessary.");
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
let isFirstCompilation = true;
|
|
41
|
+
let mostRecentCompilationHash = null;
|
|
42
|
+
let hasCompileErrors = false;
|
|
43
|
+
function clearOutdatedErrors() {
|
|
44
|
+
if (typeof console !== "undefined" && typeof console.clear === "function") {
|
|
45
|
+
if (hasCompileErrors) {
|
|
46
|
+
console.clear();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function handleSuccess() {
|
|
51
|
+
clearOutdatedErrors();
|
|
52
|
+
const isHotUpdate = !isFirstCompilation;
|
|
53
|
+
isFirstCompilation = false;
|
|
54
|
+
hasCompileErrors = false;
|
|
55
|
+
if (isHotUpdate) {
|
|
56
|
+
tryApplyUpdates();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function handleWarnings(warnings) {
|
|
60
|
+
clearOutdatedErrors();
|
|
61
|
+
const isHotUpdate = !isFirstCompilation;
|
|
62
|
+
isFirstCompilation = false;
|
|
63
|
+
hasCompileErrors = false;
|
|
64
|
+
function printWarnings() {
|
|
65
|
+
const formatted = (0, import_format_stats.formatStatsMessages)({
|
|
66
|
+
warnings,
|
|
67
|
+
errors: []
|
|
68
|
+
});
|
|
69
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
70
|
+
for (let i = 0; i < formatted.warnings.length; i++) {
|
|
71
|
+
if (i === 5) {
|
|
72
|
+
console.warn(
|
|
73
|
+
"There were more warnings in other files.\nYou can find a complete log in the terminal."
|
|
74
|
+
);
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
console.warn((0, import_strip_ansi.default)(formatted.warnings[i]));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
printWarnings();
|
|
82
|
+
if (isHotUpdate) {
|
|
83
|
+
tryApplyUpdates();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function handleErrors(errors) {
|
|
87
|
+
clearOutdatedErrors();
|
|
88
|
+
isFirstCompilation = false;
|
|
89
|
+
hasCompileErrors = true;
|
|
90
|
+
const formatted = (0, import_format_stats.formatStatsMessages)({
|
|
91
|
+
errors,
|
|
92
|
+
warnings: []
|
|
93
|
+
});
|
|
94
|
+
if (typeof console !== "undefined" && typeof console.error === "function") {
|
|
95
|
+
for (const error of formatted.errors) {
|
|
96
|
+
console.error((0, import_strip_ansi.default)(error));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function handleAvailableHash(hash) {
|
|
101
|
+
mostRecentCompilationHash = hash;
|
|
102
|
+
}
|
|
103
|
+
connection.onmessage = function(e) {
|
|
104
|
+
const message = JSON.parse(e.data);
|
|
105
|
+
switch (message.type) {
|
|
106
|
+
case "hash":
|
|
107
|
+
handleAvailableHash(message.data);
|
|
108
|
+
break;
|
|
109
|
+
case "still-ok":
|
|
110
|
+
case "ok":
|
|
111
|
+
handleSuccess();
|
|
112
|
+
break;
|
|
113
|
+
case "content-changed":
|
|
114
|
+
window.location.reload();
|
|
115
|
+
break;
|
|
116
|
+
case "warnings":
|
|
117
|
+
handleWarnings(message.data);
|
|
118
|
+
break;
|
|
119
|
+
case "errors":
|
|
120
|
+
handleErrors(message.data);
|
|
121
|
+
break;
|
|
122
|
+
default:
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
function isUpdateAvailable() {
|
|
126
|
+
return mostRecentCompilationHash !== __webpack_hash__;
|
|
127
|
+
}
|
|
128
|
+
function canApplyUpdates() {
|
|
129
|
+
return module.hot.status() === "idle";
|
|
130
|
+
}
|
|
131
|
+
function tryApplyUpdates() {
|
|
132
|
+
if (!module.hot) {
|
|
133
|
+
window.location.reload();
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (!isUpdateAvailable() || !canApplyUpdates()) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
function handleApplyUpdates(err, updatedModules) {
|
|
140
|
+
const wantsForcedReload = err || !updatedModules || hadRuntimeError;
|
|
141
|
+
if (wantsForcedReload) {
|
|
142
|
+
window.location.reload();
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (isUpdateAvailable()) {
|
|
146
|
+
tryApplyUpdates();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const result = module.hot.check(
|
|
150
|
+
/* autoApply */
|
|
151
|
+
true,
|
|
152
|
+
handleApplyUpdates
|
|
153
|
+
);
|
|
154
|
+
if (result == null ? void 0 : result.then) {
|
|
155
|
+
result.then(
|
|
156
|
+
(updatedModules) => {
|
|
157
|
+
handleApplyUpdates(null, updatedModules);
|
|
158
|
+
},
|
|
159
|
+
(err) => {
|
|
160
|
+
handleApplyUpdates(err, null);
|
|
161
|
+
}
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Server } from 'http';
|
|
4
|
+
import { EventEmitter } from 'events';
|
|
5
|
+
import type { DevServerOptions, DevMiddlewareAPI, DevMiddleware as CustomDevMiddleware } from '@rsbuild/shared';
|
|
6
|
+
type Options = {
|
|
7
|
+
dev: DevServerOptions;
|
|
8
|
+
devMiddleware?: CustomDevMiddleware;
|
|
9
|
+
};
|
|
10
|
+
export default class DevMiddleware extends EventEmitter {
|
|
11
|
+
middleware?: DevMiddlewareAPI;
|
|
12
|
+
private devOptions;
|
|
13
|
+
private socketServer;
|
|
14
|
+
constructor({
|
|
15
|
+
dev,
|
|
16
|
+
devMiddleware
|
|
17
|
+
}: Options);
|
|
18
|
+
init(app: Server): void;
|
|
19
|
+
sockWrite(type: string, data?: Record<string, any> | string | boolean): void;
|
|
20
|
+
private setupDevMiddleware;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var dev_middleware_exports = {};
|
|
30
|
+
__export(dev_middleware_exports, {
|
|
31
|
+
default: () => DevMiddleware
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(dev_middleware_exports);
|
|
34
|
+
var import_events = require("events");
|
|
35
|
+
var import_socketServer = __toESM(require("./socketServer"));
|
|
36
|
+
const noop = () => {
|
|
37
|
+
};
|
|
38
|
+
function getHMRClientPath(client) {
|
|
39
|
+
const protocol = (client == null ? void 0 : client.protocol) ? `&protocol=${client.protocol}` : "";
|
|
40
|
+
const host = (client == null ? void 0 : client.host) ? `&host=${client.host}` : "";
|
|
41
|
+
const path = (client == null ? void 0 : client.path) ? `&path=${client.path}` : "";
|
|
42
|
+
const port = (client == null ? void 0 : client.port) ? `&port=${client.port}` : "";
|
|
43
|
+
const clientEntry = `${require.resolve("@rsbuild/core/hmr-client")}?${host}${path}${port}${protocol}`;
|
|
44
|
+
return clientEntry;
|
|
45
|
+
}
|
|
46
|
+
class DevMiddleware extends import_events.EventEmitter {
|
|
47
|
+
constructor({ dev, devMiddleware }) {
|
|
48
|
+
super();
|
|
49
|
+
this.devOptions = dev;
|
|
50
|
+
this.socketServer = new import_socketServer.default(dev);
|
|
51
|
+
if (devMiddleware) {
|
|
52
|
+
this.middleware = this.setupDevMiddleware(devMiddleware);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
init(app) {
|
|
56
|
+
app.on("listening", () => {
|
|
57
|
+
this.socketServer.prepare(app);
|
|
58
|
+
});
|
|
59
|
+
app.on("close", async () => {
|
|
60
|
+
var _a;
|
|
61
|
+
(_a = this.middleware) == null ? void 0 : _a.close(noop);
|
|
62
|
+
this.socketServer.close();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
sockWrite(type, data) {
|
|
66
|
+
this.socketServer.sockWrite(type, data);
|
|
67
|
+
}
|
|
68
|
+
setupDevMiddleware(devMiddleware) {
|
|
69
|
+
const { devOptions } = this;
|
|
70
|
+
const callbacks = {
|
|
71
|
+
onInvalid: () => {
|
|
72
|
+
this.socketServer.sockWrite("invalid");
|
|
73
|
+
},
|
|
74
|
+
onDone: (stats) => {
|
|
75
|
+
this.socketServer.updateStats(stats);
|
|
76
|
+
this.emit("change", stats);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const enableHMR = this.devOptions.hot || this.devOptions.liveReload;
|
|
80
|
+
const middleware = devMiddleware({
|
|
81
|
+
headers: devOptions.headers,
|
|
82
|
+
stats: false,
|
|
83
|
+
callbacks,
|
|
84
|
+
hmrClientPath: enableHMR ? getHMRClientPath(devOptions.client) : void 0,
|
|
85
|
+
serverSideRender: true,
|
|
86
|
+
...devOptions.devMiddleware
|
|
87
|
+
});
|
|
88
|
+
return middleware;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Server } from 'http';
|
|
3
|
+
import ws from 'ws';
|
|
4
|
+
import { Stats, DevServerOptions } from '@rsbuild/shared';
|
|
5
|
+
export default class SocketServer {
|
|
6
|
+
private wsServer;
|
|
7
|
+
private readonly sockets;
|
|
8
|
+
private readonly options;
|
|
9
|
+
private app?;
|
|
10
|
+
private stats?;
|
|
11
|
+
private timer;
|
|
12
|
+
constructor(options: DevServerOptions);
|
|
13
|
+
prepare(app: Server): void;
|
|
14
|
+
updateStats(stats: Stats): void;
|
|
15
|
+
sockWrite(type: string, data?: Record<string, any> | string | boolean): void;
|
|
16
|
+
singleWrite(socket: ws, type: string, data?: Record<string, any> | string | boolean): void;
|
|
17
|
+
close(): void;
|
|
18
|
+
private onConnect;
|
|
19
|
+
private getStats;
|
|
20
|
+
private sendStats;
|
|
21
|
+
private send;
|
|
22
|
+
}
|