Home > Mobile >  How to get env variables from env in github action .yaml in Vite project
How to get env variables from env in github action .yaml in Vite project

Time:07-26

I want to set an environment variable in github action .yaml. And I can access that variable inside my Vite project run time. Exp:

# staging.yaml - my github action file
...
env: VITE_INTERNAL = true
...
// index.vue - my Vite project
function myTest(){
    console.log(process.env.VITE_INTERNAL) // I hope to get "true" instead of "undefined"
}

Anyone can help me, please. Thanks a lot!

CodePudding user response:

You can read the docs here, but to expose env variables, you can do it like the following.

.env

VITE_INTERNAL = true

.yaml

console.log(import.meta.env.VITE_INTERNAL)

CodePudding user response:

To set an environment variable in a GitHub Action YAML, you can use env, jobs.<job_id>.env, or jobs.<job_id>.steps[*].env:

name: Build

permissions:
  contents: read
  issues: read
  checks: write
  pull-requests: write

on: push

#            
  • Related