安装了最新的Vue CLI。打开Terminal,输入: npm install -g @vue/cli
or yarn global add @vue/cli
vue
使用-V来查看刚刚安装的版本: vue -V 3.0.0-rc.10
webpack
更新vue-cli以后,以前的2.0版本的构建方式就不可用了 须要再下载git
yarn global add @vue/cli-init
github
初始化Vue UI,在一个干净的目录下输入:web
vue ui
vue-router
该命令自动打开浏览器,显示以下界面vuex
添加新项目有两种方式vue-cli
可视化添加npm
若是保存过自定义项目配置,开始建立时,会在第一个选项显示;配置的选项会同步到vue.config.js
这个文件中json
点击建立项目以后,能够保存这次配置,在之后建立项目时使用相同配置
跳过这次步骤,开始下载相关插件,此时命令行同步下载,可视化工具经过操控命令行来新建项目
vue create <project-name>
? Please pick a preset: (Use arrow keys)
❯ my-test (vue-router, vuex, sass, babel, eslint)
default (babel, eslint)
Manually select features
? Check the features needed for your project: (Press <space> to select, <a> to t
oggle all, <i> to invert selection)
❯◉ Babel
◯ TypeScript
◯ Progressive Web App (PWA) Support
◯ Router
◯ Vuex
◯ CSS Pre-processors
◉ Linter / Formatter
◯ Unit Testing
◯ E2E Testing
? Check the features needed for your project: Babel, Router, Vuex, CSS Pre-proce
ssors, Linter
? Use history mode for router? (Requires proper server setup for index fallback
in production) No
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported
by default): SCSS/SASS
? Pick a linter / formatter config: Prettier
? Pick additional lint features: (Press <space> to select, <a> to toggle all, <i
> to invert selection)
❯◉ Lint on save
◯ Lint and fix on commit
? Pick additional lint features: Lint on save
? Where do you prefer placing config for Babel, PostCSS, ESLint, etc.? In packag
e.json
? Save this as a preset for future projects? (y/N) n
复制代码
按下空格键进行选取
Vue CLI v3.0.0-rc.10
✨ Creating project in /Users/zjy/ttt.
🗃 Initializing git repository...
⚙ Installing CLI plugins. This might take a while...
yarn install v1.0.1
info No lockfile found.
[1/4] 🔍 Resolving packages...
⠐ @babel/highlight@7.0.0-beta.47
复制代码
开始构建项目
安装完成以后,能够查看项目下安装的插件,能够添加其余插件
查看项目依赖的资源,能够直接查看相关官网或源码
可对项目进行配置,配置的选项会在vue.config.js中
能够本地调试,打包,
对项目进行性能分析
少了不少文件夹,目录结构更加清晰,vue-cli2.0中的build,config统一到了vue.config.js中 移除了static文件夹,添加了public Src中添加了views文件夹,用来存放视图组件,components中存放公共组件
参考文档:配置文档
module.exports = {
baseUrl: '/',
outputDir: 'dist',
lintOnSave: true,
compiler: false,
// 调整内部的 webpack 配置。
// 查阅 https://github.com/vuejs/vue-doc-zh-cn/vue-cli/webpack.md
chainWebpack: () => {},
configureWebpack: () => {},
// 配置 webpack-dev-server 行为。
devServer: {
open: process.platform === 'darwin',
host: '0.0.0.0',
port: 8080,
https: false,
hotOnly: false,
// 查阅 https://github.com/vuejs/vue-doc-zh-cn/vue-cli/cli-service.md#配置代理
proxy: null, // string | Object
before: app => {}
}
....
}
复制代码