Skip to content

Commit dd85900

Browse files
authored
refactor: migrate from webpack to rspack (#17)
1 parent e6b76fa commit dd85900

25 files changed

Lines changed: 736 additions & 714 deletions

README.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ bun add -D @rspack/dev-middleware
5151
```js
5252
const middleware = require("@rspack/dev-middleware");
5353
const express = require("express");
54-
const webpack = require("webpack");
54+
const { rspack } = require("@rspack/core");
5555

56-
const compiler = webpack({
56+
const compiler = rspack({
5757
// webpack options
5858
});
5959

@@ -261,12 +261,12 @@ This option also accepts a `Function` value, which can be used to filter which f
261261
The function follows the same premise as [`Array#filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) in which a return value of `false` _will not_ write the file, and a return value of `true` _will_ write the file to disk. eg.
262262

263263
```js
264-
const webpack = require("webpack");
264+
const { rspack } = require("@rspack/core");
265265

266266
const configuration = {
267267
/* Webpack configuration */
268268
};
269-
const compiler = webpack(configuration);
269+
const compiler = rspack(configuration);
270270

271271
middleware(compiler, {
272272
writeToDisk: (filePath) => /superman\.css$/.test(filePath),
@@ -289,12 +289,12 @@ This can be done simply by using `path.join`:
289289
const path = require("node:path");
290290
const mkdirp = require("mkdirp");
291291
const myOutputFileSystem = require("my-fs");
292-
const webpack = require("webpack");
292+
const { rspack } = require("@rspack/core");
293293

294294
myOutputFileSystem.join = path.join.bind(path); // no need to bind
295295
myOutputFileSystem.mkdirp = mkdirp.bind(mkdirp); // no need to bind
296296

297-
const compiler = webpack({
297+
const compiler = rspack({
298298
/* Webpack configuration */
299299
});
300300

@@ -306,12 +306,12 @@ middleware(compiler, { outputFileSystem: myOutputFileSystem });
306306
Allows to set up a callback to change the response data.
307307

308308
```js
309-
const webpack = require("webpack");
309+
const { rspack } = require("@rspack/core");
310310

311311
const configuration = {
312312
/* Webpack configuration */
313313
};
314-
const compiler = webpack(configuration);
314+
const compiler = rspack(configuration);
315315

316316
middleware(compiler, {
317317
// Note - if you send the `Range` header you will have `ReadStream`
@@ -344,9 +344,9 @@ A function executed once the middleware has stopped watching.
344344
```js
345345
const middleware = require("@rspack/dev-middleware");
346346
const express = require("express");
347-
const webpack = require("webpack");
347+
const { rspack } = require("@rspack/core");
348348

349-
const compiler = webpack({
349+
const compiler = rspack({
350350
/* Webpack configuration */
351351
});
352352

@@ -379,9 +379,9 @@ A function executed once the middleware has invalidated.
379379
```js
380380
const middleware = require("@rspack/dev-middleware");
381381
const express = require("express");
382-
const webpack = require("webpack");
382+
const { rspack } = require("@rspack/core");
383383

384-
const compiler = webpack({
384+
const compiler = rspack({
385385
/* Webpack configuration */
386386
});
387387

@@ -419,9 +419,9 @@ If the bundle is valid at the time of calling, the callback is executed immediat
419419
```js
420420
const middleware = require("@rspack/dev-middleware");
421421
const express = require("express");
422-
const webpack = require("webpack");
422+
const { rspack } = require("@rspack/core");
423423

424-
const compiler = webpack({
424+
const compiler = rspack({
425425
/* Webpack configuration */
426426
});
427427

@@ -453,9 +453,9 @@ URL for the requested file.
453453
```js
454454
const middleware = require("@rspack/dev-middleware");
455455
const express = require("express");
456-
const webpack = require("webpack");
456+
const { rspack } = require("@rspack/core");
457457

458-
const compiler = webpack({
458+
const compiler = rspack({
459459
/* Webpack configuration */
460460
});
461461

@@ -484,9 +484,9 @@ But there is a solution to avoid it - mount the middleware to a non-root route,
484484
```js
485485
const middleware = require("@rspack/dev-middleware");
486486
const express = require("express");
487-
const webpack = require("webpack");
487+
const { rspack } = require("@rspack/core");
488488

489-
const compiler = webpack({
489+
const compiler = rspack({
490490
// webpack options
491491
});
492492

@@ -526,9 +526,9 @@ Example Implementation:
526526
const middleware = require("@rspack/dev-middleware");
527527
const express = require("express");
528528
const isObject = require("is-object");
529-
const webpack = require("webpack");
529+
const { rspack } = require("@rspack/core");
530530

531-
const compiler = webpack({
531+
const compiler = rspack({
532532
/* Webpack configuration */
533533
});
534534

@@ -614,10 +614,10 @@ Examples of use with other servers will follow here.
614614
const http = require("node:http");
615615
const devMiddleware = require("@rspack/dev-middleware");
616616
const connect = require("connect");
617-
const webpack = require("webpack");
617+
const { rspack } = require("@rspack/core");
618618
const webpackConfig = require("./webpack.config.js");
619619

620-
const compiler = webpack(webpackConfig);
620+
const compiler = rspack(webpackConfig);
621621
const devMiddlewareOptions = {
622622
// options
623623
};
@@ -635,10 +635,10 @@ const http = require("node:http");
635635
const devMiddleware = require("@rspack/dev-middleware");
636636
const finalhandler = require("finalhandler");
637637
const Router = require("router");
638-
const webpack = require("webpack");
638+
const { rspack } = require("@rspack/core");
639639
const webpackConfig = require("./webpack.config.js");
640640

641-
const compiler = webpack(webpackConfig);
641+
const compiler = rspack(webpackConfig);
642642
const devMiddlewareOptions = {
643643
// options
644644
};
@@ -660,10 +660,10 @@ server.listen(3000);
660660
```js
661661
const devMiddleware = require("@rspack/dev-middleware");
662662
const express = require("express");
663-
const webpack = require("webpack");
663+
const { rspack } = require("@rspack/core");
664664
const webpackConfig = require("./webpack.config.js");
665665

666-
const compiler = webpack(webpackConfig);
666+
const compiler = rspack(webpackConfig);
667667
const devMiddlewareOptions = {
668668
// options
669669
};
@@ -679,10 +679,10 @@ app.listen(3000, () => console.log("Example app listening on port 3000!"));
679679
```js
680680
const middleware = require("@rspack/dev-middleware");
681681
const Koa = require("koa");
682-
const webpack = require("webpack");
682+
const { rspack } = require("@rspack/core");
683683
const webpackConfig = require("./webpack.simple.config");
684684

685-
const compiler = webpack(webpackConfig);
685+
const compiler = rspack(webpackConfig);
686686
const devMiddlewareOptions = {
687687
// options
688688
};
@@ -698,10 +698,10 @@ app.listen(3000);
698698
```js
699699
const Hapi = require("@hapi/hapi");
700700
const devMiddleware = require("@rspack/dev-middleware");
701-
const webpack = require("webpack");
701+
const { rspack } = require("@rspack/core");
702702
const webpackConfig = require("./webpack.config.js");
703703

704-
const compiler = webpack(webpackConfig);
704+
const compiler = rspack(webpackConfig);
705705
const devMiddlewareOptions = {};
706706

707707
const server = Hapi.server({ port: 3000, host: "localhost" });
@@ -732,10 +732,10 @@ Fastify interop will require the use of `fastify-express` instead of `middie` fo
732732
```js
733733
const devMiddleware = require("@rspack/dev-middleware");
734734
const fastify = require("fastify")();
735-
const webpack = require("webpack");
735+
const { rspack } = require("@rspack/core");
736736
const webpackConfig = require("./webpack.config.js");
737737

738-
const compiler = webpack(webpackConfig);
738+
const compiler = rspack(webpackConfig);
739739
const devMiddlewareOptions = {
740740
// options
741741
};
@@ -751,10 +751,10 @@ await fastify.listen(3000);
751751
import { serve } from "@hono/node-server";
752752
import devMiddleware from "@rspack/dev-middleware";
753753
import { Hono } from "hono";
754-
import webpack from "webpack";
754+
import { rspack } from "@rspack/core";
755755
import webpackConfig from "./webpack.config.js";
756756

757-
const compiler = webpack(webpackConfig);
757+
const compiler = rspack(webpackConfig);
758758
const devMiddlewareOptions = {
759759
// options
760760
};

jest.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ module.exports = {
66
testMatch: ["**/test/**/*.test.js"],
77
setupFilesAfterEnv: ["<rootDir>/setupTest.js"],
88
globalSetup: "<rootDir>/scripts/globalSetup.js",
9-
snapshotResolver: "./test/helpers/snapshotResolver.js",
109
};

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"range-parser": "^1.2.1"
5050
},
5151
"devDependencies": {
52+
"@rspack/core": "2.0.0-beta.5",
5253
"@babel/cli": "^7.16.7",
5354
"@babel/core": "^7.16.7",
5455
"@babel/preset-env": "^7.16.7",
@@ -79,14 +80,13 @@
7980
"prettier": "^3.6.0",
8081
"router": "^2.2.0",
8182
"supertest": "^7.0.0",
82-
"typescript": "^5.3.3",
83-
"webpack": "^5.101.0"
83+
"typescript": "^5.3.3"
8484
},
8585
"peerDependencies": {
86-
"webpack": "^5.0.0"
86+
"@rspack/core": "^2.0.0-0"
8787
},
8888
"peerDependenciesMeta": {
89-
"webpack": {
89+
"@rspack/core": {
9090
"optional": true
9191
}
9292
},

0 commit comments

Comments
 (0)