vite-plugin-mock
vite-plugin-mock copied to clipboard
无法使用 vite 中 define 的信息
vite.config.ts
export default () => {
return {
define: { __APP_INFO__: "hello" }
}
}
mock/test.ts
console.log(__APP_INFO__)
// undefined
// 同样,获取 env 报错
console.log(import.meta.env.VITE_TEST)
// warning: "import.meta" is not available in the configured target environment ("es2015") and will be empty
关于如何解决这类问题的很简单,还是看了大佬的代码后才知道如何解决的

所以读取的文件要以_开头,也就是入口文件要以_开头
这个目前可能支持不了
define内的可以做简单兼容,但是从环境变量设置的目前没办法做到