Configuration Reference In Vue CLI 3.0
Configuration Reference
#Global CLI Config
Some global configurations for @vue/cli
, such as your preferred package manager and your locally saved presets, are stored in a JSON file named .vuerc
in your home directory. You can edit this file directly with your editor of choice to change the saved options.
You can also use the vue config
command to inspect or modify the global CLI config.
#Target Browsers
See the Browser Compatibility section in guide.
#vue.config.js
vue.config.js
is an optional config file that will be automatically loaded by @vue/cli-service
if it's present in your project root (next to package.json
). You can also use the vue
field in package.json
, but do note in that case you will be limited to JSON-compatible values only.
The file should export an object containing options:
// vue.config.js
module.exports = {
// options...
}
#baseUrl
Deprecated since Vue CLI 3.3, please use publicPath
instead.
#publicPath
Type:
string
Default:
'/'
The base URL your application bundle will be deployed at (known as
baseUrl
before Vue CLI 3.3). This is the equivalent of webpack'soutput.publicPath
, but Vue CLI also needs this value for other purposes, so you should always usepublicPath
instead of modifying webpackoutput.publicPath
.By default, Vue CLI assumes 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 using this option. For example, if your app is deployed athttps://www.foobar.com/my-app/
, setpublicPath
to'/my-app/'
.The value can also be set to an empty string (
''
) or a relative path (./
) so that all assets are linked using relative paths. This allows the built bundle to be deployed under any public path, or used in a file system based environment like a Cordova hybrid app.Limitations of relative publicPath
Relative
publicPath
has some limitations and should be avoided when:You are using HTML5
history.pushState
routing;You are using the
pages
option to build a multi-paged app.
This value is also respected during development. If you want your dev server to be served at root instead, you can use a conditional value:
module.exports = {
publicPath: process.env.NODE_ENV === 'production'
? '/production-sub-path/'
: '/'
}
#outputDir
Type:
string
Default:
'dist'
The directory where the production build files will be generated in when running
vue-cli-service build
. Note the target directory will be removed before building (this behavior can be disabled by passing--no-clean
when building).TIP
Always use
outputDir
instead of modifying webpackoutput.path
.
#assetsDir
Type:
string
Default:
''
A directory (relative to
outputDir
) to nest generated static assets (js, css, img, fonts) under.TIP
assetsDir
is ignored when overwriting the filename or chunkFilename from the generated assets.
#indexPath
Type:
string
Default:
'index.html'
Specify the output path for the generated
index.html
(relative tooutputDir
). Can also be an absolute path.
#filenameHashing
Type:
boolean
Default:
true
By default, generated static assets contains hashes in their filenames for better caching control. However, this requires the index HTML to be auto-generated by Vue CLI. If you cannot make use of the index HTML generated by Vue CLI, you can disable filename hashing by setting this option to
false
.
#pages
Type:
Object
Default:
undefined
Build the app in multi-page mode. Each "page" should have a corresponding JavaScript entry file. The value should be an object where the key is the name of the entry, and the value is either:
- An object that specifies its
entry
,template
,filename
,title
andchunks
(all optional exceptentry
). Any other properties added beside those will also be passed directly tohtml-webpack-plugin
, allowing user to customize said plugin; - Or a string specifying its
entry
.
module.exports = {
pages: {
index: {
// entry for the page
entry: 'src/index/main.js',
// the source template
template: 'public/index.html',
// output as dist/index.html
filename: 'index.html',
// when using title option,
// template title tag needs to be <title><%= htmlWebpackPlugin.options.title %></title>
title: 'Index Page',
// chunks to include on this page, by default includes
// extracted common chunks and vendor chunks.
chunks: ['chunk-vendors', 'chunk-common', 'index']
},
// when using the entry-only string format,
// template is inferred to be `public/subpage.html`
// and falls back to `public/index.html` if not found.
// Output filename is inferred to be `subpage.html`.
subpage: 'src/subpage/main.js'
}
}
TIP
When building in multi-page mode, the webpack config will contain different plugins (there will be multiple instances of
html-webpack-plugin
andpreload-webpack-plugin
). Make sure to runvue inspect
if you are trying to modify the options for those plugins.- An object that specifies its
#lintOnSave
Type:
boolean | 'warning' | 'default' | 'error'
Default:
true
Whether to perform lint-on-save during development using eslint-loader. This value is respected only when
@vue/cli-plugin-eslint
is installed.When set to
true
or'warning'
,eslint-loader
will emit lint errors as warnings. By default, warnings are only logged to the terminal and does not fail the compilation, so this is a good default for development.To make lint errors show up in the browser overlay, you can use
lintOnSave: 'default'
. This will forceeslint-loader
to actually emit errors. this also means lint errors will now cause the compilation to fail.Setting it to
'errors'
will force eslint-loader to emit warnings as errors as well, which means warnings will also show up in the overlay.Alternatively, you can configure the overlay to display both warnings and errors:
// vue.config.js
module.exports = {
devServer: {
overlay: {
warnings: true,
errors: true
}
}
}
When
lintOnSave
is a truthy value,eslint-loader
will be applied in both development and production. If you want to disableeslint-loader
during production build, you can use the following config:// vue.config.js
module.exports = {
lintOnSave: process.env.NODE_ENV !== 'production'
}
#runtimeCompiler
Type:
boolean
Default:
false
Whether to use the build of Vue core that includes the runtime compiler. Setting it to
true
will allow you to use thetemplate
option in Vue components, but will incur around an extra 10kb payload for your app.See also: Runtime + Compiler vs. Runtime only.
#transpileDependencies
Type:
Array<string | RegExp>
Default:
[]
By default
babel-loader
ignores all files insidenode_modules
. If you want to explicitly transpile a dependency with Babel, you can list it in this option.
Jest config
This option is not respected by the cli-unit-jest plugin, because in jest, we don't have to transpile code from /node_modules
unless it uses non-standard features - Node >8.11 supports the latest ECMAScript features already.
However, jest sometimes has to transform content from node_modules if that code uses ES6 import
/export
syntax. In that case, use the tranformIgnorePatterns
option in jest.config.js
.
See the plugin's README for more information.
#productionSourceMap
Type:
boolean
Default:
true
Setting this to
false
can speed up production builds if you don't need source maps for production.
#crossorigin
Type:
string
Default:
undefined
Configure the
crossorigin
attribute on<link rel="stylesheet">
and<script>
tags in generated HTML.Note that this only affects tags injected by
html-webpack-plugin
- tags directly added in the source template (public/index.html
) are not affected.See also: CORS settings attributes
#integrity
Type:
boolean
Default:
false
Set to
true
to enable Subresource Integrity (SRI) on<link rel="stylesheet">
and<script>
tags in generated HTML. If you are hosting your built files on a CDN, it is a good idea to enable this for additional security.Note that this only affects tags injected by
html-webpack-plugin
- tags directly added in the source template (public/index.html
) are not affected.Also, when SRI is enabled, preload resource hints are disabled due to a bug in Chrome which causes the resources to be downloaded twice.
#configureWebpack
Type:
Object | Function
If the value is an Object, it will be merged into the final config using webpack-merge.
If the value is a function, it will receive the resolved config as the argument. The function can either mutate the config and return nothing, OR return a cloned or merged version of the config.
#chainWebpack
Type:
Function
A function that will receive an instance of
ChainableConfig
powered by webpack-chain. Allows for more fine-grained modification of the internal webpack config.See also: Working with Webpack > Chaining
#css.modules
Type:
boolean
Default:
false
By default, only files that ends in
*.module.[ext]
are treated as CSS modules. Setting this totrue
will allow you to drop.module
in the filenames and treat all*.(css|scss|sass|less|styl(us)?)
files as CSS modules.See also: Working with CSS > CSS Modules
#css.extract
Type:
boolean | Object
Default:
true
in production,false
in developmentWhether to extract CSS in your components into a standalone CSS files (instead of inlined in JavaScript and injected dynamically).
This is always disabled when building as web components (styles are inlined and injected into shadowRoot).
When building as a library, you can also set this to
false
to avoid your users having to import the CSS themselves.Extracting CSS is disabled by default in development mode since it is incompatible with CSS hot reloading. However, you can still enforce extraction in all cases by explicitly setting the value to
true
.
#css.sourceMap
Type:
boolean
Default:
false
Whether to enable source maps for CSS. Setting this to
true
may affect build performance.
#css.loaderOptions
Type:
Object
Default:
{}
Pass options to CSS-related loaders. For example:
module.exports = {
css: {
loaderOptions: {
css: {
// options here will be passed to css-loader
},
postcss: {
// options here will be passed to postcss-loader
}
}
}
}
Supported loaders are:
See also: Passing Options to Pre-Processor Loaders
TIP
This is preferred over manually tapping into specific loaders using
chainWebpack
, because these options need to be applied in multiple locations where the corresponding loader is used.
#devServer
Type:
Object
All options for
webpack-dev-server
are supported. Note that:Some values like
host
,port
andhttps
may be overwritten by command line flags.Some values like
publicPath
andhistoryApiFallback
should not be modified as they need to be synchronized with publicPath for the dev server to function properly.
#devServer.proxy
Type:
string | Object
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 invue.config.js
.devServer.proxy
can be a string pointing to the development API server:module.exports = {
devServer: {
proxy: 'http://localhost:4000'
}
}
This will tell the dev server to proxy any unknown requests (requests that did not match a static file) to
http://localhost:4000
.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 for full options:module.exports = {
devServer: {
proxy: {
'^/api': {
target: '<url>',
ws: true,
changeOrigin: true
},
'^/foo': {
target: '<other_url>'
}
}
}
}
#parallel
Type:
boolean
Default:
require('os').cpus().length > 1
Whether to use
thread-loader
for Babel or TypeScript transpilation. This is enabled for production builds when the system has more than 1 CPU cores.
#pwa
Type:
Object
Pass options to the PWA Plugin.
#pluginOptions
Type:
Object
This is an object that doesn't go through any schema validation, so it can be used to pass arbitrary options to 3rd party plugins. For example:
module.exports = {
pluginOptions: {
foo: {
// plugins can access these options as
// `options.pluginOptions.foo`.
}
}
}
#Babel
Babel can be configured via babel.config.js
.
TIP
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.
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.
Also see the Polyfills section in guide.
#ESLint
ESLint can be configured via .eslintrc
or eslintConfig
field in package.json
.
See @vue/cli-plugin-eslint for more details.
#TypeScript
TypeScript can be configured via tsconfig.json
.
See @vue/cli-plugin-typescript for more details.
#Unit Testing
#Jest
See @vue/cli-plugin-unit-jest for more details.
#Mocha (via mocha-webpack
)
See @vue/cli-plugin-unit-mocha for more details.
#E2E Testing
#Cypress
See @vue/cli-plugin-e2e-cypress for more details.
#Nightwatch
See @vue/cli-plugin-e2e-nightwatch for more details.
Configuration Reference In Vue CLI 3.0的更多相关文章
- @vue/cli 3.0 使用 svg-sprite-loader 加载本地 SVG 文件
目录 @vue/cli 3.0 使用 svg-sprite-loader 加载本地 SVG 文件 运行 使用 配置 svg-sprite-loader 调用当前环境下的颜色 props @vue/cl ...
- Vue CLI 3.0脚手架如何在本地配置mock数据
前后端分离的开发模式已经是目前前端的主流模式,至于为什么会前后端分离的开发我们就不做过多的阐述,既然是前后端分离的模式开发肯定是离不开前端的数据模拟阶段. 我们在开发的过程中,由于后台接口的没有完成或 ...
- 如何使用@vue/cli 3.0在npm上创建,发布和使用你自己的Vue.js组件库
译者按: 你可能npm人家的包过成千上万次,但你是否有创建,发布和使用过自己的npm包? 原文: How to create, publish and use your own VueJS Compo ...
- VUE CLI 3.0 安装及创建项目
一.安装 VUE CLI 3.0 官网: https://cli.vuejs.org/ 详细资料可以自己先把官网过一遍. 1. 安装(默认你的电脑上已安装node及npm) npm install ...
- Django + Vue cli 3.0 访问静态资源问题
[问题背景] 用Vue clie 3.0的搭建得框架把我坑死了,在打包后,调用不到静态资源js,css,mp3等 [问题原因] vue cli 3.0打包后,dist目录下没有static目录,而Dj ...
- 专访Vue作者尤雨溪:Vue CLI 3.0重构的原因
1.为什么要对 Vue CLI 进行大规模修改? 尤雨溪认为旧版本的 Vue CLI 本质上只是从 GitHub 拉取模版,这种拉模版的方式有几个问题: (1) 在单个模版里面同时支持太多选项会导致模 ...
- vue cli 4.0.5 的使用
vue cli 4.0.5 的使用 现在的 vue 脚手架已经升级到4.0的版本了,前两日vue 刚发布了3.0版本,我看了一下cli 4 和cli 3 没什么区别,既然这样,就只总结一下vue cl ...
- vue/cli 3.0脚手架搭建
在vue 2.9.6中,搭建vue-cli脚手架的流程是这样的: 首先 全局安装vue-cli,在cmd中输入命令: npm install --global vue-cli 安装成功: 安装完成 ...
- @vue/cli 4.0+express 前后端分离实践
之前总结过一篇vue-cli 2.x+express+json-server实现前后端分离的帖子,@vue/cli3.0及4.0搭建的项目与vue-cli2.x的项目结构有很大的不同.这里对@vue/ ...
随机推荐
- win10自带IE上不了网的解决办法
1.cmd以管理员身份运行powershell. 2.输入以下三条程序. netsh int tcp set heuristics disabled 回车执行后再输入 netsh int tcp se ...
- ScrollReveal.js 用于创建和管理元素进入可视区域时的动画效果,帮助你的网站增加吸引力。
ScrollReveal.js 用于创建和管理元素进入可视区域时的动画效果,帮助你的网站增加吸引力. 1.http://www.yangqq.com/jstt/css3/2017-08-08/787. ...
- Java中构造函数传参数在基本数据类型和引用类型之间的区别
Java中构造函数传参数在基本数据类型和引用类型的区别 如果构造函数中穿的参数为基本数据类型,如果在函数中没有返回值,在调用的时候不会发生改变:而如果是引用类型,改变的是存储的位置,所有不管有没有返回 ...
- unity中Android环境变量配置
http://www.cnblogs.com/windytrees/p/7533477.html
- weblogic threadpool has stuck threads
https://blog.csdn.net/wyx713510713/article/details/12705221 最近项目启动时出问题,weblogic的nohup日志文件中找到下面一段(红色部 ...
- DRDS 概述
DRDS 概述 更新时间:2017-08-04 13:53:50 分布式关系型数据库服务(Distributed Relational Database Service , 简称 DRDS ) ...
- Dede文章标题长度修改
方法一.首先你要进入dedecms后台,系统——系统基本参数——其他选项——文档标题最大长度——在这修改为200或更大(其实200应该是足够了). 方法二.进入phpmyadmin,点击dede_ar ...
- openstack(Pike 版)集群部署(四)--- Nova 部署
一.介绍 参照官网部署:https://docs.openstack.org/nova/pike/install/ 继续上一博客进行部署:http://www.cnblogs.com/weiji ...
- NumPy 切片和索引
NumPy 切片和索引 ndarray对象的内容可以通过索引或切片来访问和修改,与 Python 中 list 的切片操作一样. ndarray 数组可以基于 0 - n 的下标进行索引,切片对象可以 ...
- git 基本操作命令
1. git status 查看git 状态 2.git init 3.git push -u origin master 提交 4.git remote set "邮箱地址i" ...