Technology Sharing

Vue environment variables

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Use of common project environment variables

General rule: Use .env. environment name file to define, specify the environment when running commands

For example: .env represents some variables used by all environment variables

.env.development represents the development environment variables

.env.production represents the production environment variables, which are used after going online

vite+vue3 project (starts with VITE by default, other starters need to be configured)

Save: VITE_ variable name = xxx

Take: import.meta.env.VITE_variable name

vue-cli project (webpack+vue2)

Save: VUE_APP_ variable name = xxx

Take: process.env.VUE_APP_ variable name

Pure webpack packaging

Save: Define it to the global environment through definePlugins