vue-cli 3.0 division multiple packaged configuration environment

Sub-environment package:

  • Development environment
  • test environment
  • Formal environment

Profiles

  • .env

  • .env.development

  • .env.production

   Without these three files in the root directory you can create your own

 

 Look at what each file written env

  • .env development environment
NODE_ENV = 'dev'
VUE_APP_CURENV = 'dev'
  • .env.development test environment
NODE_ENV = ' test ' 
VUE_APP_CURENV = ' test '
  • .env.production production environment
NODE_ENV = ' pro ' 
VUE_APP_CURENV = ' pro '

 

We write the code in the top of the env is doing with it,

We can get used process.env.VUE_APP_CURENV VUE_APP_CURENV = 'pro' value, we define the interface for different environments

= the baseUrl the let '' 
Switch (process.env.VUE_APP_CURENV) {
   Case  ' dev ' : 
    the baseUrl = config.publicPath.dev // this is a local request URL 
    BREAK 
  Case  ' Test ' : 
    the baseUrl = config.publicPath.test // test environment URL 
    BREAK 
  Case  ' Pro ' : 
    the baseUrl = config.publicPath.pro // production URL 
    BREAK 
}

Instructions

 

You use the command

  • npm run build: dev // packaged development environment
  • npm run build: test // packaged test environment
  • npm run build: pro // packaging production environment

 

Guess you like

Origin www.cnblogs.com/listen9436/p/12526400.html