How do I use mocks on prod mode? #25
-
Is it possible to use the mock-dev-server features in production mode? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The plugin only supports running under And because mock files support importing node modules and third-party modules, the mock code will not be packaged into the project source code. However, it does support packaging the mock files as a small independent Node service that can be deployed separately in You can deploy this Node service separately and then use an HTTP service such as Nginx for proxy according to your application scenario so that frontend projects can use these mock interfaces. import { defineConfig } from 'vite'
import mockDevServerPlugin from 'vite-plugin-mock-dev-server'
export default defineConfig({
plugins: [
mockDevServerPlugin({
build: true,
}),
]
}) |
Beta Was this translation helpful? Give feedback.
The plugin only supports running under
vite server
andvite preview
mode by default.And because mock files support importing node modules and third-party modules, the mock code will not be packaged into the project source code.
However, it does support packaging the mock files as a small independent Node service that can be deployed separately in
vite build
mode. Seeoptions.build
in configuration documentation and Mock Services.You can deploy this Node service separately and then use an HTTP service such as Nginx for proxy according to your application scenario so that frontend projects can use these mock interfaces.