Giter VIP home page Giter VIP logo

vite-vue-starter's Introduction

Vue 通用模板项目

介绍

初始化前端项目

npm create vite@latest

# customize
Need to install the following packages:
[email protected]
Ok to proceed? (y) y
✔ Project name: … pk-front-vue3
✔ Select a framework: › Vue
✔ Select a variant: › Customize with create-vue ↗
Need to install the following packages:
[email protected]
Ok to proceed? (y) y

Vue.js - The Progressive JavaScript Framework

✔ Add TypeScript? … Yes
✔ Add JSX Support? … Yes
✔ Add Vue Router for Single Page Application development? … Yes
✔ Add Pinia for state management? … Yes
✔ Add Vitest for Unit Testing? … Yes
✔ Add an End-to-End Testing Solution? › Cypress
✔ Add ESLint for code quality? … Yes
✔ Add Prettier for code formatting? … Yes

# install dep
cd pk-front-vue3
pnpm i

# git manage repo
git init
git add .
git commit -m "init"
# link with my github remote repo
git remote add origin https://github.com/BarryCoding/pk-front-vue3.git
git branch -M main
git push -u origin main
  • 清理资源文件
git add .
git commit -m "clear assets"
  • 安装 开发依赖 sass
  • 安装 依赖 reset-css
    • 会重置所有浏览器默认样式
pnpm i -D sass
# vite 会自动处理 sass, sfc 中测试

pnpm i reset-css
# main.js 引入

git add .
git commit -m "add scss & reset-css"

更新npm依赖的3种策略

  1. 自定义 手动更新 npm i -D package@version
  2. 借助 npm 工具 npm-check-updates
  3. git平台bot Dependabot

页面路由方案

自动路由 or 手写路由

Vue-Router

自动路由 vite-plugin-pages

  • recommend unplugin-vue-router

自动路由 unplugin-vue-router

  • follow instruction
  • pnpm i -D unplugin-vue-router
  • M vite.config.ts
  • M router/index.ts
    • 运行项目 会产出 type-router.d.ts 自动处理路由类型
    • M tsconfig 补充 type-router.d.ts
  • M .vscode/settings.json
  • U pages/index.vue
    • M .eslintrc.cjs 处理 组件命名

类型问题 4种解决思路

  • unplugin-vue-router 导致 TS 错误
    • first: reload or rerun
  1. 重载或重启项目
  2. 官方 issue
  3. 研究官方 example
  4. 使用 fit仓库的 CodeSpaces
    1. 2 core 60 hrs free
  5. StackOverflow

CSS框架方案 Tailwind or UnoCSS

官方文档 UnoCSS

自动导入 AutoImport + VueUse

  • 专业处理函数 自动导入

  • 安装 pnpm i -D unplugin-auto-import

  • 配置 vite.config.ts

    • dts: 'src/auto-imports.d.ts'
    • dts: 'src/typed-router.d.ts'
    • 项目核心类型定义 不放在根目录 而是都放在 src 中, 且不用改 tsconfig.app.json
    • 集成 unplugin-vue-router 替换原生 vue-router
    • 集成 VueUse 三方库
      • pnpm i @vueuse/core
      • 自定义导入需要的 USE

自动组件注册 unplugin-vue-components

  • 专业处理组件 自动导入

  • 安装 pnpm i -D unplugin-vue-components

  • 配置 vite.config.ts

    • dts: 'src/components.d.ts'

图标插件 unplugin-icons

  • 略过
  • tailwind 集成图标

图标方案 iconify sets

  • UnoCSS 集成图标
  • 安装 pnpm add -D @iconify/json
    • 所有图标集 包比较大
  • 配置 uno.config.ts
  • iconify图标集
    • 点图标 选UnoCSS 复制粘贴
  • 安装 pnpm install -D vite-plugin-vue-layouts
  • 配置 vite.config.ts
  • 补充 Client Types 到 env.d.ts
    • 等同 tsconfig compilerOptions.types 配置
  • 集成 unplugin-vue-router
  • 常见问题 layout 未生效 ->> 重启项目 pnpm dev
  • 添加 全局路由 渐变效果

VueMacros shamefully-hoist

  • 略过

  • VueMacros 部分已经被 Vue3.3官方支持

  • 安装集成 VueMacros

  • defineProps defineEmits

  • .npmrc

    • 调整顶层依赖顺序 公共依赖拍得更高 pnpm i

PWA技术 Service Worker介绍

  • 学习
  • XMind...
  • 调试模式 application

PWA集成 vite-plugin-pwa

  • Install pnpm add -D vite-plugin-pwa
  • Usage vite.config.ts
  • 文档
    • 补充 Type declaration
    • 略 registerType为'prompt' 需 ReloadPrompt 组件
    • registerType为'autoUpdate' 自动更新 无需 ReloadPrompt 组件
  • 查看PWA效果 脚本 build
    • 脚本 preview 运行 dist项目
    • 生产模式中 dist中具备pwa
    • 开发模式中 未具备pwa

接口模拟 vite-plugin-mock

  • 略过
  • 学全栈 就用真实数据库
  • Why Not msw

发布 github template 项目

  • 清理文件和目录
    • 自动生成的类型文件 集中存放 且 git忽略
  • pages 404 页面
  • layout [...path].vue 布局
    • 新布局文件 重启项目后生效

Vue版本更新 依赖更新策略

  • 查看 Vue更新日志
  • git 版本控制 新的分支处理 版本升级
    • git tag v1.0.0
    • git checkout -b vue3.4 v1.0.0
      • 从 tag v.1.0.0 创建 vue3.4 分支
      • 工具 npm-check-updates
        • 先处理 patch 更新
        • 再处理 minor 慎重更新 + 打包测试
        • 最后处理 major 慎重更新 + 打包测试
    • 处理好更新后 合并到 main 分支

Vue3.3更新了什么

  • defineModel
    • 3.3 experimental
    • 3.4 已经官方支持
  • TS泛型组件
  • defineSlots
  • defineProps

vite-vue-starter's People

Contributors

barrycoding avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.