Introduction to VUE front-end vue.config.js

view.config.js

The configuration file of the vue project needs to be written strictly in JSON format. The structure is as follows:

module.exports = {
    
    
  // 选项...
}

publicPath

The base URL when deploying the application package. For example, https://www.my-app.com/, then the publicPath
is "/". If the application is deployed at https://www.my-app.com/my-app/, set the publicPath to /my -app/.

outputDir

The directory of the production environment build files generated when running vue-cli-service build. Note that the contents of the target directory will be cleared before building (pass --no-clean when building to turn off this behavior).

assetsDir

The directory (relative to outputDir) where the generated static resources (js, css, img, fonts) are placed.

devServer

In the development environment API requests are proxied to the API server. This problem can be configured through the devServer.proxy option in vue.config.js. The production environment is generally responsible for Nginx.

process.env.VUE_APP_BASE_API

Since our projects need to run in different environments (development, production, testing, etc.), this avoids the need for us to switch the requested address and related configuration multiple times. vue-cli2 can be configured directly in the config file. , but vue-cli4 and vue-cli3 have been simplified. What should I do if there is no config file?

Create .env series files.
First, we create three new files in the root directory, namely .env.development, .env.production, and .env.test.
Note that the files only have suffixes.

.env.development mode is used for serve and development environment, that is, the configuration in this file will be referenced when starting the environment.

.env.production mode is used for build, online environment.

.env.test test environment

Guess you like

Origin blog.csdn.net/ChengR666/article/details/128599030