用vite来搭建vue3.0的项目

553 阅读1分钟

1.用vite开始搭建项目

(1)创建项目的命令:

//npm
npm init @vitejs/app

//yarn
yarn create @vitejs/app

// 创建项目示例
npm init @vitejs/app [project-name]
yarn create @vitejs/app [project-name]

//下载node_modules  
yarn

(2)创建vue3项目

选择创建vue项目,由于项目的不熟练,先选择非ts版本的vue项目,最后按下回车键就下载完成了。

(3)安装node_moudles

yarn

(4)安装我们开发需要的依赖包

//下载依赖
//开发依赖
yarn add vue-router@next vuex@next element-plus axios -S
//生产依赖
yarn add sass -D

//删除依赖(只是展示一下命令,并不需要去操作)
yarn remove vue-router@next vuex@next element-plus axios
yarn remove sass

(5)在package.json文件里面判断是否按照成功

{
  "name": "vuevite",
  "version": "0.0.0",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "serve": "vite preview"
  },
  "dependencies": {
    "axios": "^0.21.1",
    "element-plus": "^1.0.2-beta.70",
    "vue": "^3.0.5",
    "vue-router": "^4.0.11",
    "vuex": "^4.0.2"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^1.3.0",
    "@vue/compiler-sfc": "^3.0.5",
    "sass": "^1.37.5",
    "vite": "^2.4.4"
  }
}

2.注意事项

在vite.config.js里面配置项目的参数,类似于vue.config.js