How can I use .env variable in petite-vue project?
when run yarn vite it give me error: process is not defined
The file structure is this:
Root
|_index.html
|_vue-index.ts
I've imported vue script in index.html and with something like console.log('Hello') connected to a button work fine so it's not a problem of importing script.
But, when I try to console.log(process.env.URL) it returns me that error and @click don't do nothing.
# .env
URL=http://example.com
// vue-index.ts
import { createApp } from 'petite-vue';
import 'dotenv/config';
createApp({
print() {
console.log(process.env.API_URL);
},
}).mount('#app');
The problems seems to be in import.meta.env. things by vite.
MY problem was that with TS that things is not permitted without changing tsconfig.json moule options to esnext or other.
Someone that can explain me how to use it?
If I run this with ts-node work properly.
import 'dotenv/config'
console.log(processs.env.API_URL)