How to package according to environment in vue2 version

foreword

The company has different servers, testing, pre-production, and production. If it is not the case of k8s automatic deployment, then each environment needs to change the domain name configuration and repackage, which is very troublesome. At this time, lazy people thought of a lazy trick
Step 1: Create a global directory under the static directory, and create a global.js file under the global directory.
insert image description here
Step 2: Define a variable in global.js to define which environment, such as dev, test, uat, prd, etc.

window.base = {
    
    
	dev:{
    
    
	   server:'http://&&&&',
	   serverweb:'http://wwwww'
	},
	test:{
    
    
	   server:'http://&&&&',
	   serverweb:'http://wwwww'
	}
	……
}

Step 3: Introduce global.js into index.html
insert image description here
Step 4: Where the request is requested

`${
     
     base.sq + base.version}/apiXXXX`

Step 5: After the packaging is complete, modify the configuration related to global.js

In this case, it can be less troublesome. Every environment needs to change the configuration and repackage, which is a waste of time. Of course,
if it is in the k8s environment, it is another way. You can extract the corresponding configuration and make it A public dictionary, no need to change the service every time

Guess you like

Origin blog.csdn.net/u013994400/article/details/127403178