We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
npm install -g @vue/cli # OR yarn global add @vue/cli
先安装一个全局的扩展
npm install -g @vue/cli-service-global
使用
Usage: serve [options] [entry] 在开发环境模式下零配置为 .js 或 .vue 文件启动一个服务器 Options: -o, --open 打开浏览器 -c, --copy 将本地 URL 复制到剪切板 -h, --help 输出用法信息
例如对于一个 demo.vue 文件,在该目录下运行 vue serve demo.vue 即可快速查看效果
demo.vue
vue serve demo.vue
运行
用法:vue create [options] <app-name> 创建一个由 `vue-cli-service` 提供支持的新项目 选项: -p, --preset <presetName> 忽略提示符并使用已保存的或远程的预设选项 -d, --default 忽略提示符并使用默认预设选项 -i, --inlinePreset <json> 忽略提示符并使用内联的 JSON 字符串预设选项 -m, --packageManager <command> 在安装依赖时使用指定的 npm 客户端 -r, --registry <url> 在安装依赖时使用指定的 npm registry -g, --git [message] 强制 / 跳过 git 初始化,并可选的指定初始化提交信息 -n, --no-git 跳过 git 初始化 -f, --force 覆写目标目录可能存在的配置 -c, --clone 使用 git clone 获取远程预设选项 -x, --proxy 使用指定的代理创建项目 -b, --bare 创建项目时省略默认组件中的新手指导信息 -h, --help 输出使用帮助信息
然后根据需要按提示选择对应的功能即可
package.json 里
package.json
{ "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build" } }
用法:vue-cli-service serve [options] [entry] 选项: --open 在服务器启动时打开浏览器 --copy 在服务器启动时将 URL 复制到剪切版 --mode 指定环境模式 (默认值:development) --host 指定 host (默认值:0.0.0.0) --port 指定 port (默认值:8080) --https 使用 https (默认值:false)
用法:vue-cli-service build [options] [entry|pattern] 选项: --mode 指定环境模式 (默认值:production) --dest 指定输出目录 (默认值:dist) --modern 面向现代浏览器带自动回退地构建应用 👍 --target app | lib | wc | wc-async (默认值:app) --name 库或 Web Components 模式下的名字 (默认值:package.json 中的 "name" 字段或入口文件名) --no-clean 在构建项目之前不清除目标目录 --report 生成 report.html 以帮助分析包内容 --report-json 生成 report.json 以帮助分析包内容 --watch 监听文件变化
可通过下列文件来指定环境变量:
.env # 在所有的环境中被载入 .env.local # 在所有的环境中被载入,但会被 git 忽略 .env.[mode] # 只在指定的模式中被载入 .env.[mode].local # 只在指定的模式中被载入,但会被 git 忽略
文件内容是“键=值”对 eg:
FOO=bar VUE_APP_SECRET=secret
默认情况下,一个 Vue CLI 项目有三个模式:
除 NODE_ENV 和 BASE_URL 外,以 VUE_APP_ 开头的变量会被 webpack.DefinePlugin 静态嵌入到客户端侧的包中,这样可以在代码中使用它们:
NODE_ENV
BASE_URL
console.log(process.env.VUE_APP_SECRET)
The text was updated successfully, but these errors were encountered:
https://cli.vuejs.org/zh/guide/cli-service.html#git-hook
https://cli.vuejs.org/zh/guide/browser-compatibility.html#polyfill
// vue.config.js module.exports = { pages: { index: { // page 的入口 entry: 'src/index/main.js', // 模板来源 template: 'public/index.html', // 在 dist/index.html 的输出 filename: 'index.html', // 当使用 title 选项时, // template 中的 title 标签需要是 <title><%= htmlWebpackPlugin.options.title %></title> title: 'Index Page', // 在这个页面中包含的块,默认情况下会包含 // 提取出来的通用 chunk 和 vendor chunk。 chunks: ['chunk-vendors', 'chunk-common', 'index'] }, // 当使用只有入口的字符串格式时, // 模板会被推导为 `public/subpage.html` // 并且如果找不到的话,就回退到 `public/index.html`。 // 输出文件名会被推导为 `subpage.html`。 subpage: 'src/subpage/main.js' } }
Sorry, something went wrong.
该配置只在开发环境有效,具有类似Nginx的反向代理的功能,并提供以下功能:
当你的前端应用和后端 API 服务器没有运行在同一个主机上,你需要在开发环境下将 API 请求代理到 API 服务器(为了避免浏览器的同源策略问题)
module.exports = { devServer: { proxy: { '/api': { target: '<url>', ws: true, changeOrigin: true }, '/foo': { target: '<other_url>' } } } }
详细配置看文档
https://github.com/chimurai/http-proxy-middleware#proxycontext-config https://webpack.js.org/configuration/dev-server/ https://cli.vuejs.org/zh/config/#devserver-proxy
No branches or pull requests
安装
vue serve 快速原型开发
先安装一个全局的扩展
使用
例如对于一个
demo.vue
文件,在该目录下运行vue serve demo.vue
即可快速查看效果创建一个项目
运行
然后根据需要按提示选择对应的功能即可
CLI服务
package.json
里运行项目
构建项目
静态资源
何时使用 public 文件夹
环境变量和模式
环境变量
可通过下列文件来指定环境变量:
文件内容是“键=值”对 eg:
模式 mode
默认情况下,一个 Vue CLI 项目有三个模式:
在客户端侧代码中使用环境变量
除
NODE_ENV
和BASE_URL
外,以 VUE_APP_ 开头的变量会被 webpack.DefinePlugin 静态嵌入到客户端侧的包中,这样可以在代码中使用它们:The text was updated successfully, but these errors were encountered: