How to use dotenv with Vue.js

前端 未结 3 1213
无人及你
无人及你 2021-02-19 01:43

I\'m trying to add some environment variables into my vue app.

here is content of my .env file, which is placed on root(outside src):



        
3条回答
  •  自闭症患者
    2021-02-19 02:09

    If your project was create by using Vue CLI 3, no need to use dotenv to get environment variables.

    To get environment variables within .env file in your project:

    1. Placing the .env file in your project root.
    2. In the .env file, specifying environment variables with "VUE_APP_" prefix.

      VUE_APP_SOMEKEY=SOME_KEY_VALUE.

    3. Finally, you can access them with process.env.* in your application code.

      console.log(process.env.VUE_APP_SOMEKEY) // SOME_KEY_VALUE

    Referance: Vue CLI 3 - Environment Variables and Modes

提交回复
热议问题