Skip to content

Commit 9778794

Browse files
committed
docs: wip
1 parent 0b9c837 commit 9778794

File tree

12 files changed

+240
-112
lines changed

12 files changed

+240
-112
lines changed

docs/.vuepress/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
'/': {
44
lang: 'en-US',
55
title: 'Vue CLI',
6-
description: 'Standard Tooling for Vue.js Projects'
6+
description: '🛠️ Standard Tooling for Vue.js Development'
77
}
88
},
99
serviceWorker: true,

docs/.vuepress/override.styl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.home .hero img
2+
max-height 180px

docs/.vuepress/public/logo.png

3.37 KB
Loading
-217 KB
Binary file not shown.

docs/README.md

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
# Introduction
1+
---
2+
home: true
3+
heroImage: /logo.png
4+
actionText: Get Started →
5+
actionLink: /guide/
6+
features:
7+
- title: Feature Rich
8+
details: Out-of-the-box support for Babel, TypeScript, ESLint, PostCSS, PWA, Unit Testing & End-to-end Testing.
9+
- title: Extensible
10+
details: The plugin system allows the community to build and share reusable solutions to common needs.
11+
- title: No Need to Eject
12+
details: Vue CLI is fully configurable without the need for ejecting. This allows your project to stay up-to-date for the long run.
13+
- title: GUI on top of the CLI
14+
details: Create, develop and manage your projects through an accompanying graphical user interface.
15+
- title: Instant Prototyping
16+
details: Instantly prototype new ideas with a single Vue file.
17+
- title: Future Ready
18+
details: Effortlessly ship native ES2015 code for modern browsers, or build your vue components as native web components.
19+
footer: MIT Licensed | Copyright © 2018-present Evan You
20+
---
221

3-
Vue CLI is a full system for rapid Vue.js development, providing:
22+
## Getting Started
423

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
1328

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.
15-
16-
- Overview
17-
- CLI
18-
- Creating a Project
19-
- Plugins and Presets
20-
- Instant Prototyping
21-
- CLI UI
22-
- Development
23-
- The CLI Service
24-
- Browser Compatibility
25-
- HTML and static assets
26-
- Mode and Environment Variables
27-
- Git Hooks
28-
- Building as a Library
29-
- Building as Web Components
30-
- Deployment
29+
vue create my-project
30+
```

docs/config/README.md

Lines changed: 101 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ module.exports = {
5050

5151
// CSS related options
5252
css: {
53+
//
54+
// 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+
5360
// extract CSS in components into a single CSS file (only in production)
5461
// can also be an object of options to pass to extract-text-webpack-plugin
5562
extract: true,
@@ -59,11 +66,13 @@ module.exports = {
5966

6067
// pass custom options to pre-processor loaders. e.g. to pass options to
6168
// 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+
}
6776
},
6877

6978
// use thread-loader for babel & TS in production build
@@ -113,6 +122,10 @@ module.exports = {
113122

114123
The object will be merged into the final webpack config using [webpack-merge](https://github.com/survivejs/webpack-merge).
115124

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+
116129
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:
117130

118131
``` js
@@ -134,41 +147,29 @@ The internal webpack config is maintained using [webpack-chain](https://github.c
134147

135148
This allows us finer-grained control over the internal config. Here are some examples:
136149

137-
#### Transpiling a Dependency Module
138-
139-
By default the Babel configuration skips
150+
#### Modifying Options of a Loader
140151

141152
``` js
142153
// vue.config.js
143154
module.exports = {
144155
chainWebpack: config => {
145-
config.module
146-
.rule('js')
147-
.include
148-
.add(/some-module-to-transpile/)
149-
}
150-
}
151-
```
152-
153-
#### Modifying Loader Options
154-
155-
``` js
156-
// vue.config.js
157-
module.exports = {
158-
chainWebpack: config => {
159-
config.module
160-
.rule('scss')
161-
.use('sass-loader')
162-
.tap(options =>
163-
merge(options, {
164-
includePaths: [path.resolve(__dirname, 'node_modules')],
156+
config
157+
.rule('vue')
158+
.use('vue-loader')
159+
.loader('vue-loader')
160+
.tap(options => {
161+
// modify the options...
162+
return options
165163
})
166-
)
167164
}
168165
}
169166
```
170167

171-
#### Adding a new loader example
168+
::: tip
169+
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
172173

173174
``` js
174175
// vue.config.js
@@ -185,23 +186,30 @@ module.exports = {
185186
}
186187
```
187188

188-
#### Replace existing Base Loader
189+
#### Replacing Loaders of a Rule
189190

190191
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:
191192

192193
``` js
193194
// vue.config.js
194195
module.exports = {
195196
chainWebpack: config => {
196-
config.module
197-
.rule('svg')
198-
.use('file-loader')
197+
const svgRule = 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')
199207
.loader('vue-svg-loader')
200208
}
201209
}
202210
```
203211

204-
#### Modifying Plugin Options
212+
#### Modifying Options of a Plugin
205213

206214
``` js
207215
// vue.config.js
@@ -242,21 +250,37 @@ Since `@vue/cli-service` abstracts away the webpack config, it may be more diffi
242250

243251
`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.
244252

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:
246256

247257
``` bash
248258
vue inspect > output.js
249259
```
250260

251261
Note the output is not a valid webpack config file, it's a serialized format only meant for inspection.
252262

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:
254264

255265
``` bash
256266
# only inspect the first rule
257267
vue inspect module.rules.0
258268
```
259269

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+
260284
### Using Resolved Config as a File
261285

262286
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
275299

276300
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).
277301

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+
278306
### CSS Modules
279307

