Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改mock文件,开发服务确实提示文件发生改变了,但是重新请求接口,内容和日志打印都没有发生变化 #36

Closed
morelearn1990 opened this issue Jul 9, 2021 · 8 comments

Comments

@morelearn1990
Copy link

morelearn1990 commented Jul 9, 2021

RT

使用示例里面的 ts-example ,安装最新版的 vite-plugin-mock 版本为 2.9.1。

必须要重新启动开发服务后,修改才生效

补充说明,后来实验了一下:
import { viteMockServe } from 'vite-plugin-mock'
这样的更新失效

但是使用本地未打包版本的就没问题
import { viteMockServe } from '../../src';

大佬,这个可能是什么原因啊

@renhhh
Copy link

renhhh commented Jul 9, 2021

一样,修改mock.ts文件,需要重启服务,才能生效(vite-plugin-mock 版本为 2.9.1)

@morelearn1990
Copy link
Author

没有人帮忙看看么?

@anncwb anncwb closed this as completed in 353aa9d Jul 18, 2021
@morelearn1990
Copy link
Author

啊?大佬为什么将issue关啦?

@anncwb
Copy link
Collaborator

anncwb commented Jul 19, 2021

尝试升级2.9.3

@morelearn1990
Copy link
Author

morelearn1990 commented Jul 20, 2021

还是不行嘞,改了之后还是要重启才能生效

@morelearn1990
Copy link
Author

@anncwb 老板我知道为啥开发调试能行,而打包后不能watch文件变化了。
因为你的代码里面清除缓存这儿delete require.cache[path] 里面的 require 会被编译成

var __require = (x) => {
  if (typeof require !== "undefined")
    return require(x);
  throw new Error('Dynamic require of "' + x + '" is not supported');
};

然后 delete __require.cache[fileName] 就会不生效。
而开发调试的时候从ts文件导入的模块就没这毛病

大佬,求解决呀。

@morelearn1990
Copy link
Author

我找到解决方法了,将 tsup 的 target 设置为 node12

@renhhh
Copy link

renhhh commented Jul 24, 2021

老哥,是怎么处理的呢?直接在项目里改,然后重新打包吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants