@rsbuild/core 0.0.19 → 0.0.20
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/plugins/asset.d.ts +1 -1
- package/dist/plugins/asset.js +19 -13
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.js +1 -5
- package/dist/plugins/inlineChunk.js +2 -7
- package/dist/plugins/splitChunks.js +0 -5
- package/dist/plugins/startUrl.js +5 -1
- package/dist/rspack-provider/core/initHooks.d.ts +2 -2
- package/dist/rspack-provider/core/initPlugins.js +5 -1
- package/dist/rspack-provider/index.d.ts +1 -1
- package/dist/rspack-provider/shared/plugin.js +1 -4
- package/dist/rspack-provider/types/index.d.ts +0 -1
- package/dist/rspack-provider/types/index.js +0 -2
- package/dist/rspack-provider/types/plugin.d.ts +1 -4
- package/dist/server/dev-middleware/hmr-client/createSocketUrl.d.ts +1 -1
- package/dist/server/dev-middleware/hmr-client/createSocketUrl.js +1 -1
- package/dist/server/dev-middleware/index.d.ts +2 -2
- package/dist/server/dev-middleware/index.js +1 -1
- package/dist/server/dev-middleware/socketServer.d.ts +2 -2
- package/dist/server/dev-middleware/socketServer.js +1 -4
- package/dist/server/devServer.d.ts +1 -2
- package/dist/server/devServer.js +18 -13
- package/dist/server/middlewares.d.ts +7 -1
- package/dist/server/middlewares.js +70 -2
- package/dist/server/prodServer.js +1 -1
- package/package.json +3 -3
- package/types.d.ts +63 -23
- package/dist/rspack-provider/types/hooks.d.ts +0 -3
- package/dist/rspack-provider/types/hooks.js +0 -16
- package/dist/server/constants.d.ts +0 -6
- package/dist/server/constants.js +0 -49
package/dist/plugins/asset.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { DefaultRsbuildPlugin } from '@rsbuild/shared';
|
|
2
2
|
export declare function getRegExpForExts(exts: string[]): RegExp;
|
|
3
|
-
export declare const pluginAsset: (
|
|
3
|
+
export declare const pluginAsset: () => DefaultRsbuildPlugin;
|
package/dist/plugins/asset.js
CHANGED
|
@@ -41,22 +41,28 @@ function getRegExpForExts(exts) {
|
|
|
41
41
|
"i"
|
|
42
42
|
);
|
|
43
43
|
}
|
|
44
|
-
const pluginAsset = (
|
|
45
|
-
name:
|
|
44
|
+
const pluginAsset = () => ({
|
|
45
|
+
name: "plugin-asset",
|
|
46
46
|
setup(api) {
|
|
47
47
|
api.modifyBundlerChain((chain, { isProd }) => {
|
|
48
48
|
const config = api.getNormalizedConfig();
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
49
|
+
const createAssetRule = (assetType, exts) => {
|
|
50
|
+
const regExp = getRegExpForExts(exts);
|
|
51
|
+
const distDir = (0, import_shared.getDistPath)(config.output, assetType);
|
|
52
|
+
const filename = (0, import_shared.getFilename)(config.output, assetType, isProd);
|
|
53
|
+
const maxSize = config.output.dataUriLimit[assetType];
|
|
54
|
+
const rule = chain.module.rule(assetType).test(regExp);
|
|
55
|
+
(0, import_shared.chainStaticAssetRule)({
|
|
56
|
+
rule,
|
|
57
|
+
maxSize,
|
|
58
|
+
filename: import_path.default.posix.join(distDir, filename),
|
|
59
|
+
assetType
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
createAssetRule("image", import_shared.IMAGE_EXTENSIONS);
|
|
63
|
+
createAssetRule("svg", ["svg"]);
|
|
64
|
+
createAssetRule("media", import_shared.MEDIA_EXTENSIONS);
|
|
65
|
+
createAssetRule("font", import_shared.FONT_EXTENSIONS);
|
|
60
66
|
});
|
|
61
67
|
}
|
|
62
68
|
});
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Plugins } from '@rsbuild/shared';
|
|
1
|
+
import type { Plugins } from '@rsbuild/shared';
|
|
2
2
|
export declare const plugins: Plugins;
|
package/dist/plugins/index.js
CHANGED
|
@@ -31,7 +31,6 @@ __export(plugins_exports, {
|
|
|
31
31
|
plugins: () => plugins
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(plugins_exports);
|
|
34
|
-
var import_shared = require("@rsbuild/shared");
|
|
35
34
|
const plugins = {
|
|
36
35
|
html: () => Promise.resolve().then(() => __toESM(require("./html"))).then((m) => m.pluginHtml()),
|
|
37
36
|
cleanOutput: () => Promise.resolve().then(() => __toESM(require("./cleanOutput"))).then((m) => m.pluginCleanOutput()),
|
|
@@ -46,10 +45,7 @@ const plugins = {
|
|
|
46
45
|
splitChunks: () => Promise.resolve().then(() => __toESM(require("./splitChunks"))).then((m) => m.pluginSplitChunks()),
|
|
47
46
|
inlineChunk: () => Promise.resolve().then(() => __toESM(require("./inlineChunk"))).then((m) => m.pluginInlineChunk()),
|
|
48
47
|
bundleAnalyzer: () => Promise.resolve().then(() => __toESM(require("./bundleAnalyzer"))).then((m) => m.pluginBundleAnalyzer()),
|
|
49
|
-
|
|
50
|
-
font: () => Promise.resolve().then(() => __toESM(require("./asset"))).then((m) => m.pluginAsset("font", import_shared.FONT_EXTENSIONS)),
|
|
51
|
-
image: () => Promise.resolve().then(() => __toESM(require("./asset"))).then((m) => m.pluginAsset("image", import_shared.IMAGE_EXTENSIONS)),
|
|
52
|
-
media: () => Promise.resolve().then(() => __toESM(require("./asset"))).then((m) => m.pluginAsset("media", import_shared.MEDIA_EXTENSIONS)),
|
|
48
|
+
asset: () => Promise.resolve().then(() => __toESM(require("./asset"))).then((m) => m.pluginAsset()),
|
|
53
49
|
rem: () => Promise.resolve().then(() => __toESM(require("./rem"))).then((m) => m.pluginRem()),
|
|
54
50
|
wasm: () => Promise.resolve().then(() => __toESM(require("./wasm"))).then((m) => m.pluginWasm()),
|
|
55
51
|
moment: () => Promise.resolve().then(() => __toESM(require("./moment"))).then((m) => m.pluginMoment()),
|
|
@@ -43,7 +43,6 @@ const pluginInlineChunk = () => ({
|
|
|
43
43
|
}
|
|
44
44
|
const { InlineChunkHtmlPlugin } = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared")));
|
|
45
45
|
const {
|
|
46
|
-
disableInlineRuntimeChunk,
|
|
47
46
|
enableInlineStyles,
|
|
48
47
|
// todo: not support enableInlineScripts in Rspack yet, which will take unknown build error
|
|
49
48
|
enableInlineScripts
|
|
@@ -60,12 +59,8 @@ const pluginInlineChunk = () => ({
|
|
|
60
59
|
enableInlineStyles === true ? import_shared.CSS_REGEX : enableInlineStyles
|
|
61
60
|
);
|
|
62
61
|
}
|
|
63
|
-
if (!
|
|
64
|
-
|
|
65
|
-
// RegExp like /bundler-runtime([.].+)?\.js$/
|
|
66
|
-
// matches bundler-runtime.js and bundler-runtime.123456.js
|
|
67
|
-
new RegExp(`${import_shared.RUNTIME_CHUNK_NAME}([.].+)?\\.js$`)
|
|
68
|
-
);
|
|
62
|
+
if (!scriptTests.length && !styleTests.length) {
|
|
63
|
+
return;
|
|
69
64
|
}
|
|
70
65
|
chain.plugin(CHAIN_ID.PLUGIN.INLINE_HTML).use(InlineChunkHtmlPlugin, [
|
|
71
66
|
HtmlPlugin,
|
|
@@ -226,11 +226,6 @@ function pluginSplitChunks() {
|
|
|
226
226
|
polyfill: config.output.polyfill
|
|
227
227
|
});
|
|
228
228
|
chain.optimization.splitChunks(splitChunksOptions);
|
|
229
|
-
if (chunkSplit.strategy !== "all-in-one") {
|
|
230
|
-
chain.optimization.runtimeChunk({
|
|
231
|
-
name: import_shared.RUNTIME_CHUNK_NAME
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
229
|
}
|
|
235
230
|
);
|
|
236
231
|
}
|
package/dist/plugins/startUrl.js
CHANGED
|
@@ -106,8 +106,12 @@ function pluginStartUrl() {
|
|
|
106
106
|
}
|
|
107
107
|
const urls = [];
|
|
108
108
|
if (startUrl === true || !startUrl) {
|
|
109
|
+
const { entry } = api.context;
|
|
110
|
+
const routes = (0, import_shared.formatRoutes)(entry);
|
|
109
111
|
const protocol = https ? "https" : "http";
|
|
110
|
-
urls.push(
|
|
112
|
+
urls.push(
|
|
113
|
+
(0, import_shared.normalizeUrl)(`${protocol}://localhost:${port}/${routes[0].route}`)
|
|
114
|
+
);
|
|
111
115
|
} else {
|
|
112
116
|
urls.push(
|
|
113
117
|
...(0, import_shared.castArray)(startUrl).map(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { OnExitFn, OnAfterBuildFn, OnBeforeBuildFn, OnDevCompileDoneFn, ModifyRsbuildConfigFn, OnAfterStartDevServerFn, OnBeforeStartDevServerFn, OnAfterCreateCompilerFn, OnBeforeCreateCompilerFn, ModifyBundlerChainFn, type RspackConfig } from '@rsbuild/shared';
|
|
2
|
-
import type { RsbuildConfig
|
|
1
|
+
import { OnExitFn, OnAfterBuildFn, OnBeforeBuildFn, OnDevCompileDoneFn, ModifyRsbuildConfigFn, OnAfterStartDevServerFn, OnBeforeStartDevServerFn, OnAfterCreateCompilerFn, OnBeforeCreateCompilerFn, ModifyBundlerChainFn, type RspackConfig, type ModifyRspackConfigFn } from '@rsbuild/shared';
|
|
2
|
+
import type { RsbuildConfig } from '../types';
|
|
3
3
|
export declare function initHooks(): {
|
|
4
4
|
/** parameters are not bundler-related */
|
|
5
5
|
onExitHook: import("@rsbuild/shared").AsyncHook<OnExitFn>;
|
|
@@ -73,7 +73,11 @@ function getPluginAPI({
|
|
|
73
73
|
onAfterCreateCompiler: hooks.onAfterCreateCompilerHook.tap,
|
|
74
74
|
onBeforeCreateCompiler: hooks.onBeforeCreateCompilerHook.tap,
|
|
75
75
|
onAfterStartDevServer: hooks.onAfterStartDevServerHook.tap,
|
|
76
|
-
onBeforeStartDevServer: hooks.onBeforeStartDevServerHook.tap
|
|
76
|
+
onBeforeStartDevServer: hooks.onBeforeStartDevServerHook.tap,
|
|
77
|
+
modifyWebpackChain: () => {
|
|
78
|
+
},
|
|
79
|
+
modifyWebpackConfig: () => {
|
|
80
|
+
}
|
|
77
81
|
};
|
|
78
82
|
}
|
|
79
83
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getRspackVersion } from './shared/rspackVersion';
|
|
2
2
|
export { rspackProvider } from './provider';
|
|
3
3
|
export type { RspackProvider } from './provider';
|
|
4
|
-
export type { RsbuildConfig, NormalizedConfig,
|
|
4
|
+
export type { RsbuildConfig, NormalizedConfig, RsbuildPluginAPI } from './types';
|
|
5
5
|
export type { Rspack, RspackConfig } from '@rsbuild/shared';
|
|
@@ -44,10 +44,7 @@ const applyDefaultPlugins = (plugins) => (0, import_shared.awaitableGetter)([
|
|
|
44
44
|
plugins.fileSize(),
|
|
45
45
|
// cleanOutput plugin should before the html plugin
|
|
46
46
|
plugins.cleanOutput(),
|
|
47
|
-
plugins.
|
|
48
|
-
plugins.image(),
|
|
49
|
-
plugins.media(),
|
|
50
|
-
plugins.svg(),
|
|
47
|
+
plugins.asset(),
|
|
51
48
|
plugins.html(),
|
|
52
49
|
plugins.wasm(),
|
|
53
50
|
plugins.moment(),
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export * from './hooks';
|
|
2
1
|
export * from './plugin';
|
|
3
2
|
export * from './context';
|
|
4
3
|
export type { RsbuildConfig, NormalizedConfig, DevConfig, HtmlConfig, ToolsConfig, SourceConfig, OutputConfig, SecurityConfig, PerformanceConfig, NormalizedDevConfig, NormalizedHtmlConfig, NormalizedToolsConfig, NormalizedSourceConfig, NormalizedOutputConfig, NormalizedSecurityConfig, NormalizedPerformanceConfig } from '@rsbuild/shared';
|
|
@@ -15,12 +15,10 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
15
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
16
|
var types_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(types_exports);
|
|
18
|
-
__reExport(types_exports, require("./hooks"), module.exports);
|
|
19
18
|
__reExport(types_exports, require("./plugin"), module.exports);
|
|
20
19
|
__reExport(types_exports, require("./context"), module.exports);
|
|
21
20
|
// Annotate the CommonJS export names for ESM import in node:
|
|
22
21
|
0 && (module.exports = {
|
|
23
|
-
...require("./hooks"),
|
|
24
22
|
...require("./plugin"),
|
|
25
23
|
...require("./context")
|
|
26
24
|
});
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import type { RsbuildConfig, NormalizedConfig, DefaultRsbuildPluginAPI, RsbuildPlugin as BaseRsbuildPlugin } from '@rsbuild/shared';
|
|
2
|
-
import type { ModifyRspackConfigFn } from './hooks';
|
|
3
2
|
import type { RspackConfig, RspackCompiler, RspackMultiCompiler } from '@rsbuild/shared';
|
|
4
|
-
export interface RsbuildPluginAPI extends DefaultRsbuildPluginAPI<RsbuildConfig, NormalizedConfig, RspackConfig, RspackCompiler | RspackMultiCompiler> {
|
|
5
|
-
modifyRspackConfig: (fn: ModifyRspackConfigFn) => void;
|
|
6
|
-
}
|
|
3
|
+
export interface RsbuildPluginAPI extends DefaultRsbuildPluginAPI<RsbuildConfig, NormalizedConfig, RspackConfig, RspackCompiler | RspackMultiCompiler> {}
|
|
7
4
|
export type RsbuildPlugin = BaseRsbuildPlugin<RsbuildPluginAPI>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* hmr socket connect path
|
|
3
3
|
*/
|
|
4
|
-
export declare const HMR_SOCK_PATH = "/
|
|
4
|
+
export declare const HMR_SOCK_PATH = "/rsbuild-hmr";
|
|
5
5
|
export declare function createSocketUrl(resourceQuery: string): string;
|
|
6
6
|
export declare function formatURL({
|
|
7
7
|
port,
|
|
@@ -23,7 +23,7 @@ __export(createSocketUrl_exports, {
|
|
|
23
23
|
formatURL: () => formatURL
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(createSocketUrl_exports);
|
|
26
|
-
const HMR_SOCK_PATH = "/
|
|
26
|
+
const HMR_SOCK_PATH = "/rsbuild-hmr";
|
|
27
27
|
function createSocketUrl(resourceQuery) {
|
|
28
28
|
const searchParams = resourceQuery.substr(1).split("&");
|
|
29
29
|
const options = {};
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import { Server } from 'http';
|
|
4
4
|
import { EventEmitter } from 'events';
|
|
5
|
-
import type {
|
|
5
|
+
import type { DevConfig, DevMiddlewareAPI, DevMiddleware as CustomDevMiddleware } from '@rsbuild/shared';
|
|
6
6
|
type Options = {
|
|
7
|
-
dev:
|
|
7
|
+
dev: DevConfig;
|
|
8
8
|
devMiddleware?: CustomDevMiddleware;
|
|
9
9
|
};
|
|
10
10
|
export default class DevMiddleware extends EventEmitter {
|
|
@@ -76,7 +76,7 @@ class DevMiddleware extends import_events.EventEmitter {
|
|
|
76
76
|
this.emit("change", stats);
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
|
-
const enableHMR = this.devOptions.
|
|
79
|
+
const enableHMR = this.devOptions.hmr;
|
|
80
80
|
const middleware = devMiddleware({
|
|
81
81
|
headers: devOptions.headers,
|
|
82
82
|
stats: false,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Server } from 'http';
|
|
3
3
|
import ws from 'ws';
|
|
4
|
-
import { Stats,
|
|
4
|
+
import { Stats, DevConfig } from '@rsbuild/shared';
|
|
5
5
|
export default class SocketServer {
|
|
6
6
|
private wsServer;
|
|
7
7
|
private readonly sockets;
|
|
@@ -9,7 +9,7 @@ export default class SocketServer {
|
|
|
9
9
|
private app?;
|
|
10
10
|
private stats?;
|
|
11
11
|
private timer;
|
|
12
|
-
constructor(options:
|
|
12
|
+
constructor(options: DevConfig);
|
|
13
13
|
prepare(app: Server): void;
|
|
14
14
|
updateStats(stats: Stats): void;
|
|
15
15
|
sockWrite(type: string, data?: Record<string, any> | string | boolean): void;
|
|
@@ -112,12 +112,9 @@ class SocketServer {
|
|
|
112
112
|
this.sockets.splice(idx, 1);
|
|
113
113
|
}
|
|
114
114
|
});
|
|
115
|
-
if (this.options.
|
|
115
|
+
if (this.options.hmr) {
|
|
116
116
|
this.singleWrite(connection, "hot");
|
|
117
117
|
}
|
|
118
|
-
if (this.options.liveReload) {
|
|
119
|
-
this.singleWrite(connection, "liveReload");
|
|
120
|
-
}
|
|
121
118
|
if (this.stats) {
|
|
122
119
|
this.sendStats(true);
|
|
123
120
|
}
|
|
@@ -10,9 +10,9 @@ export declare class RsbuildDevServer {
|
|
|
10
10
|
private readonly devMiddleware;
|
|
11
11
|
private pwd;
|
|
12
12
|
private app;
|
|
13
|
+
private output;
|
|
13
14
|
middlewares: connect.Server;
|
|
14
15
|
constructor(options: RsbuildDevServerOptions);
|
|
15
|
-
private getDevOptions;
|
|
16
16
|
private applySetupMiddlewares;
|
|
17
17
|
onInit(app: Server): Promise<void>;
|
|
18
18
|
private applyDefaultMiddlewares;
|
|
@@ -27,7 +27,6 @@ export declare function startDevServer<Options extends {
|
|
|
27
27
|
compiler,
|
|
28
28
|
printURLs,
|
|
29
29
|
strictPort,
|
|
30
|
-
serverOptions,
|
|
31
30
|
logger: customLogger,
|
|
32
31
|
getPortSilently
|
|
33
32
|
}?: StartDevServerOptions & {
|
package/dist/server/devServer.js
CHANGED
|
@@ -36,27 +36,22 @@ var import_http = require("http");
|
|
|
36
36
|
var import_https = require("https");
|
|
37
37
|
var import_url = __toESM(require("url"));
|
|
38
38
|
var import_shared = require("@rsbuild/shared");
|
|
39
|
-
var import_constants = require("./constants");
|
|
40
39
|
var import_dev_middleware = __toESM(require("./dev-middleware"));
|
|
41
|
-
var import_deepmerge = require("@rsbuild/shared/deepmerge");
|
|
42
40
|
var import_connect = __toESM(require("connect"));
|
|
43
41
|
var import_proxy = require("./proxy");
|
|
44
42
|
var import_middlewares = require("./middlewares");
|
|
43
|
+
var import_path = require("path");
|
|
45
44
|
class RsbuildDevServer {
|
|
46
45
|
constructor(options) {
|
|
47
46
|
this.middlewares = (0, import_connect.default)();
|
|
48
47
|
this.pwd = options.pwd;
|
|
49
|
-
this.dev =
|
|
48
|
+
this.dev = options.dev;
|
|
49
|
+
this.output = options.output;
|
|
50
50
|
this.devMiddleware = new import_dev_middleware.default({
|
|
51
51
|
dev: this.dev,
|
|
52
52
|
devMiddleware: options.devMiddleware
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
|
-
getDevOptions(options) {
|
|
56
|
-
const devOptions = typeof options.dev === "boolean" ? {} : options.dev;
|
|
57
|
-
const defaultOptions = (0, import_constants.getDefaultDevOptions)();
|
|
58
|
-
return (0, import_deepmerge.deepmerge)(defaultOptions, devOptions);
|
|
59
|
-
}
|
|
60
55
|
applySetupMiddlewares() {
|
|
61
56
|
const setupMiddlewares = this.dev.setupMiddlewares || [];
|
|
62
57
|
const serverOptions = {
|
|
@@ -117,6 +112,13 @@ class RsbuildDevServer {
|
|
|
117
112
|
}
|
|
118
113
|
devMiddleware.init(app);
|
|
119
114
|
devMiddleware.middleware && this.middlewares.use(devMiddleware.middleware);
|
|
115
|
+
this.middlewares.use(
|
|
116
|
+
(0, import_middlewares.getHtmlFallbackMiddleware)({
|
|
117
|
+
distPath: (0, import_path.join)(this.pwd, this.output.distPath),
|
|
118
|
+
assetPrefix: this.output.assetPrefix,
|
|
119
|
+
callback: devMiddleware.middleware
|
|
120
|
+
})
|
|
121
|
+
);
|
|
120
122
|
if (dev.historyApiFallback) {
|
|
121
123
|
const { default: connectHistoryApiFallback } = await Promise.resolve().then(() => __toESM(require("connect-history-api-fallback")));
|
|
122
124
|
const historyApiFallbackMiddleware = connectHistoryApiFallback(
|
|
@@ -127,6 +129,7 @@ class RsbuildDevServer {
|
|
|
127
129
|
devMiddleware.middleware && this.middlewares.use(devMiddleware.middleware);
|
|
128
130
|
}
|
|
129
131
|
this.middlewares.use(import_middlewares.faviconFallbackMiddleware);
|
|
132
|
+
this.middlewares.use(import_middlewares.notFoundMiddleware);
|
|
130
133
|
}
|
|
131
134
|
async createHTTPServer() {
|
|
132
135
|
const { dev } = this;
|
|
@@ -158,11 +161,10 @@ async function startDevServer(options, startDevCompile, {
|
|
|
158
161
|
compiler,
|
|
159
162
|
printURLs = true,
|
|
160
163
|
strictPort = false,
|
|
161
|
-
serverOptions = {},
|
|
162
164
|
logger: customLogger,
|
|
163
165
|
getPortSilently
|
|
164
166
|
} = {}) {
|
|
165
|
-
var _a;
|
|
167
|
+
var _a, _b, _c;
|
|
166
168
|
if (!process.env.NODE_ENV) {
|
|
167
169
|
process.env.NODE_ENV = "development";
|
|
168
170
|
}
|
|
@@ -170,7 +172,6 @@ async function startDevServer(options, startDevCompile, {
|
|
|
170
172
|
const logger = customLogger != null ? customLogger : import_shared.logger;
|
|
171
173
|
const { devServerConfig, port, host, https } = await (0, import_shared.getDevOptions)({
|
|
172
174
|
rsbuildConfig,
|
|
173
|
-
serverOptions,
|
|
174
175
|
strictPort,
|
|
175
176
|
getPortSilently
|
|
176
177
|
});
|
|
@@ -189,14 +190,18 @@ async function startDevServer(options, startDevCompile, {
|
|
|
189
190
|
throw new Error("Please return an array in the `printURLs` function.");
|
|
190
191
|
}
|
|
191
192
|
}
|
|
192
|
-
(0, import_shared.printServerURLs)(urls, logger);
|
|
193
|
+
(0, import_shared.printServerURLs)(urls, options.context.entry, logger);
|
|
193
194
|
}
|
|
194
195
|
(0, import_shared.debug)("create dev server");
|
|
195
196
|
const devMiddleware = await startDevCompile(options, compiler);
|
|
196
197
|
const server = new RsbuildDevServer({
|
|
197
198
|
pwd: options.context.rootPath,
|
|
198
199
|
devMiddleware,
|
|
199
|
-
dev: devServerConfig
|
|
200
|
+
dev: devServerConfig,
|
|
201
|
+
output: {
|
|
202
|
+
distPath: ((_c = (_b = rsbuildConfig.output) == null ? void 0 : _b.distPath) == null ? void 0 : _c.root) || import_shared.ROOT_DIST_DIR,
|
|
203
|
+
assetPrefix: typeof devServerConfig.assetPrefix === "string" && !(0, import_shared.isURL)(devServerConfig.assetPrefix) ? devServerConfig.assetPrefix : ""
|
|
204
|
+
}
|
|
200
205
|
});
|
|
201
206
|
(0, import_shared.debug)("create dev server done");
|
|
202
207
|
await options.context.hooks.onBeforeStartDevServerHook.call();
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import { RequestHandler as Middleware } from '@rsbuild/shared';
|
|
2
|
-
export declare const faviconFallbackMiddleware: Middleware;
|
|
2
|
+
export declare const faviconFallbackMiddleware: Middleware;
|
|
3
|
+
export declare const notFoundMiddleware: Middleware;
|
|
4
|
+
export declare const getHtmlFallbackMiddleware: (params: {
|
|
5
|
+
distPath: string;
|
|
6
|
+
assetPrefix: string;
|
|
7
|
+
callback?: Middleware;
|
|
8
|
+
}) => Middleware;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,12 +17,25 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
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
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var middlewares_exports = {};
|
|
20
30
|
__export(middlewares_exports, {
|
|
21
|
-
faviconFallbackMiddleware: () => faviconFallbackMiddleware
|
|
31
|
+
faviconFallbackMiddleware: () => faviconFallbackMiddleware,
|
|
32
|
+
getHtmlFallbackMiddleware: () => getHtmlFallbackMiddleware,
|
|
33
|
+
notFoundMiddleware: () => notFoundMiddleware
|
|
22
34
|
});
|
|
23
35
|
module.exports = __toCommonJS(middlewares_exports);
|
|
36
|
+
var import_shared = require("@rsbuild/shared");
|
|
37
|
+
var import_path = __toESM(require("path"));
|
|
38
|
+
var import_fs = __toESM(require("fs"));
|
|
24
39
|
const faviconFallbackMiddleware = (req, res, next) => {
|
|
25
40
|
if (req.url === "/favicon.ico") {
|
|
26
41
|
res.statusCode = 204;
|
|
@@ -29,7 +44,60 @@ const faviconFallbackMiddleware = (req, res, next) => {
|
|
|
29
44
|
next();
|
|
30
45
|
}
|
|
31
46
|
};
|
|
47
|
+
const notFoundMiddleware = (_req, res, _next) => {
|
|
48
|
+
res.statusCode = 404;
|
|
49
|
+
res.end();
|
|
50
|
+
};
|
|
51
|
+
const getHtmlFallbackMiddleware = ({ assetPrefix, distPath, callback }) => {
|
|
52
|
+
return (req, res, next) => {
|
|
53
|
+
if (
|
|
54
|
+
// Only accept GET or HEAD
|
|
55
|
+
req.method !== "GET" && req.method !== "HEAD" || // Require Accept header
|
|
56
|
+
!req.headers || typeof req.headers.accept !== "string" || // Ignore JSON requests
|
|
57
|
+
req.headers.accept.includes("application/json") || // Require Accept: text/html or */*
|
|
58
|
+
!(req.headers.accept.includes("text/html") || req.headers.accept.includes("*/*")) || !req.url
|
|
59
|
+
) {
|
|
60
|
+
return next();
|
|
61
|
+
}
|
|
62
|
+
const { url } = req;
|
|
63
|
+
const pathname = decodeURIComponent(url);
|
|
64
|
+
let outputFileSystem = import_fs.default;
|
|
65
|
+
if (res.locals.webpack) {
|
|
66
|
+
const { devMiddleware } = res.locals.webpack;
|
|
67
|
+
outputFileSystem = devMiddleware.outputFileSystem;
|
|
68
|
+
}
|
|
69
|
+
const tryRewrite = (filePath, newUrl) => {
|
|
70
|
+
var _a;
|
|
71
|
+
if (outputFileSystem.existsSync(filePath) && callback) {
|
|
72
|
+
newUrl = (0, import_shared.urlJoin)(assetPrefix, newUrl);
|
|
73
|
+
(_a = import_shared.debug) == null ? void 0 : _a(`Rewriting ${req.method} ${req.url} to ${newUrl}`);
|
|
74
|
+
req.url = newUrl;
|
|
75
|
+
return callback(req, res, (...args) => {
|
|
76
|
+
req.url = url;
|
|
77
|
+
next(...args);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
if (pathname.endsWith("/")) {
|
|
82
|
+
const newUrl = url + "index.html";
|
|
83
|
+
const filePath = import_path.default.join(distPath, pathname, "index.html");
|
|
84
|
+
tryRewrite(filePath, newUrl);
|
|
85
|
+
} else if (
|
|
86
|
+
// '/main' => '/main.html'
|
|
87
|
+
!pathname.endsWith(".html")
|
|
88
|
+
) {
|
|
89
|
+
const newUrl = url + ".html";
|
|
90
|
+
const filePath = import_path.default.join(distPath, pathname + ".html");
|
|
91
|
+
tryRewrite(filePath, newUrl);
|
|
92
|
+
} else {
|
|
93
|
+
tryRewrite(import_path.default.join(distPath, pathname), url);
|
|
94
|
+
}
|
|
95
|
+
next();
|
|
96
|
+
};
|
|
97
|
+
};
|
|
32
98
|
// Annotate the CommonJS export names for ESM import in node:
|
|
33
99
|
0 && (module.exports = {
|
|
34
|
-
faviconFallbackMiddleware
|
|
100
|
+
faviconFallbackMiddleware,
|
|
101
|
+
getHtmlFallbackMiddleware,
|
|
102
|
+
notFoundMiddleware
|
|
35
103
|
});
|
|
@@ -115,7 +115,7 @@ async function startProdServer(context, rsbuildConfig) {
|
|
|
115
115
|
},
|
|
116
116
|
() => {
|
|
117
117
|
const urls = (0, import_shared.getAddressUrls)("http", port);
|
|
118
|
-
(0, import_shared.printServerURLs)(urls);
|
|
118
|
+
(0, import_shared.printServerURLs)(urls, context.entry);
|
|
119
119
|
resolve({
|
|
120
120
|
port,
|
|
121
121
|
urls: urls.map((item) => item.url),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
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": {
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"core-js": "~3.32.2",
|
|
87
87
|
"filesize": "^8.0.7",
|
|
88
88
|
"gzip-size": "^6.0.0",
|
|
89
|
-
"html-webpack-plugin": "5.5.
|
|
89
|
+
"html-webpack-plugin": "npm:html-rspack-plugin@5.5.4",
|
|
90
90
|
"http-compression": "1.0.6",
|
|
91
91
|
"http-proxy-middleware": "^2.0.1",
|
|
92
92
|
"jiti": "^1.20.0",
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
"sirv": "^2.0.3",
|
|
99
99
|
"strip-ansi": "^6.0.1",
|
|
100
100
|
"ws": "^8.2.0",
|
|
101
|
-
"@rsbuild/shared": "0.0.
|
|
101
|
+
"@rsbuild/shared": "0.0.20"
|
|
102
102
|
},
|
|
103
103
|
"devDependencies": {
|
|
104
104
|
"@types/connect": "3.4.35",
|
package/types.d.ts
CHANGED
|
@@ -5,99 +5,139 @@ declare module '*.bmp' {
|
|
|
5
5
|
const src: string;
|
|
6
6
|
export default src;
|
|
7
7
|
}
|
|
8
|
-
declare module '*.
|
|
8
|
+
declare module '*.gif' {
|
|
9
9
|
const src: string;
|
|
10
10
|
export default src;
|
|
11
11
|
}
|
|
12
|
-
declare module '*.
|
|
12
|
+
declare module '*.jpg' {
|
|
13
13
|
const src: string;
|
|
14
14
|
export default src;
|
|
15
15
|
}
|
|
16
|
-
declare module '*.
|
|
16
|
+
declare module '*.jpeg' {
|
|
17
17
|
const src: string;
|
|
18
18
|
export default src;
|
|
19
19
|
}
|
|
20
|
-
declare module '*.
|
|
20
|
+
declare module '*.png' {
|
|
21
21
|
const src: string;
|
|
22
22
|
export default src;
|
|
23
23
|
}
|
|
24
|
-
declare module '*.
|
|
24
|
+
declare module '*.ico' {
|
|
25
25
|
const src: string;
|
|
26
26
|
export default src;
|
|
27
27
|
}
|
|
28
|
-
declare module '*.
|
|
28
|
+
declare module '*.webp' {
|
|
29
29
|
const src: string;
|
|
30
30
|
export default src;
|
|
31
31
|
}
|
|
32
|
-
declare module '*.
|
|
32
|
+
declare module '*.svg' {
|
|
33
33
|
const src: string;
|
|
34
34
|
export default src;
|
|
35
35
|
}
|
|
36
|
-
declare module '*.
|
|
36
|
+
declare module '*.apng' {
|
|
37
37
|
const src: string;
|
|
38
38
|
export default src;
|
|
39
39
|
}
|
|
40
|
-
declare module '*.
|
|
40
|
+
declare module '*.avif' {
|
|
41
41
|
const src: string;
|
|
42
42
|
export default src;
|
|
43
43
|
}
|
|
44
|
-
declare module '*.
|
|
44
|
+
declare module '*.tiff' {
|
|
45
45
|
const src: string;
|
|
46
46
|
export default src;
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Font assets
|
|
51
|
+
*/
|
|
52
|
+
declare module '*.woff' {
|
|
49
53
|
const src: string;
|
|
50
54
|
export default src;
|
|
51
55
|
}
|
|
52
|
-
declare module '*.
|
|
56
|
+
declare module '*.woff2' {
|
|
53
57
|
const src: string;
|
|
54
58
|
export default src;
|
|
55
59
|
}
|
|
56
|
-
declare module '*.
|
|
60
|
+
declare module '*.eot' {
|
|
57
61
|
const src: string;
|
|
58
62
|
export default src;
|
|
59
63
|
}
|
|
60
|
-
declare module '*.
|
|
64
|
+
declare module '*.ttf' {
|
|
61
65
|
const src: string;
|
|
62
66
|
export default src;
|
|
63
67
|
}
|
|
64
|
-
declare module '*.
|
|
68
|
+
declare module '*.otf' {
|
|
69
|
+
const src: string;
|
|
70
|
+
export default src;
|
|
71
|
+
}
|
|
72
|
+
declare module '*.ttc' {
|
|
65
73
|
const src: string;
|
|
66
74
|
export default src;
|
|
67
75
|
}
|
|
68
|
-
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Media assets
|
|
79
|
+
*/
|
|
80
|
+
declare module '*.mp4' {
|
|
69
81
|
const src: string;
|
|
70
82
|
export default src;
|
|
71
83
|
}
|
|
72
|
-
declare module '*.
|
|
84
|
+
declare module '*.webm' {
|
|
73
85
|
const src: string;
|
|
74
86
|
export default src;
|
|
75
87
|
}
|
|
76
|
-
declare module '*.
|
|
88
|
+
declare module '*.ogg' {
|
|
77
89
|
const src: string;
|
|
78
90
|
export default src;
|
|
79
91
|
}
|
|
80
|
-
declare module '*.
|
|
92
|
+
declare module '*.mp3' {
|
|
81
93
|
const src: string;
|
|
82
94
|
export default src;
|
|
83
95
|
}
|
|
84
|
-
declare module '*.
|
|
96
|
+
declare module '*.wav' {
|
|
85
97
|
const src: string;
|
|
86
98
|
export default src;
|
|
87
99
|
}
|
|
88
|
-
declare module '*.
|
|
100
|
+
declare module '*.flac' {
|
|
89
101
|
const src: string;
|
|
90
102
|
export default src;
|
|
91
103
|
}
|
|
92
|
-
declare module '*.
|
|
104
|
+
declare module '*.aac' {
|
|
93
105
|
const src: string;
|
|
94
106
|
export default src;
|
|
95
107
|
}
|
|
96
|
-
declare module '*.
|
|
108
|
+
declare module '*.mov' {
|
|
97
109
|
const src: string;
|
|
98
110
|
export default src;
|
|
99
111
|
}
|
|
100
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Configuration files
|
|
115
|
+
*/
|
|
116
|
+
declare module '*.yaml' {
|
|
117
|
+
const content: Record<string, any>;
|
|
118
|
+
export default content;
|
|
119
|
+
}
|
|
120
|
+
declare module '*.yml' {
|
|
121
|
+
const content: Record<string, any>;
|
|
122
|
+
export default content;
|
|
123
|
+
}
|
|
124
|
+
declare module '*.toml' {
|
|
125
|
+
const content: Record<string, any>;
|
|
126
|
+
export default content;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Queries
|
|
131
|
+
*/
|
|
132
|
+
declare module '*?url' {
|
|
133
|
+
const content: string;
|
|
134
|
+
export default content;
|
|
135
|
+
}
|
|
136
|
+
declare module '*?inline' {
|
|
137
|
+
const content: string;
|
|
138
|
+
export default content;
|
|
139
|
+
}
|
|
140
|
+
|
|
101
141
|
/**
|
|
102
142
|
* CSS Modules
|
|
103
143
|
*/
|
|
@@ -1,16 +0,0 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var hooks_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(hooks_exports);
|
package/dist/server/constants.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
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
|
-
});
|