vite-plugin-mock icon indicating copy to clipboard operation
vite-plugin-mock copied to clipboard

无法使用 vite 中 define 的信息

Open cnguu opened this issue 4 years ago • 3 comments

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

cnguu avatar Jul 08 '21 06:07 cnguu

关于如何解决这类问题的很简单,还是看了大佬的代码后才知道如何解决的 image

所以读取的文件要以_开头,也就是入口文件要以_开头

wanglei520 avatar Jul 17 '21 13:07 wanglei520

这个目前可能支持不了

anncwb avatar Jul 18 '21 15:07 anncwb

define内的可以做简单兼容,但是从环境变量设置的目前没办法做到

anncwb avatar Jul 18 '21 15:07 anncwb