Skip to content

How do I use mocks on prod mode? #25

Answered by pengzhanbo
ShookLyngs asked this question in Q&A
Discussion options

You must be logged in to vote

The plugin only supports running under vite server and vite 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. See options.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.

import { defineConfig } from 'vite'
import mockDevServerPlugin from '…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by pengzhanbo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants