forked from vuejs/vue-cli
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
300 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,142 @@ | ||
# WIP | ||
## Table of Contents | ||
|
||
- [Introduction](#introduction) | ||
- [CLI](#cli) | ||
- [CLI Service](#cli-service) | ||
- [Configuration](#configuration) | ||
- [webpack](#webpack) | ||
- [browserslist](#browserslist) | ||
- [Babel](#babel) | ||
- [CSS](#css) | ||
- [ESLint](#eslint) | ||
- [TypeScript](#typescript) | ||
- [Unit Testing](#unit-testing) | ||
- [E2E Testing](#e2e-testing) | ||
- [Environment Variables and Modes](#environment-variables-and-modes) | ||
- [Development](#development) | ||
|
||
## Introduction | ||
|
||
## The CLI | ||
Vue CLI is a full system for rapid Vue.js development, providing: | ||
|
||
- Interactive project scaffolding via `@vue/cli`. | ||
- Zero config rapid prototyping via `@vue/cli` + `@vue/cli-service-global`. | ||
- A runtime dependency (`@vue/cli-service`) that is: | ||
- Upgradeable; | ||
- Built on top of webpack, with sensible defaults; | ||
- Configurable via in-project config file; | ||
- Extensible via plugins | ||
- A rich collection of official plugins integrating the best tools in the frontend ecosystem. | ||
|
||
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. | ||
|
||
## CLI | ||
|
||
The CLI is installed globally and provides the `vue` command in your terminal: | ||
|
||
``` sh | ||
npm install -g @vue/cli | ||
vue create my-project | ||
``` | ||
|
||
For full details on what the `vue` command can do, see the [full CLI docs](https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli/README.md). | ||
|
||
## CLI Service | ||
|
||
`@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. The binary exposes commands such as `vue-cli-service serve`, which can be used in npm scripts. 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. | ||
|
||
## Configuration | ||
|
||
### Vue CLI options | ||
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. | ||
|
||
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. | ||
|
||
### vue.config.js | ||
|
||
Many aspects of a Vue CLI project can be configured by placing a `vue.config.js` file at the root of your project. The file may already exist depending on the features you selected when creating the project. | ||
|
||
`vue.config.js` should export an object, for example: | ||
|
||
``` js | ||
// vue.config.js | ||
module.exports = { | ||
lintOnSave: true | ||
} | ||
``` | ||
|
||
Check [here](./config.md) for full list of possible options. | ||
|
||
### webpack | ||
|
||
### Modes and Environment Variables | ||
Probably the most common configuration need is tweaking the internal webpack config. Vue CLI provides flexible ways to achieve that without ejecting. | ||
|
||
### Webpack | ||
See [here](./webpack.md) for full details. | ||
|
||
- #### Basic Configuration | ||
### browserlist | ||
|
||
- #### Chaining | ||
You will notice a `browserlist` 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. | ||
|
||
- #### Using Resolved Config as a File | ||
See [here](https://github.com/ai/browserslist) for how to specify browser ranges. | ||
|
||
### Babel | ||
|
||
- link to: babel preset | ||
- link to: babel plugin | ||
Babel can be configured via `.babelrc` or the `babel` field in `package.json`. | ||
|
||
### CSS | ||
All Vue CLI apps use `@vue/babel-preset-app` by default, which includes: | ||
|
||
- [babel-preset-env](https://github.com/babel/babel/tree/master/packages/babel-preset-env) | ||
- [dynamic import syntax](https://github.com/tc39/proposal-dynamic-import) | ||
- [Object rest spread](https://github.com/tc39/proposal-object-rest-spread) | ||
- [babel-preset-stage-2](https://github.com/babel/babel/tree/master/packages/babel-preset-stage-2) | ||
- Vue JSX support | ||
|
||
- #### PostCSS | ||
See [@vue/babel-preset-app](https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/babel-preset-app) for preset options. | ||
|
||
### CSS | ||
|
||
- #### CSS Modules | ||
Vue CLI projects comes with support for [PostCSS](http://postcss.org/), [CSS Modules](https://github.com/css-modules/css-modules) and pre-processors including [Sass](https://sass-lang.com/), [Less](http://lesscss.org/) and [Stylus](http://stylus-lang.com/). | ||
|
||
- #### Other Pre-Processors | ||
See [here](./css.md) for more details on CSS related configurations. | ||
|
||
### ESLint | ||
|
||
- link to: eslint plugin | ||
ESLint can be configured via `.eslintrc` or `eslintConfig` field in `package.json`. | ||
|
||
See [@vue/cli-plugin-eslint](https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint) for more details. | ||
|
||
### TypeScript | ||
|
||
- link to: typescript plugin | ||
TypeScript can be configured via `tsconfig.json`. | ||
|
||
See [@vue/cli-plugin-typescript](https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-typescript) for more details. | ||
|
||
### Unit Testing | ||
|
||
- #### Jest | ||
|
||
See [@vue/cli-plugin-unit-jest](https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-unit-jest) for more details. | ||
|
||
- #### Mocha (via `mocha-webpack`) | ||
|
||
See [@vue/cli-plugin-unit-mocha](https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-unit-mocha) for more details. | ||
|
||
### E2E Testing | ||
|
||
- #### Cypress | ||
|
||
See [@vue/cli-plugin-e2e-cypress](https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-e2e-cypress) for more details. | ||
|
||
- #### Nightwatch | ||
|
||
See [@vue/cli-plugin-e2e-nightwatch](https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-e2e-nightwatch) for more details. | ||
|
||
## Environment Variables and Modes | ||
|
||
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. | ||
|
||
Vue CLI has comprehensive support for specifying different environment variables - see the [dedicated section](./env.md) for more details. | ||
|
||
## Development | ||
|
||
- [Contributing Guide](https://github.com/vuejs/vue-cli/blob/dev/.github/CONTRIBUTING.md) | ||
- [Plugin Development Guide](https://github.com/vuejs/vue-cli/blob/dev/docs/plugin.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
## `vue.config.js` | ||
|
||
Here are all the available options with default values (all optional): | ||
|
||
``` js | ||
module.exports = { | ||
// Project deployment base | ||
// By default we assume your app will be deployed at the root of a domain, | ||
// e.g. https://www.my-app.com/ | ||
// If your app is deployed at a sub-path, you will need to specify that | ||
// sub-path here. For example, if your app is deployed at | ||
// https://www.foobar.com/my-app/ | ||
// then change this to '/my-app/' | ||
baseUrl: '/', | ||
|
||
// where to output built files | ||
outputDir: 'dist', | ||
|
||
// whether to use eslint-loader for lint on save. | ||
lintOnSave: false, | ||
|
||
// use the full build with in-browser compiler? | ||
// https://vuejs.org/v2/guide/installation.html#Runtime-Compiler-vs-Runtime-only | ||
compiler: false, | ||
|
||
// tweak internal webpack configuration. | ||
// see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md | ||
chainWebpack: () => {}, | ||
configureWebpack: () => {}, | ||
|
||
// vue-loader options | ||
// https://vue-loader.vuejs.org/en/options.html | ||
vueLoader: {}, | ||
|
||
// generate sourceMap for production build? | ||
productionSourceMap: true, | ||
|
||
// CSS related options | ||
css: { | ||
// extract CSS in components into a single CSS file (only in production) | ||
extract: true, | ||
|
||
// enable CSS source maps? | ||
sourceMap: false, | ||
|
||
// pass custom options to pre-processor loaders. e.g. to pass options to | ||
// sass-loader, use { sass: { ... } } | ||
loaderOptions: {}, | ||
|
||
// Enable CSS modules for all css / pre-processor files. | ||
// This option does not affect *.vue files. | ||
modules: false | ||
}, | ||
|
||
// use thread-loader for babel & TS in production build | ||
// enabled by default if the machine has more than 1 cores | ||
parallel: require('os').cpus().length > 1, | ||
|
||
// split vendors using autoDLLPlugin? | ||
// can also be an explicit Array of dependencies to include in the DLL chunk. | ||
dll: false, | ||
|
||
// options for the PWA plugin. | ||
// see https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa | ||
pwa: {}, | ||
|
||
// configure webpack-dev-server behavior | ||
devServer: { | ||
open: process.platform === 'darwin', | ||
host: '0.0.0.0', | ||
port: 8080, | ||
https: false, | ||
hotOnly: false, | ||
proxy: null, // string | Object | ||
before: app => {} | ||
}, | ||
|
||
// options for 3rd party plugins | ||
pluginOptions: { | ||
// ... | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
## CSS | ||
|
||
### PostCSS | ||
|
||
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). | ||
|
||
### CSS Modules | ||
|
||
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>`. | ||
|
||
As for standalone style files, any files ending with `.module.(css|sass|scss|less|styl|stylus)` will be processed as CSS modules. | ||
|
||
If you wish to be able to use CSS modules without the `.module` postfix, you can set `css: { modules: true }` in `vue.config.js`. This option does not affect `*.vue` files. | ||
|
||
### Pre-Processors | ||
|
||
You can select pre-processors (Sass/Less/Stylus) when creating the project. If you did not do so, you can also just manually install the corresponding webpack loaders. The loaders are pre-configured and will automatically be picked up. For example, to add SASS to an existing project, simply run: | ||
|
||
``` sh | ||
npm install -D sass-loader node-sass | ||
``` | ||
|
||
Then you can import `.scss` files, or use it in `*.vue` files with: | ||
|
||
``` vue | ||
<style lang="scss"> | ||
$color = red; | ||
</style> | ||
``` | ||
|
||
### Passing Options to Pre-Processor Loaders | ||
|
||
Sometimes you may want to pass options to the pre-processor's webpack loader. You can do that using the `css.loaderOptions` option in `vue.config.js`. For example, to pass some shared global variables to all your Sass styles: | ||
|
||
``` js | ||
// vue.config.js | ||
const fs = require('fs') | ||
|
||
module.exports = { | ||
css: { | ||
loaderOptions: { | ||
sass: { | ||
data: fs.readFileSync('src/variables.scss', 'utf-8') | ||
} | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
## Environment Variables and Modes | ||
|
||
You can specify env variables by placing the following files in your project root: | ||
|
||
``` sh | ||
.env # loaded in all cases | ||
.env.local # loaded in all cases, ignored by git | ||
.env.[mode] # only loaded in specified mode | ||
.env.[mode].local # only loaded in specified mode, ignored by git | ||
``` | ||
|
||
An env file simply contains key=value pairs of environment variables: | ||
|
||
``` | ||
FOO=bar | ||
VUE_APP_SECRET=secret | ||
``` | ||
|
||
Loaded variables will become available to all `vue-cli-service` commands, plugins and dependencies. | ||
|
||
### Modes | ||
|
||
**Mode** is an important concept in Vue CLI projects. By default, there are three modes in a Vue CLI project: | ||
|
||
- `development` is used by `vue-cli-service serve` | ||
- `production` is used by `vue-cli-service build` | ||
- `test` is used by `vue-cli-service test` | ||
|
||
Note that a mode is different from `NODE_ENV`, as a mode can contain multiple environment variables. That said, each mode does set `NODE_ENV` to the same value by default - for example, `NODE_ENV` will be set to `"development"` in development mode. | ||
|
||
You can set environment variables only available to a certain mode by postfixing the `.env` file. For example, if you create a file named `.env.development` in your project root, then the variables declared in that file will only be loaded in development mode. | ||
|
||
### Using Env Variables in Client-side Code | ||
|
||
Only variables that start with `VUE_APP_` will be statically embedded into the client bundle with `webpack.DefinePlugin`. You can access them in your application code: | ||
|
||
``` js | ||
console.log(process.env.VUE_APP_SECRET) | ||
``` | ||
|
||
During build, `process.env.VUE_APP_SECRET` will be replaced by the corresponding value. In the case of `VUE_APP_SECRET=secret`, it will be replaced by `"secret"`. | ||
|
||
In addition to `VUE_APP_*` variables, there are also two special variables that will always be available in your app code: | ||
|
||
- `NODE_ENV` - this will be one of `"development"`, `"production"` or `"test"` depending on the [mode](#modes) the app is running in. | ||
- `BASE_URL` - this corresponds to the `baseUrl` option in `vue.config.js` and is the base path your app is deployed at. | ||
|
||
### Local Variables | ||
|
||
Sometimes you might have env variables that should not be committed into the codebase, especially if your project is hosted in a public repository. In that case you should use an `.env.local` file instead. Local env files are ignored in `.gitignore` by default. | ||
|
||
`.local` can also be appended to mode-specific env files, for example `.env.development.local` will be loaded during development, and is ignored by git. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# WIP | ||
|
||
### Basic Configuration | ||
|
||
### Chaining | ||
|
||
### Using Resolved Config as a File |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# @vue/cli | ||
|
||
## Usage | ||
|
||
``` sh | ||
npm install -g @vue/cli | ||
vue create my-app | ||
vue create my-project | ||
``` | ||
|
||
[Full Docs](https://github.com/vuejs/vue-cli/tree/dev/docs) |