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
Vue CLI is a full system for rapid Vue.js development, providing:
22
+
## Getting Started
4
23
5
-
- Interactive project scaffolding via `@vue/cli`.
6
-
- Zero config rapid prototyping via `@vue/cli` + `@vue/cli-service-global`.
7
-
- A runtime dependency (`@vue/cli-service`) that is:
8
-
- Upgradeable;
9
-
- Built on top of webpack, with sensible defaults;
10
-
- Configurable via in-project config file;
11
-
- Extensible via plugins
12
-
- A rich collection of official plugins integrating the best tools in the frontend ecosystem.
24
+
```bash
25
+
npm install -g @vue/cli
26
+
# OR
27
+
yarn global add @vue/cli
13
28
14
-
Vue CLI aims to be the standard tooling baseline for the Vue ecosystem. It ensures the various build tools work smoothly together with sensible defaults so you can focus on writing your app instead of spending days wrangling with configurations. At the same time, it still offers the flexibility to tweak the config of each tool without the need for ejecting.
// By defualt only files ending with *.modules.[ext] are loaded as
55
+
// CSS modules. Setting this to true enables CSS modules for all style
56
+
// file types.
57
+
// This option does not affect *.vue files.
58
+
modules:false,
59
+
53
60
// extract CSS in components into a single CSS file (only in production)
54
61
// can also be an object of options to pass to extract-text-webpack-plugin
55
62
extract:true,
@@ -59,11 +66,13 @@ module.exports = {
59
66
60
67
// pass custom options to pre-processor loaders. e.g. to pass options to
61
68
// sass-loader, use { sass: { ... } }
62
-
loaderOptions: {},
63
-
64
-
// Enable CSS modules for all css / pre-processor files.
65
-
// This option does not affect *.vue files.
66
-
modules:false
69
+
loaderOptions: {
70
+
css: {},
71
+
postcss: {},
72
+
less: {},
73
+
sass: {},
74
+
stylus: {}
75
+
}
67
76
},
68
77
69
78
// use thread-loader for babel & TS in production build
@@ -113,6 +122,10 @@ module.exports = {
113
122
114
123
The object will be merged into the final webpack config using [webpack-merge](https://github.com/survivejs/webpack-merge).
115
124
125
+
::: warning
126
+
Some webpack options are set based on values in `vue.config.js` and should not be mutated directly. For example, instead of modifying `output.path`, you should use the `outputDir` option in `vue.config.js`; instead of modifying `output.publicPath`, you should use the `baseUrl` option in `vue.config.js`. This is because the values in `vue.config.js` will be used in multiple places inside the config to ensure everything works properly together.
127
+
:::
128
+
116
129
If you need conditional behavior based on the environment, or want to directly mutate the config, use a function (which will be lazy evaluated after the env variables are set). The function receives the resolved config as the argument. Inside the function, you can either mutate the config directly, OR return an object which will be merged:
117
130
118
131
```js
@@ -134,41 +147,29 @@ The internal webpack config is maintained using [webpack-chain](https://github.c
134
147
135
148
This allows us finer-grained control over the internal config. Here are some examples:
For CSS related loaders, it's recommended to use [css.loaderOptions](#passing-options-to-pre-processor-loaders) instead of directly targeting loaders via chaining. This is because there are multiple rules for each CSS file type and `css.loaderOptions` ensures you can affect all rules in one single place.
170
+
:::
171
+
172
+
#### Adding a New Loader
172
173
173
174
```js
174
175
// vue.config.js
@@ -185,23 +186,30 @@ module.exports = {
185
186
}
186
187
```
187
188
188
-
#### Replace existing Base Loader
189
+
#### Replacing Loaders of a Rule
189
190
190
191
If you want to replace an existing [Base Loader](https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-service/lib/config/base.js), for example using `vue-svg-loader` to inline SVG files instead of loading the file:
191
192
192
193
```js
193
194
// vue.config.js
194
195
module.exports= {
195
196
chainWebpack:config=> {
196
-
config.module
197
-
.rule('svg')
198
-
.use('file-loader')
197
+
constsvgRule=config.module.rule('svg')
198
+
199
+
// clear all existing loaders.
200
+
// if you don't do this, the loader below will be appended to
201
+
// existing loaders of the rule.
202
+
svgRule.uses.clear()
203
+
204
+
// add replacement loader(s)
205
+
svgRule
206
+
.use('vue-svg-loader')
199
207
.loader('vue-svg-loader')
200
208
}
201
209
}
202
210
```
203
211
204
-
#### Modifying Plugin Options
212
+
#### Modifying Options of a Plugin
205
213
206
214
```js
207
215
// vue.config.js
@@ -242,21 +250,37 @@ Since `@vue/cli-service` abstracts away the webpack config, it may be more diffi
242
250
243
251
`vue-cli-service` exposes the `inspect` command for inspecting the resolved webpack config. The global `vue` binary also provides the `inspect` command, and it simply proxies to `vue-cli-service inspect` in your project.
244
252
245
-
The command prints to stdout by default, so you can redirect that into a file for easier inspection:
253
+
The command will print the resolved webpack config to stdout, which also contains hints on how to access rules and plugins via chaining.
254
+
255
+
You can redirect the output into a file for easier inspection:
246
256
247
257
```bash
248
258
vue inspect > output.js
249
259
```
250
260
251
261
Note the output is not a valid webpack config file, it's a serialized format only meant for inspection.
252
262
253
-
You can also inspect a certain path of the config to narrow it down:
263
+
You can also inspect a subset of the config by specifying a path:
254
264
255
265
```bash
256
266
# only inspect the first rule
257
267
vue inspect module.rules.0
258
268
```
259
269
270
+
Or, target a named rule or plugin:
271
+
272
+
```bash
273
+
vue inspect --rule vue
274
+
vue inspect --plugin html
275
+
```
276
+
277
+
Finally, you can list all named rules and plugins:
278
+
279
+
```bash
280
+
vue inspect --rules
281
+
vue inspect --plugins
282
+
```
283
+
260
284
### Using Resolved Config as a File
261
285
262
286
Some external tools may need access to the resolved webpack config as a file, for example IDEs or command line tools that expects a webpack config path. In that case you can use the following path:
@@ -275,6 +299,10 @@ Vue CLI projects comes with support for [PostCSS](http://postcss.org/), [CSS Mod
275
299
276
300
Vue CLI uses PostCSS internally, and enables [autoprefixer](https://github.com/postcss/autoprefixer) by default. You can configure PostCSS via `.postcssrc` or any config source supported by [postcss-load-config](https://github.com/michael-ciniawsky/postcss-load-config).
277
301
302
+
You can also configure `postcss-loader` via `css.loaderOptions.postcss` in `vue.config.js`.
303
+
304
+
The [autoprefixer](https://github.com/postcss/autoprefixer) plugin is enabled by default. To configure the browser targets, use the [browserslist](../guide/browser-compatibility.html#browserslist) field in `package.json`.
305
+
278
306
### CSS Modules
279
307
280
308
You can [use CSS Modules in `*.vue` files](https://vue-loader.vuejs.org/en/features/css-modules.html) out of the box with `<style module>`.
@@ -295,7 +323,20 @@ import styles from './foo.css?module'
295
323
importsassStylesfrom'./foo.scss?module'
296
324
```
297
325
298
-
If you wish to customize the generated CSS modules class names, you can do so via the `css.localIdentName` option in `vue.config.js`.
326
+
If you wish to customize the generated CSS modules class names, you can do so via `css.loaderOptions.css` in `vue.config.js`. All `css-loader` options are supported here, for example `localIdentName` and `camelCase`:
You will notice a `browserslist` field in `package.json` specifying a range of browsers the project is targeting. This value will be used by `babel-preset-env` and `autoprefixer` to automatically determine the JavaScript polyfills and CSS vendor prefixes needed.
340
-
341
-
See [here](https://github.com/ai/browserslist) for how to specify browser ranges.
387
+
This is preferred over manually tapping into specific loaders, because these options will be shared across all rules that are related to it.
342
388
343
389
## Dev Server
344
390
@@ -401,10 +447,16 @@ module.exports = {
401
447
402
448
## Babel
403
449
404
-
Babel can be configured via `.babelrc` or the `babel` field in `package.json`.
450
+
Babel can be configured via `babel.config.js`.
451
+
452
+
::: tip
453
+
Vue CLI uses `babel.config.js` which is a new config format in Babel 7. Unlike `.babelrc` or the `babel` field in `package.json`, this config file does not use a file-location based resolution, and is applied consistently to any file under project root, including dependencies inside `node_modules`. It is recommended to always use `babel.config.js` instead of other formats in Vue CLI projects.
454
+
:::
405
455
406
456
All Vue CLI apps use `@vue/babel-preset-app`, which includes `babel-preset-env`, JSX support and optimized configuration for minimal bundle size overhead. See [its docs](https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/babel-preset-app) for details and preset options.
407
457
458
+
Also see the [Polyfills](../guide/browser-compatibility.md#polyfills) section in guide.
459
+
408
460
## ESLint
409
461
410
462
ESLint can be configured via `.eslintrc` or `eslintConfig` field in `package.json`.
@@ -436,3 +488,7 @@ See [@vue/cli-plugin-e2e-cypress](https://github.com/vuejs/vue-cli/tree/dev/pack
436
488
### Nightwatch
437
489
438
490
See [@vue/cli-plugin-e2e-nightwatch](https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-e2e-nightwatch) for more details.
491
+
492
+
## Browser Targets
493
+
494
+
See the [Browser Compatibility](../guide/browser-compatibility.md#browserslist) section in guide.
@@ -19,38 +19,30 @@ Vue CLI aims to be the standard tooling baseline for the Vue ecosystem. It ensur
19
19
20
20
## Understanding the Architecture
21
21
22
-
### CLI
22
+
There are several moving parts of Vue CLI - if you look at the [source code](https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue), you will find that it is a monorepo containing a number of separately published packages.
23
23
24
-
The CLI is a installed globally npm package and provides the `vue` command in your terminal:
24
+
###CLI
25
25
26
-
```bash
27
-
npm install -g @vue/cli
28
-
vue create my-project
29
-
```
26
+
The CLI (`@vue/cli`) is a globally installed npm package and provides the `vue` command in your terminal. It provides the ability to quickly scaffold a new project via `vue create`, or instantly prototype new ideas via `vue serve`. You can also manage your projects using a graphical user interface via `vue ui`. We will walk through what it can do in the next few sections of the guide.
30
27
31
28
### CLI Service
32
29
33
-
`@vue/cli-service` is an npm package 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.
34
-
35
-
See [CLI Service docs](./cli-service.md) for all available commands.
30
+
The CLI Service (`@vue/cli-service`) is a development dependency. It's an npm package installed locally into every project created by `@vue/cli`.
36
31
37
-
### CLI Plugins
38
-
39
-
Each project will likely contain a number of
32
+
The CLI Service is built on top of [webpack](http://webpack.js.org/) and [webpack-dev-server](https://github.com/webpack/webpack-dev-server). It contains:
40
33
41
-
### Presets
34
+
- The core service that loads other CLI Plugins;
35
+
- An internal webpack config that is optimized for most apps;
36
+
- The `vue-cli-service` binary inside the project, which comes with the basic `serve`, `build` and `inspect` commands.
42
37
43
-
A preset
38
+
If you are familiar with [create-react-app](https://github.com/facebookincubator/create-react-app), `@vue/cli-service` is roughly the equivalent of `react-scripts`, although the feature set is different.
44
39
45
-
## Development Features
40
+
The section on [CLI Service](./cli-service.md) covers its detailed usage.
46
41
47
-
- webpack
48
-
- webpack-dev-server
49
-
- pre-processors
50
-
- git hooks
42
+
### CLI Plugins
51
43
52
-
## Configuration without Ejecting
44
+
CLI Plugins are npm packages that provide optional features to your Vue CLI projects, such as Babel/TypeScript trasnpilation, ESLint integration, unit testing, and end-to-end testing. It's easy to spot a Vue CLI plugin as their names start with either `@vue/cli-plugin-` (for built-in plugins) or `vue-cli-plugin-` (for community plugins).
53
45
54
-
Projects created from vue create are ready to go out-of-the-box. The plugins are designed to work with one another so in most cases, all you need to do is pick the features you want during the interactive prompts.
46
+
When you run the `vue-cli-service` binary inside your project, it automatically resolves and loads all CLI Plugins listed in your project's `package.json`.
55
47
56
-
However, we also understand that it's impossible to cater to every possible need, and the need of a project may also change over time. Projects created by Vue CLI allows you to configure almost every aspect of the tooling without ever needing to eject. Check out the [Config Reference](../config/) for more details.
48
+
Plugins can be included as part of your project creation process or added into the project later. They can also be grouped into reusable presets. We will discuss these in more depth in the [Plugins and Presets](./plugins-and-presets.md) section.
0 commit comments