VUE项目基础
大约 1 分钟
VUE项目基础
1.项目环境搭建
1.1安装vue-cli脚手架构建工具
vue-cli提供了一个官方命令行工具,可用于快速搭建大型单页应用
npm install -g @vue/cli
1.2查看脚手架工具
vue -V
1.3创建项目
vue create 项目名称
npm init vite@latest 项目名称
npm init vite@latest 项目名称
选用- vue
- Customize with create-vue
- Add TypeScript? › No / Yes
- Add JSX Support? › No / Yes
- Add Vue Router for Single Page Application development? › No / Yes
- Add Pinia for state management? › No / Yes
- Add Vitest for Unit Testing? › No / Yes
- Add an End-to-End Testing Solution? › - Use arrow-keys. Return to submit. ❯ No Cypress Nightwatch Playwright
- Add ESLint for code quality? › No / Yes
vue create 项目名称
选用Please pick a preset: (Use arrow keys)
- Default ([Vue 3] babel, eslint)
- Default ([Vue 2] babel, eslint)
- Manually select features
Check the features needed for your project: (Press <space> to select, <a> to toggle all, <i> to invert selection, and <enter> to proceed)
- ◉ Babel
- ◯ TypeScript
- ◯ Progressive Web App (PWA) Support
- ◉ Router
- ◉ Vuex
- ◯ CSS Pre-processors
- ◯ Linter / Formatter
- ◯ Unit Testing
- ◯ E2E Testing
Choose a version of Vue.js that you want to start the project with (Use arrow keys)
- 3.x
- 2.x
Use history mode for router? (Requires proper server setup for index fallback in production) (Y/n) n
Where do you prefer placing config for Babel, ESLint, etc.? (Use arrow keys)
- In dedicated config files
- In package.json
Save this as a preset for future projects? (y/N) n
2.配置默认端口
// vue.config.js
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true,
devServer:{
port:8082,
host:'localhost',
open:true
}
})