@rsbuild/core 0.1.0 → 0.1.2
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/compiled/ws/index.d.ts +410 -0
- package/compiled/ws/index.js +1 -0
- package/compiled/ws/license +20 -0
- package/compiled/ws/package.json +1 -0
- package/dist/cli/commands.d.ts +3 -0
- package/dist/cli/commands.js +9 -7
- package/dist/cli/prepare.js +1 -1
- package/dist/client/hmr.js +187 -187
- package/dist/plugins/fileSize.js +4 -3
- package/dist/plugins/html.d.ts +6 -4
- package/dist/plugins/html.js +46 -27
- package/dist/rspack-plugins/HtmlBasicPlugin.d.ts +2 -2
- package/dist/rspack-plugins/HtmlBasicPlugin.js +9 -17
- package/dist/rspack-provider/core/createCompiler.d.ts +1 -1
- package/dist/rspack-provider/core/createCompiler.js +16 -0
- package/dist/rspack-provider/core/createContext.js +1 -1
- package/dist/rspack-provider/plugins/swc.js +2 -3
- package/dist/rspack-provider/plugins/transition.js +0 -4
- package/dist/rspack-provider/provider.js +0 -7
- package/dist/rspack-provider/shared.d.ts +2 -2
- package/dist/rspack-provider/shared.js +7 -8
- package/dist/server/dev-middleware/index.d.ts +5 -2
- package/dist/server/dev-middleware/index.js +23 -4
- package/dist/server/dev-middleware/socketServer.d.ts +3 -3
- package/dist/server/dev-middleware/socketServer.js +1 -1
- package/dist/server/devServer.js +3 -3
- package/dist/server/middlewares.d.ts +0 -1
- package/dist/server/middlewares.js +1 -6
- package/package.json +2 -4
|
@@ -35,6 +35,7 @@ module.exports = __toCommonJS(createCompiler_exports);
|
|
|
35
35
|
var import_shared = require("@rsbuild/shared");
|
|
36
36
|
var import_devMiddleware = require("./devMiddleware");
|
|
37
37
|
var import_initConfigs = require("./initConfigs");
|
|
38
|
+
var import_shared2 = require("../shared");
|
|
38
39
|
async function createCompiler({
|
|
39
40
|
context,
|
|
40
41
|
rspackConfigs
|
|
@@ -44,11 +45,26 @@ async function createCompiler({
|
|
|
44
45
|
bundlerConfigs: rspackConfigs
|
|
45
46
|
});
|
|
46
47
|
const { rspack } = await Promise.resolve().then(() => __toESM(require("@rspack/core")));
|
|
48
|
+
if (!await (0, import_shared2.isSatisfyRspackVersion)(rspack.rspackVersion)) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`The current Rspack version does not meet the requirements, the minimum supported version of Rspack is ${import_shared.color.green(
|
|
51
|
+
import_shared2.rspackMinVersion
|
|
52
|
+
)}`
|
|
53
|
+
);
|
|
54
|
+
}
|
|
47
55
|
const compiler = rspackConfigs.length === 1 ? rspack(rspackConfigs[0]) : rspack(rspackConfigs);
|
|
48
56
|
let isFirstCompile = true;
|
|
49
57
|
compiler.hooks.watchRun.tap("rsbuild:compiling", () => {
|
|
58
|
+
if (isFirstCompile) {
|
|
59
|
+
import_shared.logger.start(`Use Rspack v${rspack.rspackVersion}`);
|
|
60
|
+
}
|
|
50
61
|
import_shared.logger.start("Compiling...");
|
|
51
62
|
});
|
|
63
|
+
if ((0, import_shared.isProd)()) {
|
|
64
|
+
compiler.hooks.run.tap("rsbuild:run", () => {
|
|
65
|
+
import_shared.logger.start(`Use Rspack v${rspack.rspackVersion}`);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
52
68
|
compiler.hooks.done.tap("rsbuild:done", async (stats) => {
|
|
53
69
|
const obj = stats.toJson({
|
|
54
70
|
all: false,
|
|
@@ -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.1.
|
|
67
|
+
version: "0.1.2",
|
|
68
68
|
target,
|
|
69
69
|
rootPath,
|
|
70
70
|
distPath,
|
|
@@ -92,7 +92,7 @@ const pluginSwc = () => ({
|
|
|
92
92
|
swcConfig.env.mode = void 0;
|
|
93
93
|
} else {
|
|
94
94
|
swcConfig.env.mode = polyfillMode;
|
|
95
|
-
await applyCoreJs(swcConfig, chain,
|
|
95
|
+
await applyCoreJs(swcConfig, chain, polyfillMode);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
rule.use(CHAIN_ID.USE.SWC).loader(builtinSwcLoaderName).options(swcConfig);
|
|
@@ -110,7 +110,7 @@ const pluginSwc = () => ({
|
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
112
|
});
|
|
113
|
-
async function applyCoreJs(swcConfig, chain,
|
|
113
|
+
async function applyCoreJs(swcConfig, chain, polyfillMode) {
|
|
114
114
|
const coreJsPath = require.resolve("core-js/package.json");
|
|
115
115
|
const version = (0, import_shared.getCoreJsVersion)(coreJsPath);
|
|
116
116
|
const coreJsDir = path.dirname(coreJsPath);
|
|
@@ -121,7 +121,6 @@ async function applyCoreJs(swcConfig, chain, rule, polyfillMode) {
|
|
|
121
121
|
chain.resolve.alias.merge({
|
|
122
122
|
"core-js": coreJsDir
|
|
123
123
|
});
|
|
124
|
-
rule.exclude.add(coreJsDir);
|
|
125
124
|
}
|
|
126
125
|
function applyTransformImport(swcConfig, pluginImport) {
|
|
127
126
|
var _a, _b, _c;
|
|
@@ -21,7 +21,6 @@ __export(transition_exports, {
|
|
|
21
21
|
pluginTransition: () => pluginTransition
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(transition_exports);
|
|
24
|
-
var import_shared = require("@rsbuild/shared");
|
|
25
24
|
const pluginTransition = () => ({
|
|
26
25
|
name: "rsbuild:transition",
|
|
27
26
|
setup(api) {
|
|
@@ -31,9 +30,6 @@ const pluginTransition = () => ({
|
|
|
31
30
|
chain.optimization.chunkIds("deterministic");
|
|
32
31
|
}
|
|
33
32
|
});
|
|
34
|
-
api.modifyRspackConfig((config) => {
|
|
35
|
-
(0, import_shared.setConfig)(config, "experiments.rspackFuture.newResolver", true);
|
|
36
|
-
});
|
|
37
33
|
}
|
|
38
34
|
});
|
|
39
35
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -41,13 +41,6 @@ function rspackProvider({
|
|
|
41
41
|
}) {
|
|
42
42
|
const rsbuildConfig = (0, import_shared.pickRsbuildConfig)(originalRsbuildConfig);
|
|
43
43
|
return async ({ pluginStore, rsbuildOptions, plugins }) => {
|
|
44
|
-
if (!await (0, import_shared2.isSatisfyRspackMinimumVersion)()) {
|
|
45
|
-
throw new Error(
|
|
46
|
-
`The current Rspack version does not meet the requirements, the minimum supported version of Rspack is ${import_shared.color.green(
|
|
47
|
-
import_shared2.supportedRspackMinimumVersion
|
|
48
|
-
)}`
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
44
|
const context = await (0, import_createContext.createContext)(rsbuildOptions, rsbuildConfig);
|
|
52
45
|
const pluginAPI = (0, import_initPlugins.getPluginAPI)({ context, pluginStore });
|
|
53
46
|
context.pluginAPI = pluginAPI;
|
|
@@ -2,7 +2,7 @@ import { RsbuildPlugin } from '../types';
|
|
|
2
2
|
import { Plugins } from '@rsbuild/shared';
|
|
3
3
|
export declare const applyDefaultPlugins: (plugins: Plugins) => import("@rsbuild/shared").AwaitableGetter<RsbuildPlugin>;
|
|
4
4
|
export declare const getRspackVersion: () => Promise<string>;
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
5
|
+
export declare const rspackMinVersion = "0.3.6";
|
|
6
|
+
export declare const isSatisfyRspackVersion: (version: string) => Promise<boolean>;
|
|
7
7
|
export declare const getCompiledPath: (packageName: string) => string;
|
|
8
8
|
export declare const BUILTIN_LOADER = "builtin:";
|
|
@@ -32,8 +32,8 @@ __export(shared_exports, {
|
|
|
32
32
|
applyDefaultPlugins: () => applyDefaultPlugins,
|
|
33
33
|
getCompiledPath: () => getCompiledPath,
|
|
34
34
|
getRspackVersion: () => getRspackVersion,
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
isSatisfyRspackVersion: () => isSatisfyRspackVersion,
|
|
36
|
+
rspackMinVersion: () => rspackMinVersion
|
|
37
37
|
});
|
|
38
38
|
module.exports = __toCommonJS(shared_exports);
|
|
39
39
|
var import_path = require("path");
|
|
@@ -87,14 +87,13 @@ const getRspackVersion = async () => {
|
|
|
87
87
|
return "";
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
|
-
const
|
|
91
|
-
const
|
|
92
|
-
let version = customVersion || await getRspackVersion();
|
|
90
|
+
const rspackMinVersion = "0.3.6";
|
|
91
|
+
const isSatisfyRspackVersion = async (version) => {
|
|
93
92
|
const semver = await Promise.resolve().then(() => __toESM(require("semver")));
|
|
94
93
|
if (version.includes("-canary")) {
|
|
95
94
|
version = version.split("-canary")[0];
|
|
96
95
|
}
|
|
97
|
-
return version ? semver.lte(
|
|
96
|
+
return version ? semver.lte(rspackMinVersion, version) : true;
|
|
98
97
|
};
|
|
99
98
|
const getCompiledPath = (packageName) => {
|
|
100
99
|
const providerCompilerPath = (0, import_path.join)(__dirname, "../../compiled", packageName);
|
|
@@ -111,6 +110,6 @@ const BUILTIN_LOADER = "builtin:";
|
|
|
111
110
|
applyDefaultPlugins,
|
|
112
111
|
getCompiledPath,
|
|
113
112
|
getRspackVersion,
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
isSatisfyRspackVersion,
|
|
114
|
+
rspackMinVersion
|
|
116
115
|
});
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import { Server } from 'http';
|
|
3
|
+
import type { Server } from 'http';
|
|
4
4
|
import { EventEmitter } from 'events';
|
|
5
5
|
import type { DevConfig, DevMiddlewareAPI, DevMiddleware as CustomDevMiddleware } from '@rsbuild/shared';
|
|
6
6
|
type Options = {
|
|
7
|
+
publicPaths: string[];
|
|
7
8
|
dev: DevConfig;
|
|
8
9
|
devMiddleware?: CustomDevMiddleware;
|
|
9
10
|
};
|
|
@@ -11,10 +12,12 @@ export default class DevMiddleware extends EventEmitter {
|
|
|
11
12
|
middleware?: DevMiddlewareAPI;
|
|
12
13
|
private devOptions;
|
|
13
14
|
private devMiddleware?;
|
|
15
|
+
private publicPaths;
|
|
14
16
|
private socketServer;
|
|
15
17
|
constructor({
|
|
16
18
|
dev,
|
|
17
|
-
devMiddleware
|
|
19
|
+
devMiddleware,
|
|
20
|
+
publicPaths
|
|
18
21
|
}: Options);
|
|
19
22
|
init(app: Server): void;
|
|
20
23
|
close(): void;
|
|
@@ -44,15 +44,19 @@ function getHMRClientPath(client) {
|
|
|
44
44
|
return clientEntry;
|
|
45
45
|
}
|
|
46
46
|
class DevMiddleware extends import_events.EventEmitter {
|
|
47
|
-
constructor({ dev, devMiddleware }) {
|
|
47
|
+
constructor({ dev, devMiddleware, publicPaths }) {
|
|
48
48
|
super();
|
|
49
49
|
this.devOptions = dev;
|
|
50
|
+
this.publicPaths = publicPaths;
|
|
50
51
|
this.socketServer = new import_socketServer.default(dev);
|
|
51
52
|
this.devMiddleware = devMiddleware;
|
|
52
53
|
}
|
|
53
54
|
init(app) {
|
|
54
55
|
if (this.devMiddleware) {
|
|
55
|
-
this.middleware = this.setupDevMiddleware(
|
|
56
|
+
this.middleware = this.setupDevMiddleware(
|
|
57
|
+
this.devMiddleware,
|
|
58
|
+
this.publicPaths
|
|
59
|
+
);
|
|
56
60
|
}
|
|
57
61
|
app.on("listening", () => {
|
|
58
62
|
this.socketServer.prepare(app);
|
|
@@ -66,7 +70,7 @@ class DevMiddleware extends import_events.EventEmitter {
|
|
|
66
70
|
sockWrite(type, data) {
|
|
67
71
|
this.socketServer.sockWrite(type, data);
|
|
68
72
|
}
|
|
69
|
-
setupDevMiddleware(devMiddleware) {
|
|
73
|
+
setupDevMiddleware(devMiddleware, publicPaths) {
|
|
70
74
|
const { devOptions } = this;
|
|
71
75
|
const callbacks = {
|
|
72
76
|
onInvalid: () => {
|
|
@@ -80,12 +84,27 @@ class DevMiddleware extends import_events.EventEmitter {
|
|
|
80
84
|
const enableHMR = this.devOptions.hmr;
|
|
81
85
|
const middleware = devMiddleware({
|
|
82
86
|
headers: devOptions.headers,
|
|
87
|
+
publicPath: "/",
|
|
83
88
|
stats: false,
|
|
84
89
|
callbacks,
|
|
85
90
|
hmrClientPath: enableHMR ? getHMRClientPath(devOptions.client) : void 0,
|
|
86
91
|
serverSideRender: true,
|
|
87
92
|
writeToDisk: devOptions.writeToDisk
|
|
88
93
|
});
|
|
89
|
-
|
|
94
|
+
const warp = async (req, res, next) => {
|
|
95
|
+
const url = req.url;
|
|
96
|
+
const assetPrefix = url && publicPaths.find((prefix) => url.startsWith(prefix));
|
|
97
|
+
if (assetPrefix && assetPrefix !== "/") {
|
|
98
|
+
req.url = url.slice(assetPrefix.length - 1);
|
|
99
|
+
middleware(req, res, (...args) => {
|
|
100
|
+
req.url = url;
|
|
101
|
+
next(...args);
|
|
102
|
+
});
|
|
103
|
+
} else {
|
|
104
|
+
middleware(req, res, next);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
warp.close = middleware.close;
|
|
108
|
+
return warp;
|
|
90
109
|
}
|
|
91
110
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Server } from 'http';
|
|
3
|
-
import ws from 'ws';
|
|
4
|
-
import { Stats, DevConfig } from '@rsbuild/shared';
|
|
2
|
+
import type { Server } from 'http';
|
|
3
|
+
import ws from '../../../compiled/ws';
|
|
4
|
+
import { type Stats, type DevConfig } from '@rsbuild/shared';
|
|
5
5
|
export default class SocketServer {
|
|
6
6
|
private wsServer;
|
|
7
7
|
private readonly sockets;
|
|
@@ -31,7 +31,7 @@ __export(socketServer_exports, {
|
|
|
31
31
|
default: () => SocketServer
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(socketServer_exports);
|
|
34
|
-
var import_ws = __toESM(require("ws"));
|
|
34
|
+
var import_ws = __toESM(require("../../../compiled/ws"));
|
|
35
35
|
var import_shared = require("@rsbuild/shared");
|
|
36
36
|
class SocketServer {
|
|
37
37
|
constructor(options) {
|
package/dist/server/devServer.js
CHANGED
|
@@ -50,6 +50,7 @@ class RsbuildDevServer {
|
|
|
50
50
|
this.output = options.output;
|
|
51
51
|
this.devMiddleware = new import_dev_middleware.default({
|
|
52
52
|
dev: this.dev,
|
|
53
|
+
publicPaths: options.output.publicPaths,
|
|
53
54
|
devMiddleware: options.devMiddleware
|
|
54
55
|
});
|
|
55
56
|
}
|
|
@@ -116,7 +117,6 @@ class RsbuildDevServer {
|
|
|
116
117
|
this.middlewares.use(
|
|
117
118
|
(0, import_middlewares.getHtmlFallbackMiddleware)({
|
|
118
119
|
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
|
htmlFallback: this.dev.htmlFallback
|
|
122
122
|
})
|
|
@@ -192,14 +192,14 @@ async function startDevServer(options, createDevMiddleware, {
|
|
|
192
192
|
options,
|
|
193
193
|
customCompiler
|
|
194
194
|
);
|
|
195
|
-
const
|
|
195
|
+
const publicPaths = compiler.compilers ? compiler.compilers.map(import_shared.getPublicPathFromCompiler) : [(0, import_shared.getPublicPathFromCompiler)(compiler)];
|
|
196
196
|
const server = new RsbuildDevServer({
|
|
197
197
|
pwd: options.context.rootPath,
|
|
198
198
|
devMiddleware,
|
|
199
199
|
dev: devServerConfig,
|
|
200
200
|
output: {
|
|
201
201
|
distPath: ((_d = (_c = rsbuildConfig.output) == null ? void 0 : _c.distPath) == null ? void 0 : _d.root) || import_shared.ROOT_DIST_DIR,
|
|
202
|
-
|
|
202
|
+
publicPaths
|
|
203
203
|
}
|
|
204
204
|
});
|
|
205
205
|
(0, import_shared.debug)("create dev server done");
|
|
@@ -3,7 +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
|
-
publicPath: string;
|
|
7
6
|
callback?: Middleware;
|
|
8
7
|
htmlFallback?: HtmlFallback;
|
|
9
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 = ({ htmlFallback,
|
|
51
|
+
const getHtmlFallbackMiddleware = ({ htmlFallback, distPath, callback }) => {
|
|
52
52
|
return (req, res, next) => {
|
|
53
53
|
if (
|
|
54
54
|
// Only accept GET or HEAD
|
|
@@ -68,7 +68,6 @@ const getHtmlFallbackMiddleware = ({ htmlFallback, publicPath, distPath, callbac
|
|
|
68
68
|
}
|
|
69
69
|
const rewrite = (newUrl) => {
|
|
70
70
|
var _a;
|
|
71
|
-
newUrl = (0, import_shared.urlJoin)(publicPath, newUrl);
|
|
72
71
|
(_a = import_shared.debug) == null ? void 0 : _a(`Rewriting ${req.method} ${req.url} to ${newUrl}`);
|
|
73
72
|
req.url = newUrl;
|
|
74
73
|
if (callback) {
|
|
@@ -94,10 +93,6 @@ const getHtmlFallbackMiddleware = ({ htmlFallback, publicPath, distPath, callbac
|
|
|
94
93
|
if (outputFileSystem.existsSync(filePath)) {
|
|
95
94
|
return rewrite(newUrl);
|
|
96
95
|
}
|
|
97
|
-
} else {
|
|
98
|
-
if (outputFileSystem.existsSync(import_path.default.join(distPath, pathname))) {
|
|
99
|
-
return rewrite(url);
|
|
100
|
-
}
|
|
101
96
|
}
|
|
102
97
|
if (htmlFallback === "index") {
|
|
103
98
|
if (outputFileSystem.existsSync(import_path.default.join(distPath, "index.html"))) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
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": {
|
|
@@ -63,12 +63,10 @@
|
|
|
63
63
|
"html-webpack-plugin": "npm:html-rspack-plugin@5.5.7",
|
|
64
64
|
"postcss": "8.4.31",
|
|
65
65
|
"semver": "^7.5.4",
|
|
66
|
-
"
|
|
67
|
-
"@rsbuild/shared": "0.1.0"
|
|
66
|
+
"@rsbuild/shared": "0.1.2"
|
|
68
67
|
},
|
|
69
68
|
"devDependencies": {
|
|
70
69
|
"@types/node": "^16",
|
|
71
|
-
"@types/ws": "^8.2.0",
|
|
72
70
|
"@types/semver": "^7.5.4",
|
|
73
71
|
"typescript": "^5.3.0"
|
|
74
72
|
},
|