280308
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'
295323
import sassStyles from './foo.scss?module'
296324
```
297325

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`:
327+
328+
``` js
329+
// vue.config.js
330+
module.exports = {
331+
css: {
332+
loaderOptions: {
333+
css: {
334+
camelCase: 'only'
335+
}
336+
}
337+
}
338+
}
339+
```
299340

300341
### Pre-Processors
301342

@@ -324,21 +365,26 @@ const fs = require('fs')
324365
module.exports = {
325366
css: {
326367
loaderOptions: {
368+
// pass options to sass-loader
327369
sass: {
328-
data: fs.readFileSync('src/variables.scss', 'utf-8')
370+
// @/ is an alias to src/
371+
// so this assumes you have a file named `src/variables.scss`
372+
data: `@import "@/variables.scss";`
329373
}
330374
}
331375
}
332376
}
333377
```
334378

335-
This is preferred over manually tapping into specific loaders, because these options will be shared across all rules that are related to it.
379+
Loaders can be configured via `loaderOptions` include:
336380

337-
## browserslist
381+
- [css-loader](https://github.com/webpack-contrib/css-loader)
382+
- [postcss-loader](https://github.com/postcss/postcss-loader)
383+
- [sass-loader](https://github.com/webpack-contrib/sass-loader)
384+
- [less-loader](https://github.com/webpack-contrib/less-loader)
385+
- [stylus-loader](https://github.com/shama/stylus-loader)
338386

339-
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.
342388

343389
## Dev Server
344390

@@ -401,10 +447,16 @@ module.exports = {
401447

402448
## Babel
403449

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+
:::
405455

406456
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.
407457

458+
Also see the [Polyfills](../guide/browser-compatibility.md#polyfills) section in guide.
459+
408460
## ESLint
409461

410462
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
436488
### Nightwatch
437489

438490
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.

docs/guide/README.md

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebarDepth: 1
2+
sidebarDepth: 0
33
---
44

55
# Overview
@@ -19,38 +19,30 @@ Vue CLI aims to be the standard tooling baseline for the Vue ecosystem. It ensur
1919

2020
## Understanding the Architecture
2121

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.
2323

24-
The CLI is a installed globally npm package and provides the `vue` command in your terminal:
24+
### CLI
2525

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.
3027

3128
### CLI Service
3229

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`.
3631

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:
4033

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.
4237

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.
4439

45-
## Development Features
40+
The section on [CLI Service](./cli-service.md) covers its detailed usage.
4641

47-
- webpack
48-
- webpack-dev-server
49-
- pre-processors
50-
- git hooks
42+
### CLI Plugins
5143

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).
5345

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`.
5547

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

Comments
 (0)