You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Environment Variables and Modes](#environment-variables-and-modes)
6
10
-[Configuration](#configuration)
7
11
-[webpack](#webpack)
8
12
-[browserslist](#browserslist)
13
+
-[Dev Server Proxy](#dev-server-proxy)
9
14
-[Babel](#babel)
10
15
-[CSS](#css)
11
16
-[ESLint](#eslint)
12
17
-[TypeScript](#typescript)
13
18
-[Unit Testing](#unit-testing)
14
19
-[E2E Testing](#e2e-testing)
15
-
-[Environment Variables and Modes](#environment-variables-and-modes)
16
20
-[Development](#development)
17
21
18
22
## Introduction
@@ -39,34 +43,39 @@ npm install -g @vue/cli
39
43
vue create my-project
40
44
```
41
45
42
-
For full details on what the `vue` command can do, see the [full CLI docs](./cli.md).
46
+
See [CLI docs](./cli.md) for all available commands.
43
47
44
48
## CLI Service
45
49
46
50
`@vue/cli-service` is a dependency installed locally into every project created by `@vue/cli`. It contains the core service that loads other plugins, resolves the final webpack config, and provides the `vue-cli-service` binary to your project. If you are familiar with [create-react-app](https://github.com/facebookincubator/create-react-app), `@vue/cli-service` is essentially the equivalent of `react-scripts`, but more flexible.
47
51
48
-
Inside a project, you can access the binary directly as `vue-cli-service` in npm scripts, or as `./node_modules/.bin/vue-cli-service` from the terminal. This is what you will see in the `package.json` of a project using the default preset:
52
+
See [CLI Service docs](./cli-service.md) for all available commands.
49
53
50
-
```json
51
-
{
52
-
"scripts": {
53
-
"serve": "vue-cli-service serve --open",
54
-
"build": "vue-cli-service build"
55
-
}
56
-
}
57
-
```
54
+
## Conventions
58
55
59
-
Some CLI plugins will inject additional commands to `vue-cli-service`. For example, `@vue/cli-plugin-eslint` injects the `vue-cli-service lint` command. You can see all injected commands by running:
56
+
### The Index Page
60
57
61
-
```sh
62
-
./node_modules/.bin/vue-cli-service help
63
-
```
58
+
The file `public/index.html` is a template that will be processed with [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin). During build, asset links will be injected automatically. In addition, Vue CLI also automatically injects resource hints (`preload/prefetch`), manifest/icon links (when PWA plugin is used) and inlines the webpack runtime / chunk manifest for optimal performance.
64
59
65
-
You can also learn about the available options of each command with:
60
+
You can edit the file to add your own tags, but note one thing: you need to prefix links to assets with `<%= webpackConfig.output.publicPath %>` in case you are not deploying your app at the root of a domain.
66
61
67
-
```sh
68
-
./node_modules/.bin/vue-cli-service help [command]
69
-
```
62
+
### Static Assets Handling
63
+
64
+
Static assets can be handled in two different ways:
65
+
66
+
- Imported in JavaScript or referenced in templates/CSS via relative paths. Such references will be handled by webpack.
67
+
68
+
- Placed in the `public` directory and referenced via absolute paths. These assets will simply be copied and not go through webpack.
69
+
70
+
See [Static Assets Handling](./assets.md) for more details.
71
+
72
+
### Environment Variables and Modes
73
+
74
+
It is a common need to customize the app's behavior based on the target environment - for example, you may want the app to use different API endpoints or credentials during development / staging / production environments.
75
+
76
+
Vue CLI has comprehensive support for specifying different environment variables using modes and `.env` files.
77
+
78
+
See [Environment Variables and Modes](./env.md) for more details.
70
79
71
80
## Configuration
72
81
@@ -101,6 +110,12 @@ You will notice a `browserlist` field in `package.json` specifying a range of br
101
110
102
111
See [here](https://github.com/ai/browserslist) for how to specify browser ranges.
103
112
113
+
### Dev Server Proxy
114
+
115
+
If your frontend app and the backend API server are not running on the same host, you will need to proxy API requests to the API server during development. This is configurable via the `devServer.proxy` option in `vue.cofnig.js`.
116
+
117
+
See [Configuring Proxy](./cli-service.md#configuring-proxy) for more details.
118
+
104
119
### Babel
105
120
106
121
Babel can be configured via `.babelrc` or the `babel` field in `package.json`.
@@ -153,13 +168,7 @@ See [@vue/cli-plugin-typescript](https://github.com/vuejs/vue-cli/tree/dev/packa
153
168
154
169
See [@vue/cli-plugin-e2e-nightwatch](https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-e2e-nightwatch) for more details.
155
170
156
-
## Environment Variables and Modes
157
-
158
-
It is a common need to customize the app's behavior based on the target environment - for example, you may want the app to use different API endpoints or credentials during development / staging / production environments.
159
-
160
-
Vue CLI has comprehensive support for specifying different environment variables - see the [dedicated section](./env.md) for more details.
-[Caching and Parallel Mode](#caching-and-parallel-mode)
8
+
-[Building as Library or Web Component](#building-as-library-or-web-component)
9
+
-[DLL Mode](#dll-mode)
10
+
-[inspect](#inspect)
11
+
-[Checking All Available Commands](#checking-all-available-commands)
12
+
13
+
### Using the Binary
14
+
15
+
Inside a Vue CLI project, `@vue/cli-service` installs a binary named `vue-cli-service`. You can access the binary directly as `vue-cli-service` in npm scripts, or as `./node_modules/.bin/vue-cli-service` from the terminal.
16
+
17
+
This is what you will see in the `package.json` of a project using the default preset:
18
+
19
+
```json
20
+
{
21
+
"scripts": {
22
+
"serve": "vue-cli-service serve --open",
23
+
"build": "vue-cli-service build"
24
+
}
25
+
}
26
+
```
27
+
28
+
### serve
29
+
30
+
```
31
+
Usage: vue-cli-service dev [options]
32
+
33
+
Options:
34
+
35
+
--open open browser on server start
36
+
--mode specify env mode (default: development)
37
+
--host specify host (default: 0.0.0.0)
38
+
--port specify port (default: 8080)
39
+
--https use https (default: false)
40
+
```
41
+
42
+
`vue-cli-service serve` starts a dev server based on [webpack-dev-server](https://github.com/webpack/webpack-dev-server). It comes with hot-module-replacement (HMR) out of the box.
43
+
44
+
You can configure the dev server's behavior using the `devServer` option in `vue.config.js`:
45
+
46
+
```js
47
+
module.exports= {
48
+
devServer: {
49
+
open:process.platform==='darwin',
50
+
host:'0.0.0.0',
51
+
port:8080,
52
+
https:false,
53
+
hotOnly:false,
54
+
proxy:null, // string | Object
55
+
before:app=> {
56
+
// app is an express instance
57
+
}
58
+
}
59
+
}
60
+
```
61
+
62
+
#### Configuring Proxy
63
+
64
+
`devServer.proxy` can be a string pointing to the development API server:
65
+
66
+
```js
67
+
module.exports= {
68
+
devServer: {
69
+
proxy:'http://localhost:4000'
70
+
}
71
+
}
72
+
```
73
+
74
+
This will tell the dev server to proxy any unknown requests (requests that did not match a static file) to `http://localhost:4000`.
75
+
76
+
If you want to have more control over the proxy behavior, you can also use an object with `path: options` pairs. Consult [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware#proxycontext-config) for full options:
--name name for lib or web-component mode (default: "name" in package.json or entry filename)
105
+
```
106
+
107
+
`vue-cli-service build` produces a production-ready bundle in the `dist/` directory, with minification for JS/CSS/HTML and auto vendor chunk splitting for better caching. The chunk manifest is inlined into the HTML.
108
+
109
+
#### Caching and Parallel Mode
110
+
111
+
-`cache-laoder` is enabled for Babel/TypeScript transpilation by default.
112
+
-`thread-loader` will be enabled for Babel/TypeScript transpilation when the machine has more than 1 CPI cores.
113
+
114
+
#### Building as Library or Web Components
115
+
116
+
It is also possible to build any component(s) inside your project as a library or as web components. See [Build Targets](./build-targets.md) for more details.
117
+
118
+
#### DLL Mode
119
+
120
+
If your app has a large amount of dependency libraries, you can improve the build performance by opting into DLL mode. DLL mode builds your dependencies into a separate vendor bundle which will be reused on future builds as long as your dependencies did not change.
121
+
122
+
To enable DLL mode, set the `dll` option in `vue.config.js` to `true`:
123
+
124
+
```js
125
+
// vue.config.js
126
+
module.exports= {
127
+
dll:true
128
+
}
129
+
```
130
+
131
+
This by default builds **all the modules listed in the `dependencies` field in `package.json`** into the DLL bundle. It is important that you correctly list your dependencies, otherwise it may end up including unnecessary code.
132
+
133
+
If you wish to have finer grained control over what modules to be included in the DLL bundle, you can also provide an Array of modules to the `dll` option:
You can use `vue-cli-service inspect` to inspect the webpack config inside a Vue CLI project. See [Inspecting Webpack Config](./webpack.md#inspecting-the-projects-webpack-config) for more details.
156
+
157
+
### Checking All Available Commands
158
+
159
+
Some CLI plugins will inject additional commands to `vue-cli-service`. For example, `@vue/cli-plugin-eslint` injects the `vue-cli-service lint` command. You can see all injected commands by running:
160
+
161
+
```sh
162
+
./node_modules/.bin/vue-cli-service help
163
+
```
164
+
165
+
You can also learn about the available options of each command with:
166
+
167
+
```sh
168
+
./node_modules/.bin/vue-cli-service help [command]
0 commit comments