A Vite plugin that integrates Express middleware into the Vite dev server for development mocking and API prototyping. Version 1.0.3 is the latest stable release, maintained via GitHub. It uses glob patterns to load server files automatically, supports hot reload without restarting Vite, and respects Vite's resolve aliases. Differs from alternatives like vite-plugin-mock by leveraging actual Express middleware, allowing realistic request/response handling including headers, CORS, and body parsing.
npm install vite-plugin-expressVerified import paths — ran on the pinned version, not inferred.
Basic setup: Vite config with express plugin, and a server file exporting a default middleware router.
Upgrade Vite to >=3.0.0 or use an alternative plugin.
Use ESM import syntax. If using CommonJS, consider dynamic import().
Ensure middlewareFiles pattern matches all desired files (e.g., './server/**/*.ts').
No action needed; changes apply on save.
Provide a full array of middlewares if overriding; include cors and bodyParser.json if needed.
Switch to ESM by using import statement or set "type": "module" in package.json.
Use default import: import express from 'vite-plugin-express'
Run npm install vite-plugin-express --save-dev and ensure import path is correct.
Use default import: import express from 'vite-plugin-express'
Convert project to ESM (type: module) or use dynamic import in server files.