{"name":"@rspack/dev-middleware","version":"2.0.0","keywords":["rspack","middleware","development"],"author":{"name":"Tobias Koppers @sokra"},"license":"MIT","_id":"@rspack/dev-middleware@2.0.0","maintainers":[{"name":"hardfist","email":"1562502418@qq.com"},{"name":"chenjiahan","email":"416417567@163.com"}],"homepage":"https://github.com/rstackjs/rspack-dev-middleware","bugs":{"url":"https://github.com/rstackjs/rspack-dev-middleware/issues"},"dist":{"shasum":"b5462710ce7e82f12f10e08f3e6b94963bb0fb9a","tarball":"http://registry-npm.ywwl.com/@rspack/dev-middleware/download/@rspack/dev-middleware-2.0.0.tgz","fileCount":19,"integrity":"sha512-XYyUgvdNV6Fiom6fYNibvLtg9EbqMvgdpnx2CaO4RacDe0yEIYJgAFAdKjWoqKH+3GhPTRI1xqjtR2XlssBThw==","signatures":[{"sig":"MEUCIFeEfgY66pvxc7W1Iy/tD//ftpUsy2k7fWhQF80NTWUXAiEA185br6UvZmOwUBMMRMjMbwErIIx/Q0R5kI6ViZFNFAY=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@rspack%2fdev-middleware@2.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":487705,"size":76915,"noattachment":false,"key":"/@rspack/dev-middleware/-/@rspack/dev-middleware-2.0.0.tgz"},"main":"dist/index.js","type":"module","types":"types/index.d.ts","engines":{"node":"^20.19.0 || >=22.12.0"},"gitHead":"566722817dc6203d09183aa6bad52a0b706e6699","scripts":{"bump":"npx bumpp","lint":"npm-run-all -l -p \"lint:**\"","test":"rstest","build":"rslib --syntax es2023 && pnpm run build:types","prepare":"pnpm run build","lint:types":"tsc --pretty --noEmit","test:watch":"rstest -w","build:types":"tsc --declaration --emitDeclarationOnly --outDir types && prettier \"types/**/*.ts\" --write","lint:rslint":"rslint","lint:prettier":"prettier --cache --list-different .","lint:spelling":"cspell --cache --no-must-find-files --quiet \"**/*.*\""},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:edc00837-916c-445f-8133-6748e52c5e39"}},"repository":{"url":"git+https://github.com/rstackjs/rspack-dev-middleware.git","type":"git"},"_npmVersion":"11.9.0","description":"A development middleware for Rspack","directories":{},"_nodeVersion":"24.14.0","_hasShrinkwrap":false,"packageManager":"pnpm@10.21.0","devDependencies":{"koa":"^3.0.0","hono":"^4.4.13","execa":"^5.1.1","memfs":"^4.43.1","cspell":"^9.6.2","mrmime":"^2.0.1","router":"^2.2.0","express":"^5.1.0","prettier":"^3.6.0","deepmerge":"^4.2.2","supertest":"^7.0.0","@hapi/hapi":"^21.3.7","typescript":"^6.0.2","@rslib/core":"^0.20.0","@types/node":"^22.3.0","npm-run-all":"^4.1.5","on-finished":"^2.4.1","@rslint/core":"^0.3.3","@rspack/core":"2.0.0-beta.5","@rstest/core":"0.9.2","connect-next":"^4.0.0","finalhandler":"^2.1.0","range-parser":"^1.2.1","@types/express":"^5.0.2","@hono/node-server":"^1.12.0","@types/on-finished":"^2.3.4","@types/range-parser":"^1.2.7"},"peerDependencies":{"@rspack/core":"^2.0.0-0"},"peerDependenciesMeta":{"@rspack/core":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/dev-middleware_2.0.0_1774939904874_0.5470414939108263","host":"s3://npm-registry-packages-npm-production"},"readme":"# @rspack/dev-middleware\n\n<p>\n  <a href=\"https://npmjs.com/package/@rspack/dev-middleware?activeTab=readme\"><img src=\"https://img.shields.io/npm/v/@rspack/dev-middleware?style=flat-square&colorA=564341&colorB=EDED91\" alt=\"npm version\" /></a>\n  <a href=\"https://npmcharts.com/compare/@rspack/dev-middleware?minimal=true\"><img src=\"https://img.shields.io/npm/dm/@rspack/dev-middleware.svg?style=flat-square&colorA=564341&colorB=EDED91\" alt=\"downloads\" /></a>\n  <a href=\"https://nodejs.org/en/about/previous-releases\"><img src=\"https://img.shields.io/node/v/@rspack/dev-middleware.svg?style=flat-square&colorA=564341&colorB=EDED91\" alt=\"node version\"></a>\n  <a href=\"https://github.com/rstackjs/rspack-dev-middleware/blob/main/LICENSE\"><img src=\"https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91\" alt=\"license\" /></a>\n</p>\n\nAn express-style development middleware for use with [Rspack](https://rspack.rs). It serves the files emitted by the compiler from memory.\n\nThis should be used for **development only**.\n\nSome of the benefits of using this middleware include:\n\n- No files are written to disk, rather it handles files in memory\n- If files changed in watch mode, the middleware delays requests until compiling\n  has completed.\n- Supports hot module reload (HMR).\n\n## Getting Started\n\nInstall the module:\n\n```bash\n# npm\nnpm install @rspack/dev-middleware -D\n\n# pnpm\npnpm add -D @rspack/dev-middleware\n\n# yarn\nyarn add -D @rspack/dev-middleware\n\n# bun\nbun add -D @rspack/dev-middleware\n```\n\n## Usage\n\n```js\nimport { rspack } from \"@rspack/core\";\nimport { devMiddleware } from \"@rspack/dev-middleware\";\nimport express from \"express\";\n\nconst compiler = rspack({\n  // Rspack options\n});\n\nconst app = express();\n\napp.use(\n  devMiddleware(compiler, {\n    // options\n  }),\n);\n\napp.listen(3000, () => console.log(\"Example app listening on port 3000!\"));\n```\n\nSee [below](#other-servers) for examples of use with other servers.\n\n## Options\n\n|                      Name                       |               Type                |                    Default                    | Description                                                                                                          |\n| :---------------------------------------------: | :-------------------------------: | :-------------------------------------------: | :------------------------------------------------------------------------------------------------------------------- |\n|            **[`methods`](#methods)**            |              `Array`              |              `[ 'GET', 'HEAD' ]`              | Allows to pass the list of HTTP request methods accepted by the middleware                                           |\n|            **[`headers`](#headers)**            |     `Array\\|Object\\|Function`     |                  `undefined`                  | Allows to pass custom HTTP headers on each request.                                                                  |\n|              **[`index`](#index)**              |         `boolean\\|string`         |                 `index.html`                  | If `false` (but not `undefined`), the server will not respond to requests to the root URL.                           |\n|          **[`mimeTypes`](#mimetypes)**          |             `Object`              |                  `undefined`                  | Allows to register custom mime types or extension mappings.                                                          |\n|    **[`mimeTypeDefault`](#mimetypedefault)**    |             `string`              |                  `undefined`                  | Allows to register a default mime type when we can't determine the content type.                                     |\n|               **[`etag`](#tag)**                |   `boolean\\| \"weak\"\\| \"strong\"`   |                  `undefined`                  | Enable or disable etag generation.                                                                                   |\n|       **[`lastModified`](#lastmodified)**       |             `boolean`             |                  `undefined`                  | Enable or disable `Last-Modified` header. Uses the file system's last modified value.                                |\n|       **[`cacheControl`](#cachecontrol)**       | `boolean\\|number\\|string\\|Object` |                  `undefined`                  | Enable or disable setting `Cache-Control` response header.                                                           |\n|     **[`cacheImmutable`](#cacheimmutable)**     |             `boolean`             |                    `false`                    | Enable or disable setting `Cache-Control: public, max-age=31536000, immutable` response header for immutable assets. |\n|         **[`publicPath`](#publicpath)**         |             `string`              |                  `undefined`                  | The public path that the middleware is bound to.                                                                     |\n|              **[`stats`](#stats)**              |     `boolean\\|string\\|Object`     |        `stats` (from a configuration)         | Stats options object or preset name.                                                                                 |\n|   **[`serverSideRender`](#serversiderender)**   |             `boolean`             |                  `undefined`                  | Instructs the module to enable or disable the server-side rendering mode.                                            |\n|        **[`writeToDisk`](#writetodisk)**        |        `boolean\\|Function`        |                    `false`                    | Instructs the module to write files to the configured location on disk as specified in your Rspack configuration.    |\n|   **[`outputFileSystem`](#outputfilesystem)**   |             `Object`              | [`memfs`](https://github.com/streamich/memfs) | Set the default file system which will be used by Rspack as primary destination of generated files.                  |\n| **[`modifyResponseData`](#modifyresponsedata)** |            `Function`             |                  `undefined`                  | Allows to set up a callback to change the response data.                                                             |\n\nThe middleware accepts an `options` Object. The following is a property reference for the Object.\n\n### methods\n\nType: `Array`  \nDefault: `[ 'GET', 'HEAD' ]`\n\nThis property allows a user to pass the list of HTTP request methods accepted by the middleware\\*\\*.\n\n### headers\n\nType: `Array|Object|Function`\nDefault: `undefined`\n\nThis property allows a user to pass custom HTTP headers on each request.\neg. `{ \"X-Custom-Header\": \"yes\" }`\n\nor\n\n```js\ndevMiddleware(compiler, {\n  headers: () => ({\n    \"Last-Modified\": new Date(),\n  }),\n});\n```\n\nor\n\n```js\ndevMiddleware(compiler, {\n  headers: (req, res, context) => {\n    res.setHeader(\"Last-Modified\", new Date());\n  },\n});\n```\n\nor\n\n```js\ndevMiddleware(compiler, {\n  headers: [\n    {\n      key: \"X-custom-header\",\n      value: \"foo\",\n    },\n    {\n      key: \"Y-custom-header\",\n      value: \"bar\",\n    },\n  ],\n});\n```\n\nor\n\n```js\ndevMiddleware(compiler, {\n  headers: () => [\n    {\n      key: \"X-custom-header\",\n      value: \"foo\",\n    },\n    {\n      key: \"Y-custom-header\",\n      value: \"bar\",\n    },\n  ],\n});\n```\n\n### index\n\nType: `Boolean|String`\nDefault: `index.html`\n\nIf `false` (but not `undefined`), the server will not respond to requests to the root URL.\n\n### mimeTypes\n\nType: `Object`  \nDefault: `undefined`\n\nThis property allows a user to register custom mime types or extension mappings.\neg. `mimeTypes: { phtml: 'text/html' }`.\n\nPlease see the documentation for [`mrmime`](https://github.com/lukeed/mrmime) for more information.\n\n### mimeTypeDefault\n\nType: `String`  \nDefault: `undefined`\n\nThis property allows a user to register a default mime type when we can't determine the content type.\n\n### etag\n\nType: `\"weak\" | \"strong\"`  \nDefault: `undefined`\n\nEnable or disable etag generation. Boolean value use\n\n### lastModified\n\nType: `Boolean`\nDefault: `undefined`\n\nEnable or disable `Last-Modified` header. Uses the file system's last modified value.\n\n### cacheControl\n\nType: `Boolean | Number | String | { maxAge?: number, immutable?: boolean }`\nDefault: `undefined`\n\nDepending on the setting, the following headers will be generated:\n\n- `Boolean` - `Cache-Control: public, max-age=31536000`\n- `Number` - `Cache-Control: public, max-age=YOUR_NUMBER_IN_SECONDS`\n- `String` - `Cache-Control: YOUR_STRING`\n- `{ maxAge?: number, immutable?: boolean }` - `Cache-Control: public, max-age=YOUR_MAX_AGE_IN_SECONDS_or_31536000`, also `, immutable` is added when you set the `immutable` option to `true`\n\nNumeric `cacheControl` and `cacheControl.maxAge` values are interpreted as milliseconds, clamped to `0..31536000000`, and converted to seconds for the response header.\n\nEnable or disable setting `Cache-Control` response header.\n\n### cacheImmutable\n\nType: `Boolean`\nDefault: `false`\n\nEnable or disable setting `Cache-Control: public, max-age=31536000, immutable` response header for immutable assets (i.e. asset with a hash like `image.a4c12bde.jpg`).\n\nImmutable assets are assets that have their hash in the file name therefore they can be cached, because if you change their contents the file name will be changed.\n\nWhen omitted, immutable assets fall back to the `cacheControl` option.\n\nSet `cacheImmutable: true` to opt into the immutable cache header for hashed assets.\nThis takes precedence over the `cacheControl` option only when the asset was defined as immutable and `cacheImmutable` is `true`.\n\n### publicPath\n\nType: `String`\nDefault: `output.publicPath` (from a configuration)\n\nThe public path that the middleware is bound to.\n\n> Best Practice: use the same `publicPath` defined in your Rspack config.\n\n### stats\n\nType: `Boolean|String|Object`\nDefault: `stats` (from a configuration)\n\nStats options object or preset name.\n\n### serverSideRender\n\nType: `Boolean`  \nDefault: `undefined`\n\nInstructs the module to enable or disable the server-side rendering mode.\nPlease see [Server-Side Rendering](#server-side-rendering) for more information.\n\n### writeToDisk\n\nType: `Boolean|Function`  \nDefault: `false`\n\nIf `true`, the option will instruct the module to write files to the configured location on disk as specified in your Rspack config file.\n\n_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._\n\nThis option also accepts a `Function` value, which can be used to filter which files are written to disk.\nThe 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.\n\n```js\nimport { rspack } from \"@rspack/core\";\n\nconst configuration = {/* Rspack configuration */};\nconst compiler = rspack(configuration);\n\ndevMiddleware(compiler, {\n  writeToDisk: (filePath) => /superman\\.css$/.test(filePath),\n});\n```\n\n### outputFileSystem\n\nType: `Object`  \nDefault: [memfs](https://github.com/streamich/memfs)\n\nSet the default file system which will be used by Rspack as primary destination of generated files.\nThis option isn't affected by the [writeToDisk](#writeToDisk) option.\n\nThis can be done simply by using `node:path`'s `join`:\n\n```js\nimport { join } from \"node:path\";\nimport { rspack } from \"@rspack/core\";\nimport mkdirp from \"mkdirp\";\nimport myOutputFileSystem from \"my-fs\";\n\nmyOutputFileSystem.join = join;\nmyOutputFileSystem.mkdirp = mkdirp;\n\nconst compiler = rspack({/* Rspack configuration */});\n\ndevMiddleware(compiler, { outputFileSystem: myOutputFileSystem });\n```\n\n### modifyResponseData\n\nAllows to set up a callback to change the response data.\n\n```js\nimport { rspack } from \"@rspack/core\";\n\nconst configuration = {/* Rspack configuration */};\nconst compiler = rspack(configuration);\n\ndevMiddleware(compiler, {\n  // Note - if you send the `Range` header you will have `ReadStream`\n  // Also `data` can be `string` or `Buffer`\n  modifyResponseData: (req, res, data, byteLength) =>\n    // Your logic\n    // Don't use `res.end()` or `res.send()` here\n    ({ data, byteLength }),\n});\n```\n\n## API\n\n`@rspack/dev-middleware` also provides convenience methods that can be use to\ninteract with the middleware at runtime:\n\n### `close(callback)`\n\nInstructs the `@rspack/dev-middleware` instance to stop watching for file changes.\n\n#### Parameters\n\n##### `callback`\n\nType: `Function`\nRequired: `No`\n\nA function executed once the middleware has stopped watching.\n\n```js\nimport { rspack } from \"@rspack/core\";\nimport { devMiddleware } from \"@rspack/dev-middleware\";\nimport express from \"express\";\n\nconst compiler = rspack({/* Rspack configuration */});\n\nconst instance = devMiddleware(compiler);\n\nconst app = express();\n\napp.use(instance);\n\nsetTimeout(() => {\n  // Says Rspack to stop watch changes\n  instance.close();\n}, 1000);\n```\n\n### `invalidate(callback)`\n\nInstructs the `@rspack/dev-middleware` instance to recompile the bundle, e.g. after a change to the configuration.\n\n#### Parameters\n\n##### `callback`\n\nType: `Function`\nRequired: `No`\n\nA function executed once the middleware has invalidated.\n\n```js\nimport { rspack } from \"@rspack/core\";\nimport { devMiddleware } from \"@rspack/dev-middleware\";\nimport express from \"express\";\n\nconst compiler = rspack({/* Rspack configuration */});\n\nconst instance = devMiddleware(compiler);\n\nconst app = express();\n\napp.use(instance);\n\nsetTimeout(() => {\n  // After a short delay the configuration is changed and a banner plugin is added to the config\n  new rspack.BannerPlugin(\"A new banner\").apply(compiler);\n\n  // Recompile the bundle with the banner plugin:\n  instance.invalidate();\n}, 1000);\n```\n\n### `waitUntilValid(callback)`\n\nExecutes a callback function when the compiler bundle is valid, typically after\ncompilation.\n\n#### Parameters\n\n##### `callback`\n\nType: `Function`\nRequired: `No`\n\nA function executed when the bundle becomes valid.\nIf the bundle is valid at the time of calling, the callback is executed immediately.\n\n```js\nimport { rspack } from \"@rspack/core\";\nimport { devMiddleware } from \"@rspack/dev-middleware\";\nimport express from \"express\";\n\nconst compiler = rspack({/* Rspack configuration */});\n\nconst instance = devMiddleware(compiler);\n\nconst app = express();\n\napp.use(instance);\n\ninstance.waitUntilValid(() => {\n  console.log(\"Package is in a valid state\");\n});\n```\n\n### `getFilenameFromUrl(url)`\n\nGet filename from URL.\n\n#### Parameters\n\n##### `url`\n\nType: `String`\nRequired: `Yes`\n\nURL for the requested file.\n\n```js\nimport { rspack } from \"@rspack/core\";\nimport { devMiddleware } from \"@rspack/dev-middleware\";\nimport express from \"express\";\n\nconst compiler = rspack({/* Rspack configuration */});\n\nconst instance = devMiddleware(compiler);\n\nconst app = express();\n\napp.use(instance);\n\ninstance.waitUntilValid(() => {\n  let resolved;\n\n  try {\n    resolved = instance.getFilenameFromUrl(\"/bundle.js\");\n  } catch (error) {\n    console.error(error);\n    return;\n  }\n\n  if (!resolved) {\n    console.log(\"Not found\");\n    return;\n  }\n\n  console.log(`Filename is ${resolved.filename}`);\n});\n```\n\n## FAQ\n\n### Avoid blocking requests to non-Rspack resources.\n\nSince `output.publicPath` and `output.filename`/`output.chunkFilename` can be dynamic, it's not possible to know which files are Rspack bundles (and they public paths) and which are not, so we can't avoid blocking requests.\n\nBut there is a solution to avoid it - mount the middleware to a non-root route, for example:\n\n```js\nimport { rspack } from \"@rspack/core\";\nimport { devMiddleware } from \"@rspack/dev-middleware\";\nimport express from \"express\";\n\nconst compiler = rspack({\n  // Rspack options\n});\n\nconst app = express();\n\n// Mounting the middleware to the non-root route allows avoids this.\n// Note - check your public path, if you want to handle `/dist/`, you need to setup `output.publicPath` to `/` value.\napp.use(\n  \"/dist/\",\n  devMiddleware(compiler, {\n    // @rspack/dev-middleware options\n  }),\n);\n\napp.listen(3000, () => console.log(\"Example app listening on port 3000!\"));\n```\n\n## Server-Side Rendering\n\n_Note: this feature is experimental and may be removed or changed completely in the future._\n\nIn order to develop an app using server-side rendering, we need access to the\n[`stats`](https://rspack.rs/api/javascript-api/stats), which is\ngenerated with each build.\n\nWith server-side rendering enabled, `@rspack/dev-middleware` sets the `stats` to `res.locals.rspack.devMiddleware.stats`\nand the filesystem to `res.locals.rspack.devMiddleware.outputFileSystem` before invoking the next middleware,\nallowing a developer to render the page body and manage the response to clients.\n\n_Note: Requests for bundle files will still be handled by\n`@rspack/dev-middleware` and all requests will be pending until the build\nprocess is finished with server-side rendering enabled._\n\nExample Implementation:\n\n```js\nimport { join } from \"node:path\";\nimport { rspack } from \"@rspack/core\";\nimport { devMiddleware } from \"@rspack/dev-middleware\";\nimport express from \"express\";\nimport isObject from \"is-object\";\n\nconst compiler = rspack({/* Rspack configuration */});\n\nconst app = express();\n\n// This function makes server rendering of asset references consistent with different Rspack chunk/entry configurations\nfunction normalizeAssets(assets) {\n  if (isObject(assets)) {\n    return Object.values(assets);\n  }\n\n  return Array.isArray(assets) ? assets : [assets];\n}\n\napp.use(devMiddleware(compiler, { serverSideRender: true }));\n\n// The following middleware would not be invoked until the latest build is finished.\napp.use((req, res) => {\n  const { devMiddleware } = res.locals.rspack;\n  const { outputFileSystem } = devMiddleware;\n  const jsonStats = devMiddleware.stats.toJson();\n  const { assetsByChunkName, outputPath } = jsonStats;\n\n  // Then use `assetsByChunkName` for server-side rendering\n  // For example, if you have only one main chunk:\n  res.send(`\n<html>\n  <head>\n    <title>My App</title>\n    <style>\n    ${normalizeAssets(assetsByChunkName.main)\n      .filter((asset) => asset.endsWith(\".css\"))\n      .map((asset) => outputFileSystem.readFileSync(join(outputPath, asset)))\n      .join(\"\\n\")}\n    </style>\n  </head>\n  <body>\n    <div id=\"root\"></div>\n    ${normalizeAssets(assetsByChunkName.main)\n      .filter((asset) => asset.endsWith(\".js\"))\n      .map((asset) => `<script src=\"${asset}\"></script>`)\n      .join(\"\\n\")}\n  </body>\n</html>\n  `);\n});\n```\n\n## Other servers\n\nExamples of use with other servers will follow here.\n\n### connect-next\n\n[connect-next](https://github.com/rstackjs/connect-next) is an actively maintained fork of Connect.\n\n```js\nimport { createServer } from \"node:http\";\nimport { rspack } from \"@rspack/core\";\nimport { devMiddleware } from \"@rspack/dev-middleware\";\nimport { connect } from \"connect-next\";\nimport rspackConfig from \"./rspack.config.js\";\n\nconst compiler = rspack(rspackConfig);\nconst devMiddlewareOptions = {\n  // options\n};\nconst app = connect();\n\napp.use(devMiddleware(compiler, devMiddlewareOptions));\n\ncreateServer(app).listen(3000);\n```\n\n### Router\n\n```js\nimport { createServer } from \"node:http\";\nimport { rspack } from \"@rspack/core\";\nimport { devMiddleware } from \"@rspack/dev-middleware\";\nimport finalhandler from \"finalhandler\";\nimport Router from \"router\";\nimport rspackConfig from \"./rspack.config.js\";\n\nconst compiler = rspack(rspackConfig);\nconst devMiddlewareOptions = {\n  // options\n};\n\n// eslint-disable-next-line new-cap\nconst router = Router();\n\nrouter.use(devMiddleware(compiler, devMiddlewareOptions));\n\nconst server = createServer((req, res) => {\n  router(req, res, finalhandler(req, res));\n});\n\nserver.listen(3000);\n```\n\n### Express\n\n```js\nimport { rspack } from \"@rspack/core\";\nimport { devMiddleware } from \"@rspack/dev-middleware\";\nimport express from \"express\";\nimport rspackConfig from \"./rspack.config.js\";\n\nconst compiler = rspack(rspackConfig);\nconst devMiddlewareOptions = {\n  // options\n};\nconst app = express();\n\napp.use(devMiddleware(compiler, devMiddlewareOptions));\n\napp.listen(3000, () => console.log(\"Example app listening on port 3000!\"));\n```\n\n### Koa\n\n```js\nimport { rspack } from \"@rspack/core\";\nimport { devMiddleware } from \"@rspack/dev-middleware\";\nimport Koa from \"koa\";\nimport rspackConfig from \"./rspack.simple.config.js\";\n\nconst compiler = rspack(rspackConfig);\nconst devMiddlewareOptions = {\n  // options\n};\nconst app = new Koa();\n\napp.use(devMiddleware.koaWrapper(compiler, devMiddlewareOptions));\n\napp.listen(3000);\n```\n\n### Hapi\n\n```js\nimport Hapi from \"@hapi/hapi\";\nimport { rspack } from \"@rspack/core\";\nimport { devMiddleware } from \"@rspack/dev-middleware\";\nimport rspackConfig from \"./rspack.config.js\";\n\nconst compiler = rspack(rspackConfig);\nconst devMiddlewareOptions = {};\n\nconst server = Hapi.server({ port: 3000, host: \"localhost\" });\n\nawait server.register({\n  plugin: devMiddleware.hapiWrapper(),\n  options: {\n    // The `compiler` option is required\n    compiler,\n    ...devMiddlewareOptions,\n  },\n});\n\nawait server.start();\n\nconsole.log(\"Server running on %s\", server.info.uri);\n\nprocess.on(\"unhandledRejection\", (err) => {\n  console.log(err);\n  process.exit(1);\n});\n```\n\n### Hono\n\n```js\nimport { rspack } from \"@rspack/core\";\nimport { devMiddleware } from \"@rspack/dev-middleware\";\nimport { serve } from \"@hono/node-server\";\nimport { Hono } from \"hono\";\nimport rspackConfig from \"./rspack.config.js\";\n\nconst compiler = rspack(rspackConfig);\nconst devMiddlewareOptions = {\n  // options\n};\n\nconst app = new Hono();\n\napp.use(devMiddleware.honoWrapper(compiler, devMiddlewareOptions));\n\nserve(app);\n```\n\n## Credits\n\nThis repository is forked from [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware). It adapts the original implementation for the Rspack ecosystem, bridging behavioral differences with webpack while adding Rspack-specific capabilities.\n\n> Thanks to the webpack-dev-middleware maintainers and its original creator, [@sokra](https://github.com/sokra).\n\n## Contributing\n\nPlease take a moment to read our contributing guidelines if you haven't yet done so.\n\n[CONTRIBUTING](./CONTRIBUTING.md)\n\n## License\n\n[MIT](./LICENSE)\n","publish_time":1774939905032,"_cnpm_publish_time":1774939905032,"dist-tags":{"beta":"2.0.0-beta.2","canary":"0.2.12-canary-8211957-20230823102424","latest":"2.0.6","nightly":"0.2.12-canary-eb22d90-20230824011432","snapshot":"0.0.0-canary-2d5264852-20230525090643"}}