1. 安装node.js(node.js下载地址)
2. 全局安装vue-cli最新版本
npm install -g @vue/cli
安装成功后,可以通过 vue -V 查看下载的@vue/cli版本号。我使用的是@vue/cli 4.5.13
3.创建项目
vue create <project name>
项目名称要避开特殊名字如echarts、vue等,接下来就是配置选择,具体如下:
- Manually select features (自定义配置)
Default ([Vue 3] babel, eslint):默认预设配置,会快速创建一个Vue3.0项目,提供了babel和eslint支持
Default ([Vue 2] babel, eslint):默认预设配置,会快速创建一个Vue2.0项目,提供了babel和eslint支持
Manually select features:手动配置项目,可根据项目的需要选择合适的选项,具备更多的选择性
- Check the features needed for your project (根据自己的需求添加配置项)
Babel:使用Babel将源码进行转码(把ES6=>ES5)
TypeScript:使用TypeScript进行源码编写。使用TypeScript可以编写强类型JavaScript
Progressive Web App (PWA) Support:使用渐进式Web应用程序
Router:使用Vue路由
Vuex:使用Vuex状态管理器
CSS Pre-processors:CSS 预处理器(如:less、sass)
Linter / Formatter:使用代码风格检查和格式化(如:ESlint)
Unit Testing:使用单元测试(unit tests)
E2E Testing:使用E2E(end to end)黑盒测试
- Choose a version of Vue.js that you want to start the project with
选择项目版本
- Use class-style component syntax
是否使⽤Class(类)风格装饰器, 即通过export default class Home extends Vue{} 创建Vue实例
- Use Babel alongside TypeScript (required for modern mode, auto-detected polyfills, transpiling JSX) 使⽤Babel做转义, 与TypeScript⼀起⽤于⾃动检测
- Use history mode for router?
路由模式, 是否选择history模式,启⽤history模式,项⽬build之后,可能会出现打开页⾯空⽩的情况哦
- Pick a CSS pre-processor?
选择⼀种css 预处理器, 在这⾥我选择less
node-sass 是用 node(调用 cpp 编写的 libsass)来编译 sass;
dart-sass 是用 drat VM 来编译 sass;
node-sass是自动编译实时的,dart-sass需要保存后才会生效
推荐 dart-sass 性能更好(也是 sass 官方使用的),而且 node-sass 因为经常装不上
- Pick a linter / formatter config?
选择⼀种代码格式化检测⼯具
TSLint: ts格式检验⼯具
ESLint with error prevention only: ESLint 只会进⾏错误提醒
ESLint + Airbnb config: ESLint Airbnb标准
ESLint + Standard config: ESLint Standard 标准
ESLint + Prettier: ESLint(代码质量检测)+ Prettier(代码格式化⼯具)
- Pick additional lint features?
代码检查⽅式: 保存时检查 / 提交时检查; 我一般习惯保存时检查
- Where do you prefer placing config for Babel,ESLint, etc.?
选择配置文件保存在哪里,选package.json文件里
- Save this as a preset for future projects?
是否将这次的配置设置为之后项目的预设模式