Vue2.x official scaffolding distinguishes development environment and production environment

At work, using the official scaffolding of vue2.x, it is necessary to distinguish the IP of different servers according to the development environment and the upper production environment. How to deal with this change

 

1. Use the webpack script to distinguish whether "npm run dev" or "npm run build" is used, and then introduce different configuration information according to this condition

 

// Whether the current environment is a development environment
export const IS_DEV = process.env.NODE_ENV === 'development';

 

 

explain:

1. The process module allows you to obtain or modify the settings of the current node process. Unlike other modules that need to be imported, process is a global process (node ​​main process) , and you can directly access it directly through the process variable.

2. In the webpack scaffolding, an attribute value of env.NODE_ENV is dynamically added. It is simple to understand that process is a large JSON object with personal attributes added.

 

 

2. Today, the company's architect, Mr. Yang, provided the simplest idea, that is, the configuration information is directly introduced as a JS file of the index.html page , and the rest of the business logic pages are packaged by webpack, and all the internal configuration information is packaged Get from the imported JS file

 

 

Insight: Look at the essence of the problem, you need to simplify complex problems, don't focus too much on one point, you should jump out to see the overall situation, and make the problem clear and simple .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326451118&siteId=291194637