- 安装vue-cli
npm install vue/cli -g
-
查看vue版本
注意:V要大写
vue -V
- 如果下载速度太慢,可以使用cnpm淘宝镜像
npm install -g cnpm --registry=https://registry.npm.taobao.org
此时下载出来的应该是2.9.6版本的脚手架
vue项目创建分为两种
- vue-cli2
vue init webpack name
- vue-cli3
vue create name
一.CLI2
vue init webpack font-admin
提示 | 含义 - 操作 |
---|---|
Project name (font-admin) | 项目名称 - 直接回车即可 |
Project description (A Vue.js project) | 项目介绍 - 直接回车即可 |
Author (xxx <xxxxx.com>) | 作者 - 回车即可 |
Vue build | 项目构建 - 推荐使用第一个/运行加编译 |
Install vue-router? (Y/n) | 是否使用router路由-y |
Use ESLint to lint your code? (Y/n) | 是否开启ESLint检查模式 - 根据需求y/n |
Set up unit tests (Y/n) | 是否开启单元测试-根据需求,一般为n |
? Setup e2e tests with Nightwatch? (Y/n) | 使用设置e2e测试?- e2e单元测试不需要n |
Should we run npm install for you after the project has been created? (recommended) (Use arrow keys) |
依赖包管理方式-根据需求使用npm或者yarn |
项目创建完成后 cd 项目名进入项目并启动,在浏览器打开即成功 :
npm run dev
项目初始化完成后目录:
二.CLI3
vue create name
如果cli的版本低于3.0会提示:
vue create is a Vue CLI 3 only command and you are using Vue CLI 2.9.6.
You may want to run the following to upgrade to Vue CLI 3:
npm uninstall -g vue-cli
npm install -g @vue/cli
按照提示安装新版本的cli即可
提示 | 含义 - 操作 |
---|---|
Please pick a preset: (Use arrow keys) | 项目构建预设 - 根据自己选择,我选择最后一个手动配置 |
之后根据自己项目需求用空格选择后回车确认,
TypeScript 支持使用 TypeScript 书写源码
Progressive Web App (PWA) Support PWA 支持。
Router 支持 vue-router 。
Vuex 支持 vuex 。
CSS Pre-processors 支持 CSS 预处理器。
Linter / Formatter 支持代码风格检查和格式化。
Unit Testing 支持单元测试。
E2E Testing 支持 E2E 测试。
选择出去后:
提示 | 含义 - 操作 |
---|---|
Choose a version of Vue.js that you want to start the project with | vue版本 - 2.x |
Where do you prefer placing config for Babel, ESLint, etc.? | eslint/babel的配置方式,第一个为专门配置文件,第二个为在package.json里面配置-我选择第一个 |
Save this as a preset for future projects? (y/N) | 是否存储此配置- 看需求,存储 |
Save preset as | 存储名 - 自定义 |
Pick the package manager to use when installing dependencies: (Use arrow keys) | 依赖包管理方式-根据需求使用npm或者yarn |
之后运行项目:
npm run serve
或者
yarn serve
vue-cli3创建出来的项目目录: