用vue-cli4 从0搭建一个H5项目

626 阅读2分钟

 

使用@vue/cli4创建项目

全局安装vue cli 脚手架

npm install -g @vue/cli
vue -V

创建vue项目

vue create <projectName>

选择自定义配置

> Manually select features
? Check the features needed for your project: (Press <space> to select, <a> to toggle all, <i> to invert selection)
>
(*) Babel
(*) TypeScript
(*) Progressive Web App (PWA) Support
(*) Router
(*) Vuex
(*) CSS Pre-processors
(*) Linter / Formatter
( ) Unit Testing
( ) E2E Testing

自定义配置说明

序号选项描述
1Choose Vue version选择Vue版本
2Babelvue项目中普遍使用es6语法,但有时我们的项目需要兼容低版本浏览器,这时就需要引入babel插件,将es6转成es5
3TypeScriptTypeScript通过添加类型来扩展JavaScript。通过了解JavaScript,TypeScript可以节省您捕获错误的时间并在运行代码之前提供修复。任何浏览器,任何操作系统,任何运行JavaScript的地方。 完全开源
4Progressive Web App (PWA) Support渐进式Web应用程序(PWA)支持
5Router路由
6VuexVuex 是一个专为 Vue.js 应用程序开发的状态管理模式。它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化
7CSS Pre-processorsCSS预处理器,预处理器:比如要用sass或者cssNext就要按照人家规定的语法形式,就是用人家的语法去编写,然后人家把你编写的代码转成css。
8Linter / Formatter格式化程序
9Unit Testing单元测试
10E2E Testing端到端测试(end-to-end)

选择自定义配置的选项

配置选项说明

序号配置选项描述
1Choose a version of Vue.js that you want to start the project with 3.x选择vue版本
2Use class-style component syntax? Yes是否使用class风格的组件语?
3Use Babel alongside TypeScript (required for modern mode, auto-detected polyfills, transpiling JSX)? Yes要不要使用 babel 工具自动为转换后的 TypeScript 代码注入 polyfiills
4Use history mode for router? (Requires proper server setup for index fallback in production) Yes是不是用history模式来创建路由
5Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Less询问项目的CSS预处理器
6Pick a linter / formatter config: Prettier项目的格式校验方式
7Pick additional lint features: Lint on save1、保存时 2、提交时项目的什么时候校验格式
8Where do you prefer placing config for Babel, ESLint, etc.? In dedicated config files1、独立文件 2、package项目的配置文件放在哪儿?
9Save this as a preset for future projects? No是否作为一个模板配置

引入UI组件

引入 vant

引入axios

引入常用工具