viteMockServe.ts 607 B

12345678910111213141516
  1. import { viteMockServe } from 'vite-plugin-mock'
  2. // import { resolve } from "path";
  3. export const configViteMockServePlugin = (isBuild: boolean, prodBuild: boolean) => {
  4. return viteMockServe({
  5. mockPath: '/mock',
  6. supportTs: true,
  7. localEnabled: !isBuild, // 是否应用于本地
  8. prodEnabled: isBuild && prodBuild, // 是否应用于生产-isBuild 并且生产环境配置了true
  9. // 这样可以控制关闭mock的时候不让mock打包到最终代码内 生产用的
  10. injectCode: `
  11. import { setupProdMockServer } from '/mock/index';
  12. setupProdMockServer();
  13. `
  14. })
  15. }