1111[ ![ discussion] [ discussion ]] [ discussion-url ]
1212[ ![ size] [ size ]] [ size-url ]
1313
14- # webpack-dev-middleware
14+ # @rspack/dev-middleware
15+
16+ An express-style development middleware for use with [ Rspack] ( https://rspack.rs ) and webpack-compatible compilers. It serves the files emitted by the compiler from memory.
1517
16- An express-style development middleware for use with [ webpack] ( https://webpack.js.org )
17- bundles and allows for serving of the files emitted from webpack.
1818This should be used for ** development only** .
1919
2020Some of the benefits of using this middleware include:
@@ -29,7 +29,7 @@ Some of the benefits of using this middleware include:
2929First thing's first, install the module:
3030
3131``` console
32- npm install webpack- dev-middleware --save-dev
32+ npm install @rspack/ dev-middleware -D
3333```
3434
3535> [ !WARNING]
@@ -41,7 +41,7 @@ npm install webpack-dev-middleware --save-dev
4141``` js
4242const express = require (" express" );
4343const webpack = require (" webpack" );
44- const middleware = require (" webpack- dev-middleware" );
44+ const middleware = require (" @rspack/ dev-middleware" );
4545
4646const compiler = webpack ({
4747 // webpack options
@@ -51,7 +51,7 @@ const app = express();
5151
5252app .use (
5353 middleware (compiler, {
54- // webpack-dev-middleware options
54+ // options
5555 }),
5656);
5757
@@ -100,7 +100,7 @@ eg. `{ "X-Custom-Header": "yes" }`
100100or
101101
102102``` js
103- webpackDevMiddleware (compiler, {
103+ middleware (compiler, {
104104 headers : () => ({
105105 " Last-Modified" : new Date (),
106106 }),
@@ -110,7 +110,7 @@ webpackDevMiddleware(compiler, {
110110or
111111
112112``` js
113- webpackDevMiddleware (compiler, {
113+ middleware (compiler, {
114114 headers : (req , res , context ) => {
115115 res .setHeader (" Last-Modified" , new Date ());
116116 },
@@ -120,7 +120,7 @@ webpackDevMiddleware(compiler, {
120120or
121121
122122``` js
123- webpackDevMiddleware (compiler, {
123+ middleware (compiler, {
124124 headers: [
125125 {
126126 key: " X-custom-header" ,
@@ -137,7 +137,7 @@ webpackDevMiddleware(compiler, {
137137or
138138
139139``` js
140- webpackDevMiddleware (compiler, {
140+ middleware (compiler, {
141141 headers : () => [
142142 {
143143 key: " X-custom-header" ,
@@ -242,7 +242,9 @@ Type: `Boolean|Function`
242242Default: ` false `
243243
244244If ` true ` , the option will instruct the module to write files to the configured location on disk as specified in your ` webpack ` config file.
245- _ Setting ` writeToDisk: true ` won't change the behavior of the ` webpack-dev-middleware ` , and bundle files accessed through the browser will still be served from memory._
245+
246+ _ Setting ` writeToDisk: true ` won't change the behavior of ` @rspack/dev-middleware ` , and bundle files accessed through the browser will still be served from memory._
247+
246248This option provides the same capabilities as the [ ` WriteFilePlugin ` ] ( https://github.com/gajus/write-file-webpack-plugin/pulls ) .
247249
248250This option also accepts a ` Function ` value, which can be used to filter which files are written to disk.
@@ -313,12 +315,12 @@ middleware(compiler, {
313315
314316## API
315317
316- ` webpack- dev-middleware` also provides convenience methods that can be use to
318+ ` @rspack/ dev-middleware` also provides convenience methods that can be use to
317319interact with the middleware at runtime:
318320
319321### ` close(callback) `
320322
321- Instructs ` webpack- dev-middleware` instance to stop watching for file changes.
323+ Instructs the ` @rspack/ dev-middleware` instance to stop watching for file changes.
322324
323325#### Parameters
324326
@@ -337,7 +339,7 @@ const compiler = webpack({
337339 /* Webpack configuration */
338340});
339341
340- const middleware = require (" webpack- dev-middleware" );
342+ const middleware = require (" @rspack/ dev-middleware" );
341343
342344const instance = middleware (compiler);
343345
@@ -354,7 +356,7 @@ setTimeout(() => {
354356
355357### ` invalidate(callback) `
356358
357- Instructs ` webpack- dev-middleware` instance to recompile the bundle, e.g. after a change to the configuration.
359+ Instructs the ` @rspack/ dev-middleware` instance to recompile the bundle, e.g. after a change to the configuration.
358360
359361#### Parameters
360362
@@ -373,7 +375,7 @@ const compiler = webpack({
373375 /* Webpack configuration */
374376});
375377
376- const middleware = require (" webpack- dev-middleware" );
378+ const middleware = require (" @rspack/ dev-middleware" );
377379
378380const instance = middleware (compiler);
379381
@@ -414,7 +416,7 @@ const compiler = webpack({
414416 /* Webpack configuration */
415417});
416418
417- const middleware = require (" webpack- dev-middleware" );
419+ const middleware = require (" @rspack/ dev-middleware" );
418420
419421const instance = middleware (compiler);
420422
@@ -449,7 +451,7 @@ const compiler = webpack({
449451 /* Webpack configuration */
450452});
451453
452- const middleware = require (" webpack- dev-middleware" );
454+ const middleware = require (" @rspack/ dev-middleware" );
453455
454456const instance = middleware (compiler);
455457
@@ -476,7 +478,7 @@ But there is a solution to avoid it - mount the middleware to a non-root route,
476478``` js
477479const express = require (" express" );
478480const webpack = require (" webpack" );
479- const middleware = require (" webpack- dev-middleware" );
481+ const middleware = require (" @rspack/ dev-middleware" );
480482
481483const compiler = webpack ({
482484 // webpack options
@@ -489,7 +491,7 @@ const app = express();
489491app .use (
490492 " /dist/" ,
491493 middleware (compiler, {
492- // webpack- dev-middleware options
494+ // @rspack/ dev-middleware options
493495 }),
494496);
495497
@@ -504,12 +506,12 @@ In order to develop an app using server-side rendering, we need access to the
504506[ ` stats ` ] ( https://github.com/webpack/docs/wiki/node.js-api#stats ) , which is
505507generated with each build.
506508
507- With server-side rendering enabled, ` webpack- dev-middleware` sets the ` stats ` to ` res.locals.webpack.devMiddleware.stats `
509+ With server-side rendering enabled, ` @rspack/ dev-middleware` sets the ` stats ` to ` res.locals.webpack.devMiddleware.stats `
508510and the filesystem to ` res.locals.webpack.devMiddleware.outputFileSystem ` before invoking the next middleware,
509511allowing a developer to render the page body and manage the response to clients.
510512
511513_ Note: Requests for bundle files will still be handled by
512- ` webpack- dev-middleware` and all requests will be pending until the build
514+ ` @rspack/ dev-middleware` and all requests will be pending until the build
513515process is finished with server-side rendering enabled._
514516
515517Example Implementation:
@@ -518,7 +520,7 @@ Example Implementation:
518520const express = require (" express" );
519521const isObject = require (" is-object" );
520522const webpack = require (" webpack" );
521- const middleware = require (" webpack- dev-middleware" );
523+ const middleware = require (" @rspack/ dev-middleware" );
522524
523525const compiler = webpack ({
524526 /* Webpack configuration */
@@ -606,12 +608,12 @@ Examples of use with other servers will follow here.
606608const http = require (" node:http" );
607609const connect = require (" connect" );
608610const webpack = require (" webpack" );
609- const devMiddleware = require (" webpack- dev-middleware" );
611+ const devMiddleware = require (" @rspack/ dev-middleware" );
610612const webpackConfig = require (" ./webpack.config.js" );
611613
612614const compiler = webpack (webpackConfig);
613615const devMiddlewareOptions = {
614- /** Your webpack-dev-middleware- options */
616+ // options
615617};
616618const app = connect ();
617619
@@ -627,12 +629,12 @@ const http = require("node:http");
627629const finalhandler = require (" finalhandler" );
628630const Router = require (" router" );
629631const webpack = require (" webpack" );
630- const devMiddleware = require (" webpack- dev-middleware" );
632+ const devMiddleware = require (" @rspack/ dev-middleware" );
631633const webpackConfig = require (" ./webpack.config.js" );
632634
633635const compiler = webpack (webpackConfig);
634636const devMiddlewareOptions = {
635- /** Your webpack-dev-middleware- options */
637+ // options
636638};
637639
638640// eslint-disable-next-line new-cap
@@ -652,12 +654,12 @@ server.listen(3000);
652654``` js
653655const express = require (" express" );
654656const webpack = require (" webpack" );
655- const devMiddleware = require (" webpack- dev-middleware" );
657+ const devMiddleware = require (" @rspack/ dev-middleware" );
656658const webpackConfig = require (" ./webpack.config.js" );
657659
658660const compiler = webpack (webpackConfig);
659661const devMiddlewareOptions = {
660- /** Your webpack-dev-middleware- options */
662+ // options
661663};
662664const app = express ();
663665
@@ -671,12 +673,12 @@ app.listen(3000, () => console.log("Example app listening on port 3000!"));
671673``` js
672674const Koa = require (" koa" );
673675const webpack = require (" webpack" );
674- const middleware = require (" webpack- dev-middleware" );
676+ const middleware = require (" @rspack/ dev-middleware" );
675677const webpackConfig = require (" ./webpack.simple.config" );
676678
677679const compiler = webpack (webpackConfig);
678680const devMiddlewareOptions = {
679- /** Your webpack-dev-middleware- options */
681+ // options
680682};
681683const app = new Koa ();
682684
@@ -690,7 +692,7 @@ app.listen(3000);
690692``` js
691693const Hapi = require (" @hapi/hapi" );
692694const webpack = require (" webpack" );
693- const devMiddleware = require (" webpack- dev-middleware" );
695+ const devMiddleware = require (" @rspack/ dev-middleware" );
694696const webpackConfig = require (" ./webpack.config.js" );
695697
696698const compiler = webpack (webpackConfig);
@@ -699,7 +701,7 @@ const devMiddlewareOptions = {};
699701const server = Hapi .server ({ port: 3000 , host: " localhost" });
700702
701703await server .register ({
702- plugin: devMiddleware .hapiPlugin (),
704+ plugin: devMiddleware .hapiWrapper (),
703705 options: {
704706 // The `compiler` option is required
705707 compiler,
@@ -724,12 +726,12 @@ Fastify interop will require the use of `fastify-express` instead of `middie` fo
724726``` js
725727const fastify = require (" fastify" )();
726728const webpack = require (" webpack" );
727- const devMiddleware = require (" webpack- dev-middleware" );
729+ const devMiddleware = require (" @rspack/ dev-middleware" );
728730const webpackConfig = require (" ./webpack.config.js" );
729731
730732const compiler = webpack (webpackConfig);
731733const devMiddlewareOptions = {
732- /** Your webpack-dev-middleware- options */
734+ // options
733735};
734736
735737await fastify .register (require (" @fastify/express" ));
@@ -743,12 +745,12 @@ await fastify.listen(3000);
743745import { serve } from " @hono/node-server" ;
744746import { Hono } from " hono" ;
745747import webpack from " webpack" ;
746- import devMiddleware from " webpack- dev-middleware" ;
748+ import devMiddleware from " @rspack/ dev-middleware" ;
747749import webpackConfig from " ./webpack.config.js" ;
748750
749751const compiler = webpack (webpackConfig);
750752const devMiddlewareOptions = {
751- /** Your webpack-dev-middleware- options */
753+ // options
752754};
753755
754756const app = new Hono ();
@@ -762,27 +764,27 @@ serve(app);
762764
763765Please take a moment to read our contributing guidelines if you haven't yet done so.
764766
765- [ CONTRIBUTING] ( https://github.com/webpack/sass-loader?tab=contributing-ov-file#contributing )
767+ [ CONTRIBUTING] ( ./CONTRIBUTING.md )
766768
767769## License
768770
769771[ MIT] ( ./LICENSE )
770772
771- [ npm ] : https://img.shields.io/npm/v/webpack-dev -middleware.svg
772- [ npm-url ] : https://npmjs.com/package/webpack- dev-middleware
773- [ node ] : https://img.shields.io/node/v/webpack-dev -middleware.svg
773+ [ npm ] : https://img.shields.io/npm/v/%40rspack%2Fdev -middleware.svg
774+ [ npm-url ] : https://www. npmjs.com/package/@rspack/ dev-middleware
775+ [ node ] : https://img.shields.io/node/v/%40rspack%2Fdev -middleware.svg
774776[ node-url ] : https://nodejs.org
775- [ tests ] : https://github.com/webpack/webpack -dev-middleware/workflows/webpack-dev-middleware /badge.svg
776- [ tests-url ] : https://github.com/webpack/webpack -dev-middleware/actions
777- [ cover ] : https://codecov.io/gh/webpack/webpack -dev-middleware/branch/main/graph/badge.svg
778- [ cover-url ] : https://codecov.io/gh/webpack/webpack -dev-middleware
777+ [ tests ] : https://github.com/rstackjs/rspack -dev-middleware/actions/ workflows/test.yml /badge.svg
778+ [ tests-url ] : https://github.com/rstackjs/rspack -dev-middleware/actions
779+ [ cover ] : https://codecov.io/gh/rstackjs/rspack -dev-middleware/branch/main/graph/badge.svg
780+ [ cover-url ] : https://codecov.io/gh/rstackjs/rspack -dev-middleware
779781[ discussion ] : https://img.shields.io/github/discussions/webpack/webpack
780782[ discussion-url ] : https://github.com/webpack/webpack/discussions
781- [ size ] : https://packagephobia.com/badge?p=webpack-dev -middleware
782- [ size-url ] : https://packagephobia.com/result?p=webpack-dev -middleware
783- [ docs-url ] : https://webpack.js.org/guides/development/#using-webpack- dev-middleware
783+ [ size ] : https://packagephobia.com/badge?p=%40rspack%2Fdev -middleware
784+ [ size-url ] : https://packagephobia.com/result?p=%40rspack%2Fdev -middleware
785+ [ docs-url ] : https://github.com/rstackjs/rspack- dev-middleware#readme
784786[ hash-url ] : https://twitter.com/search?q=webpack
785- [ middleware-url ] : https://github.com/webpack/webpack -dev-middleware
786- [ stack-url ] : https://stackoverflow.com/questions/tagged/webpack -dev-middleware
787+ [ middleware-url ] : https://github.com/rstackjs/rspack -dev-middleware
788+ [ stack-url ] : https://stackoverflow.com/questions/tagged/rspack -dev-middleware
787789[ chat-url ] : https://github.com/webpack/webpack/discussions
788790[ wjo-url ] : https://github.com/webpack/webpack.js.org
0 commit comments