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.
The CLI is installed globally and provides the vue
command in your terminal:
npm install -g @vue/cli
vue create my-project
See CLI docs for all available commands.
@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, @vue/cli-service
is essentially the equivalent of react-scripts
, but more flexible.
See CLI Service docs for all available commands.
The file public/index.html
is a template that will be processed with 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.
Static assets can be handled in two different ways:
-
Imported in JavaScript or referenced in templates/CSS via relative paths. Such references will be handled by webpack.
-
Placed in the
public
directory and referenced via absolute paths. These assets will simply be copied and not go through webpack.
See Static Assets Handling for more details.
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 using modes and .env
files.
See Environment Variables and Modes for more details.
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.
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:
// vue.config.js
module.exports = {
lintOnSave: true
}
Check here for full list of possible options.
Probably the most common configuration need is tweaking the internal webpack config. Vue CLI provides flexible ways to achieve that without ejecting.
See here for full details.
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.
See here for how to specify browser ranges.
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.config.js
.
See Configuring Proxy for more details.
Babel can be configured via .babelrc
or the babel
field in package.json
.
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 for details and preset options.
Vue CLI projects comes with support for PostCSS, CSS Modules and pre-processors including Sass, Less and Stylus.
See here for more details on CSS related configurations.
ESLint can be configured via .eslintrc
or eslintConfig
field in package.json
.
See @vue/cli-plugin-eslint for more details.
TypeScript can be configured via tsconfig.json
.
See @vue/cli-plugin-typescript for more details.
-
See @vue/cli-plugin-unit-jest for more details.
-
See @vue/cli-plugin-unit-mocha for more details.
-
See @vue/cli-plugin-e2e-cypress for more details.
-
See @vue/cli-plugin-e2e-nightwatch for more details.