Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use vue-cli3.0.x

Shulou Source: shulou.com Published: 2022-06-03 16:47:02 11月14日 Update

This article is to share with you about how to use vue-cli3.0.x. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Installation environment

Here, npm install-g @ vue/cli is recommended. Other settings need to be made through yarn global add @ vue/cli, and some files are generated and deleted for a few minutes.

Npm install-g @ vue/cli# oryarn global add @ vue/cli# uses the vue command to create a project (different from cli2.0 's init,create) vue create my-project

If you use yarn global add @ vue/cli to install, you need to go to the directory. Execution

The yarn / / installation project relies on cd packages/@vue/cli / / directory yarn link / / add link `vue` to perform instructions. Vue create my-project / / create a project.

Multi-environment configuration

Because the company has development environment, test environment, joint debugging environment, online environment. Reduce artificial configuration, one-time configuration to the principle. So in 2.0.x added "package.json" tt ":" node build/tt-build.js "" type configuration, configuration can not be a lot of files. The ".env" file configuration is supported in vue-cli 3.0.x, and I add ".env.development", ".env.production" and ".env.test" configurations here.

1. Basic correspondence and default

Development is used by vue-cli-service serve production is used by vue-cli-service build test is used by vue-cli-service test

two。 Specify configuration startup

To add other configurations, you need to specify the configuration below.

"dev-build": "vue-cli-service build-mode development"

3. Compilation of ".env" configuration file

The content of the configuration file is in the following format

VUE_APP_*

For example, ".env.production" is as follows

VUE_APP_MOCK_URL = 'https://xxx.xxx.xxx/restapi/'

4. Adjust the configuration of the environment

Console.log (process.env.VUE_APP_MOCK_URL); process.env.NODE_ENV / / specific BASE_URL / / vue.config.js configuration Thank you for reading! This is the end of the article on "how to use vue-cli3.0.x". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Configuration environment file content project more catalog article good practical company principle command article format look knowledge type reference help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia OPPO Reno Huawei Shulou Technology Shulou Tech Info