Steps to configure different packaging commands for different environments in vue projects

The steps to configure different packaging commands for different environments in vue are as follows:

  1. Create a new file in the root directory of the project .envto store public environment variables.
  2. Create new files such as .env.development, .env.test, and .env.production in the root directory of the project to store variables in different environments, such as API addresses and port numbers.
  3. Add packaging commands for different environments in the scripts field in the package.json file,
    for example "build:test":“vue-cli-service build --mode test”, where --mode specifies which .env file to use. Use in the project process.envto obtain the corresponding environment variables.

Example: For example, to obtain the environment variables of the test environment

My .env.testfile content is as follows:

NODE_ENV=test // 环境区分变量
VUE_APP_MODE =test2 // 其他变量

Then vue.config.jsget the environment NODE_ENVmethod in:process.env.NODE_ENV

Guess you like

Origin blog.csdn.net/weixin_52443895/article/details/130135242