Giter VIP home page Giter VIP logo

dishait / tov-template Goto Github PK

View Code? Open in Web Editor NEW
807.0 8.0 201.0 3.33 MB

vite + vue3 + ts 开箱即用现代开发模板 | vite + vue3 + ts out-of-the-box modern development template

Home Page: https://tov-template.netlify.app

License: MIT License

HTML 0.62% TypeScript 53.28% Vue 22.57% CSS 4.86% Shell 0.12% JavaScript 17.17% Handlebars 1.38%
vite vue3 ts template modern vue starter unocss

tov-template's Introduction


帝莎编程 https://pc.dishait.cn/

vite + vue3 + ts 开箱即用现代开发模板



特点 🐳

  1. Vite 的
  2. Vue3 的
  3. 文件路由
  4. 布局系统
  5. Mock 支持
  6. Api 自动引入
  7. 组件自动引入
  8. 图标自动引入
  9. VueUse 支持
  10. TypeScript 的
  11. UnoCss 的
  12. 暗黑模式支持
  13. SWR 请求支持
  14. pinia 状态管理
  15. pnpm 包管理器
  16. 跳转进度条支持
  17. 开发面板支持
  18. 插件自动加载支持
  19. Vitest 单元测试支持
  20. 支持 Markdown 渲染
  21. 路径别名支持
  22. 命令行自动创建与删除
  23. i18n 国际化支持
  24. 漂亮的 404 页 支持
  25. tsx 支持
  26. gzip 资源压缩支持
  27. 环境变量配置支持
  28. 统一的代码规范与风格支持
  29. 生产环境自动移除开发日志
  30. defineOptions 支持
  31. echarts 支持
  32. 全局通用 toast 通知
  33. 全局通用 axios 请求封装
  34. 自动生成环境变量类型声明
  35. renovate 自动更新依赖
  36. 自动版本更新并生成 CHANGELOG
  37. 最快最小的 dockerfile 静态 go 服务
  38. base 安全的路径解析
  39. lightningcss 支持
  40. vite 配置层支持 (实验性)


克隆模板 🦕

  1. Github
git clone [email protected]:dishait/tov-template.git
  1. Gitee
git clone [email protected]:dishait/tov-template.git
  1. degit
npx degit https://github.com/dishait/tov-template#main
  1. 新的 Github 仓库 👉 Use this template



node 版本推荐 🐎

因为该模板完全面向现代,所以推荐大家使用 node 当前的长期维护版本 v20




使用 🐂

该模板仅支持 pnpm 包管理器 👉 安装教程

  1. 安装依赖
pnpm install
  1. 开发
pnpm dev

# 开启 host
pnpm dev:host

# 自动打开浏览器
pnpm dev:open
  1. 预览
pnpm preview

# 开启 host
pnpm preview:host

# 自动打开浏览器
pnpm preview:open
  1. 打包
pnpm build

pnpm build:debug
  1. 单元测试
pnpm test
  1. 单元测试报告生成
pnpm coverage
  1. 类型检查
pnpm typecheck
  1. 自动创建
pnpm auto:create
  1. 自动移除
pnpm auto:remove
  1. 依赖更新
# 依赖版本更新
pnpm deps:fresh
# 以上命令仅对包信息 package.json 进行写入,需要重新执行包安装命令
pnpm i
  1. 代码规范校验
pnpm lint

# 校验时修复
pnpm lint:fix
  1. 安全初始化
pnpm safe:init


动机 🐗

为什么要做这个 模板 呢?

  1. 为下次开发节省浪费在配置上的时间
  2. 结合主流插件整合现代开发架构,提高开发效率


使用场景 🐻

什么时候你应该用?

  1. 不想浪费时间在项目配置上
  2. 希望尝试用更现代的方式开发 web 应用,提高开发效率


启发 🐃

该模板受 vitesse 启发,如果你有 SSG 的场景,推荐你使用 vitesse



组织 🦔

欢迎关注 帝莎编程



详情 🐳

该模板采用 vite 作为构建工具,你可以在根目录下的 vite.config.ts 对项目的构建进行配置。

对于众多主流插件的引入和繁杂配置已经整合到根目录下的预设 presets 中,大多数情况下你是不需要重新对它们进行配置的。



目录结构即路由。

eg:

  • src/pages/index.vue => /
  • src/pages/about.vue => /about
  • src/pages/users/index.vue => /users
  • src/pages/users/profile.vue => /users/profile
  • src/pages/users/[id].vue => /users/:id
  • src/pages/[user]/settings.vue => /:user/settings
  • src/pages/[...notFound].vue => 404 路由

具体可见 👉 unplugin-vue-router


默认布局

src/layouts/default.vue 将作为默认布局。

<!-- src/layouts/default.vue -->
<template>
	我是默认布局
	<router-view />
	<!-- 页面视图出口 -->
</template>

此时 src/pages/index.vue

<!-- src/pages/index.vue -->
<template>
	<div>我是首页</div>
</template>

路由到 /时,页面将渲染

我是默认布局 我是首页

此时 src/pages/about.vue

<!-- src/pages/about.vue -->
<template>
	<div>我是关于页</div>
</template>

路由到 /about 时,页面将渲染

我是默认布局 我是关于页

非默认布局

随便创建一个 src/layouts/custom.vue

<!-- src/layouts/custom.vue -->
<template>
	我是非默认布局custom
	<router-view />
	<!-- 页面视图出口 -->
</template>

此时 src/pages/index.vue

<!-- src/pages/index.vue -->
<template>
	<div>我是首页</div>
</template>

<!-- 添加自定义块 👇 -->
<route lang="json">
{
	"meta": {
		"layout": "custom"
	}
}
</route>

此时路由到 /, 页面将渲染

我是非默认布局custom 我是首页

具体可见 👉 vite-plugin-vue-meta-layouts


在根目录下的 mock 目录下,可以在模块中导出默认的 api 资源。

例如 mock/test.ts 内导出

import { MockMethod } from "vite-plugin-mock";
export default [
  {
    url: "/api/mock/get",
    method: "get",
    response: () => {
      return {
        code: 0,
        data: {
          name: "vben",
        },
      };
    },
  },
] as MockMethod[];

src 中就可以进行模拟请求。

<script setup lang="ts">
	import { useRequest } from 'vue-request'
	// 请求接口 /api/get
	const { data, loading, error } = useRequest('/api/mock/get')
</script>

<template>
	<div>data: {{data}}</div>
	<div>loading: {{loading}}</div>
	<div>error: {{error}}</div>
</template>

这里用到 vue-request 去做请求,不过因为该 mock 拦截的是一整个接口,所以换成 axios 等请求库也是可以的。

更多 mock 设置可见 👉 vite-plugin-mock


原本 vueapi 需要自行 import

import { computed, ref } from "vue";
const count = ref(0);
const doubled = computed(() => count.value * 2);

现在可以直接使用。

const count = ref(0);
const doubled = computed(() => count.value * 2);

而且上边的 api 是按需自动引入的。

目前模板支持自动引入 api 的库列表 👉

  • vue
  • vuex
  • pinia
  • vue-i18n
  • vue-router
  • @vueuse/core
  • @vueuse/head
  • @vueuse/math

只要确保已经安装依赖即可,具体可见 👉 vite-auto-import-resolvers

当然还有项目中的自动引入,只需要满足以下规范即可。

  1. src/composables 的导出将被按需自动引入。

例如有个 src/composables/foo.ts

// default 导出
export default 1000;

此时就不再需要 import

<script setup lang="ts">
	console.log(foo) // 输出 1000
</script>

<template>
	<div @click="store.inc()">{{store.counter}}</div>
</template>
  1. src/stores 的导出将被按需自动引入。

例如有个 src/stores/counterStore.ts

// default 导出
export default defineStore("counter", {
  state() {
    return {
      counter: 1,
    };
  },
  actions: {
    inc() {
      this.counter++;
    },
  },
});

此时就不再需要 import

<script setup lang="ts">
	const store = counterStore()
</script>

<template>
	<div @click="store.inc()">{{store.counter}}</div>
</template>
  1. src/api 也是自动按需导入,与上述类似

具体可见 👉 unplugin-auto-import


原来需要 import

<!-- src/pages/index.vue -->
<script setup lang="ts">
	import Hello from '../components/Hello.vue'
</script>

<template>
	<Hello />
</template>

现在只要在 src/components 下定义的组件都将会按需引入,即 import 是不需要的。

<!-- src/pages/index.vue -->
<template>
	<Hello />
</template>

当然也支持嵌套组件,例如 src/components/foo/bar.vue 👇

<!-- src/pages/index.vue -->
<template>
	<FooBar />
</template>

同时流行组件库自动引入也是支持的,例如 Naive ui

只需安装依赖。

pnpm add naive-ui

即可在模板中使用。

<!-- src/pages/index.vue -->
<template>
	<n-button type="success">Success</n-button>
</template>

目前支持的组件库有:

具体可见 👉 unplugin-vue-components


可前往 👉 icones,随意选择点击进入其中一个图标库

icons-first-step

再点击选择其中一个喜欢的图标

icons-second-step

复制其名称

icons-second-step

在模板中即可通过 class 的方式直接使用,注意加上前缀 i-

<template>
	<div class="i-mdi:account-box-multiple"></div>
</template>

保存后等待自动下载该图标库后,就可以在页面中看到对应图标。

同时推荐你使用 vscode 插件 Iconify IntelliSense

该插件会在模板中显示图标的预览。

当然图标动态加载也是支持的 👇

<script>
	const icon = ref("i-ep:arrow-left")

	// 两秒后换成另一个图标
	setTimeout(() => {
		icon.value = 'i-icon-park-outline:arrow-circle-down'
	}, 2000)
</script>

<template>
	<div :class="icon"></div>
</template>

注意动态图标,请确保在开发环境下所有的图标都测过一遍。

具体可见 👉 unocss/presets/icons


VueUse 是一个超级强的 hooks 库,例如你要获取鼠标位置,只需要这样 👇

<script setup lang="ts">
	// useMouse 被自动按需引入了,不需要import
	const { x, y } = useMouse()
</script>

<template>
	<div>x坐标 {{x}}</div>
	<div>y坐标 {{y}}</div>
</template>

具体可见 👉 VueUse


不需要重新配置,直接用 ts 书写就行了。


unocss 是一个开发中速度更快的 原子css 库。

直接在模板中用就行了,不需要配置。

<template>
	<div class="bg-red-500 text-white">我是红色背景的白色文本</div>
</template>

上述模板将渲染红色背景白色的字。

同时支持 属性化模式,即可以用简写。

<template>
	<div text="white" bg="red-500">我是红色背景的白色文本</div>
</template>

这在调整边距尺寸以及等方面可以减少代码量。

具体可见 👉 unocss


暗黑模式由 vue-dark-switch 实现。

<script setup>
import { SwitchIcon } from "vue-dark-swicth"
</script>

<template>
	<!-- 暗黑 switch,一键切换暗黑模式 -->
	<SwitchIcon /> 
</template>

具体可见 👉 vue-dark-switch


SWR 是更现代的请求方式,具体可见文章 👉 SWR

vue-request 是一个 SWRVue 版本请求库。

你可以这样用,例如请求 /api/test

<script setup lang="ts">
	import { useRequest } from 'vue-request'
	const { data, loading, error } = useRequest('/api/test')
</script>

<template>
	<div>data: {{data}}</div>
	<div>error: {{error}}</div>
	<div>loading: {{loading}}</div>
</template>

所有基本的数据,状态和缓存都帮你搞定了,不需要重新封装。

具体可见 👉 vue-request


pinia 是下一代的状态管理库,比 vuex 更简单,ts 支持更好。

你可以在 src/stores 中进行状态的定义。

例如创建 src/stores/counter.ts 👇

// src/stores/counter.ts
import { defineStore } from "pinia";

export const useCounterStore = defineStore("counter", {
  state() {
    return { count: 0 };
  },
  actions: {
    inc() {
      this.count++;
    },
  },
});

定义完后在 setup 中直接使用即可

<!-- src/pages/index.vue -->
<script setup lang="ts">
    const Counter = useCounterStore()
<script>

<template>
    <div @click="Counter.inc">{{Counter.count}}</div>
</template>

更多具体使用可见 👉 pinia


pnpm 是非常优秀的包管理器,更快、更节省空间、更合理。

具体可见 👉 pnpm


跳转进度条由 nprogress 实现,可在src/styles/main.css 中调整配色。

/** src/styles/main.css **/

/** 省略其他样式 **/
#nprogress .bar {
	@apply bg-blue-700 bg-opacity-75; /** 配色 **/

	position: fixed;
	z-index: 1031;
	top: 0;
	left: 0;

	width: 100%;
	height: 2px;
}

关于 @apply@unocss/transformer-directives 实现。

具体可见 👉 nprogress


该面板可以让你在开发过程中,了解项目的方方面面,目前仅在开发环境下有效

具体可见 👉 vite-plugin-vue-devtools


只需要在 src/plugins 中的模块里导出默认函数即可。

例如 pinia,只需要这样做。

// src/plugins/pinia.ts
// 导出 default 接口
export default createPinia(); // pinia 将被自动安装

或者 vue-router

// src/plugins/router.ts
// 省略各种配置

// 导出 default 接口
export default router; // 路由将被自动安装

当然 piniavue-router 已经预设好了,你不需要重新关注他们。

具体可见 👉 vite-plugin-use-modules


src/test 目录中可以书写单元测试。

import { assert, describe, expect, it } from "vitest";

describe("suite name", () => {
  it("foo", () => {
    expect(1 + 1).toEqual(2);
    expect(true).to.be.true;
  });

  it("bar", () => {
    assert.equal(Math.sqrt(4), 2);
  });

  it("snapshot", () => {
    expect({ foo: "bar" }).toMatchSnapshot();
  });
});

然后在终端中输入命令即可测试

pnpm test

或者生成报告

pnpm coverage

具体可见 👉 Vitest


markdown 渲染可以用来书写一些简单的说明。

只需要把 src/pages 目录下的页面后缀由 .vue 改为 .md,然后再改为 markdown 语法即可。

例如 src/pages/about.md

## About Page

> The page is markdown file

当你路由到 /about 后即可看到对应的 markdown 渲染。

当然也支持在 markdown 中嵌入 vue 组件

具体可见 👉 unplugin-vue-markdown



21. 路径别名支持

~ 或者 @ 路径将被导向项目的 src 目录,同时有更好的类型提示

<!-- src/pages/index.vue -->
<script lang="ts" setup>
	import { useDarks } from '~/composables/dark'

	// 等价于
	// import { useDarks } from "../composables/dark"
</script>


22. 命令行自动创建与删除

只要输入 👇,即可创建一个标准的页面或组件

pnpm auto:create

当然也可以进行删除 👇

pnpm auto:remove


在日常的业务当中,可能会存在一些需要国际化的场景。那么只需要在根目录下的 locales 中定义不同语言的 yml 即可在项目中做到开箱即用的国际化支持。

比如 locales/en.yml 中用来定义需要国际化支持的英文内容。

# locales/en.yml
# English

index: index
about: about
not-found: Notfound

又如 locales/简体中文.yml 中用来定义需要国际化支持的中文内容。

# locales/简体中文.yml
# 中文

index: 主页
about: 关于
not-found: 未找到页面

此时在组件中即可这样用 👇

<script setup>
	// 该api是全局按需引入的,所以可以直接用
	// t 用来绑定特定的语块
	const { t, locale } = useI18n()

	const toggleLocale = () => {
		// locale.value 用来表示当前所属语言,可修改进行语言切换
		locale.value = locale.value === '简体中文' ? 'en' : '简体中文'
	}
</script>

<template>
	<div m="6" cursor="pointer" @click="toggleLocale()">
		language: {{ t('index') }} click me!!
	</div>
</template>

更详细的说明可见用到的 vite 插件 👉 @intlify/vite-plugin-vue-i18nvue插件 vue-i18n

另外 yml 是目前前端中流行的配置文件格式,语法可见阮一峰先生的 👉 YAML 语言教程

vscode 插件推荐:



24. 漂亮的 404 页支持

在日常业务中,当用户访问不存在的页面时,应该给到我们的用户一个不存在的信息提示,而这个提示的页面就是 404 页。

你可以随便访问一个不存在的页面,例如 /bucunzai

notFound

当然还有暗黑模式适应。

notFound-dark

也支持简单的响应式适应。例如移动端浏览器上会有正确的显示。

当然如果这个 404 的封面不符合你的口味,那么可以在 pages/[...notFound].vue 中修改 img 标签的 src。默认是 32.svg,支持 1 ~ 33svg

例如,默认 👇

<!-- 省略各种代码 -->
<template>
	<img src="/notFound/32.svg" class="cover" alt="page not found" />
</template>

修改 /notFound/32.svg/notFound/33.svg

<!-- 省略各种代码 -->
<template>
	<img src="/notFound/33.svg" class="cover" alt="page not found" />
</template>

即可切换封面为 👇

notFound-other



只需要 tsx 文件放在 src/components 下,即可直接在模板中使用。

例如你有一个 src/components/foo.tsx 文件,那么即可直接在模板中使用。

// src/components/foo.tsx
export default defineComponent({
  render() {
    return <div>Test</div>;
  },
});
<template>
	<foo />
</template>

具体可见 👉 @vitejs/plugin-vue-jsx



生产环境下开箱即用的 gzip 资源压缩,无需配置。

具体可见 👉 vite-plugin-compression



根目录下的 .env 用来对项目进行环境变量配置。



28. 统一的代码规范与风格支持

eslint 提供的代码规范校验,使用 prettier 统一代码风格。

husky + lint-staged 提供的 commit 时校验。



生产环境下 console.logconsole.warnconsole.error 等日志会被自动移除掉,以避免开发时日志的泄漏。

具体可见 👉 vite-plugin-removelog



<script setup lang="ts">
	// 定义额外的 options
	defineOptions({
		name: 'Foo',
	})
</script>


简单集成了 vue-echarts,具体可见 echartsvue-echarts 文档



集成了 vue-toastification,你可以在 src 目录下所有文件中使用它 👇

// src 下任何文件都是可用的
toast.info("信息");
toast.error("失败");
toast.warning("警告");
toast.success("成功");

具体可见 👉 全局通用 toast 通知



封装了 axios,你可以在 src 目录下所有文件中使用它 👇

// src 下任何文件都是可用的
http.get("...");
http.post("...", { name: "张三", age: 20 });
// ... 以此类推

上述 httpaxios 单独创建的实例,具有简单错误提示,以及响应数据转换。具体可见 src/composables/http.ts

如果你喜欢响应式风格和 swr,可以跟 vue-request 一起使用

import { useRequest } from "vue-request";

const { data, error, loading } = useRequest(() => http.get("..."));

loading.value; // 是否加载中

error.value; // 错误内容

data.value; // 响应数据

http 实例的 baseURL 取自环境变量文件 .envVITE_API_BASE_URL,默认为 /api,可以按自己需求更改。

具体可见 👉 axios



vite 项目中,我们虽然可以在 .env 中设置环境变量,并在前端源码中通过 import.meta.env 来使用它们,但是类型提示是糟糕的。这个功能可以自动生成类型声明以达到实时的类型提示,让你不需要关心和手动管理它们。

具体可见 👉 vite-plugin-env-types



githubrenovate 机器人会定期对 github 检查依赖,并向仓库提起 pr,更新策略 👉 unjs/renovate-config

当然你也可以执行,来手动更新 👇

pnpm deps:fresh

具体可见 👉 renovate



当我们执行 pnpm run release 时,会自动进行版本更新,并更新 CHANGELOG.md

具体可见 👉 unjs/changelogen



根目录下的 dockerfile 配置最小最快的静态 go 服务容器,更方便云容器服务

具体可见 👉 PierreZ/goStatic



38. base 安全的路径解析

vite 中,如果我们改了 vite.config.ts 中的 base,这导致资源路径和路由路径失效,使用 safeResolve 可以保证在开发环境和生产环境下都是统一的 base.

<script setup lang="ts">
const path = safeResolve("你的路由路径")
</script>

<template>
	<!-- 模板中应用也是允许的 -->
	<img :src="safeResolve('/notFound/32.svg')"/>
</template>


39. lightningcss 支持

现在会默认检测当前项目是否支持 lightningcss 并智能开启



40. vite 配置层支持 (实验性)

现在在 tov-template 中,我们可以使用 vite.config.[mode].ts 的形式来支持不同环境下的配置文件。

  1. 仅 vite.config.ts 时,通用选择该配置
  2. vite.config.ts + vite.config.dev.ts,开发时合并两者的配置,同时 vite.config.dev.ts 的配置优先级更高
  3. vite.config.ts + vite.config.prod.ts 生产时合并两者的配置,同时 vite.config.prod.ts 的配置优先级更高

以此类推,支持不同的 mode

该特性由 vite-layers 提供支持 🥰




License

Made with markthree

Published under MIT License.


tov-template's People

Contributors

androidmumo avatar cuitpanfei avatar luoqiz avatar markthree avatar ottocsb avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tov-template's Issues

路由守护

请问在这个框架里常见的路由守护有没有例子?

👍👍👍

牛的牛的,最近也在做一个admin模板,做了基本的插件自动加载和文件路由,直到我看到了这个项目,原来已经有插件做好了👍👍

能否添加一下pinia持久化

信息

nodejs 版本

TODO

(推荐使用 v16 以上)


包管理器及其版本

TODO

(推荐使用 pnpm)


系统

win10

(该项目开发环境系统为 win11)



bug

描述

TODO


预期结果

TODO


最小测试仓库

TODO

嵌套式路由

信息

在 layout/default.vue 中已经嵌入routerView,在page下的home/index.vue 文件中再次配置routerView 并使用vant tab组件配置to属性,此时点击就跳转到 /home/focus 路径下, 但是会丢失 /home 页面上的 tab标签栏,大佬,您知道怎么处理嘛?

image

如何用 h 渲染 iconify 图标,而不会出现编辑器错误

我想通过h()来渲染图标,如果像这样

import CarbonAlignBoxMiddleCenter from '~icons/carbon/align-box-middle-center'

直接导入是可以生效的,但是编辑器会报错,实际运行没问题。

编辑器错误显示为找不到模块“~icons/carbon/align-box-middle-center”或其相应的类型声明
那有没有优雅一点的方法导入😫

具体代码类似像这样:

import CarbonAlignBoxMiddleCenter from '~icons/carbon/align-box-middle-center'

const renderIcon = (icon: Component) => {
	return () => h(NIcon, null, { default: () => h(icon) })
}

···
return renderIcon(CarbonAlignBoxMiddleCenter)

能不能做到像这种格式的导入且不报错

import {CarbonAlignBoxMiddleCenter as CA} from '~icons/carbon'

出现@click的Typescript的格式检查错误

信息

nodejs 版本

(推荐使用 v16 以上)
v17.2.0

包管理器及其版本

pnpm

(推荐使用 pnpm)


系统

mac

(该项目开发环境系统为 win11)



bug

描述

将代码从git上拉下来,使用pnpm安装完依赖之后发现@click的类型提示错误。之前接触的其他vue3+ts项目没有出现这种提示,谷歌了没能查询到解决办法(typescript萌新)

image


预期结果

不使用tsignore也能够通过检查


最小测试仓库

TODO

naive ui 暗黑模式

hi 我该如何使用windi css 渲染naive ui的组件呢, 切换模式时组件的边框和样式切换成暗黑模式了,但组件内的文本并没有渲染,还是说我需要使用naive ui的暗黑模式?
我是个菜鸟,问的问题可能很愚蠢,希望不要介意
image
如上图,按钮中的文本并没有渲染
image

i18n

请问i18n怎么支持?

UI组件库 resolver 存在命名冲突

场景说明

安装ant-design-vue库后,在使用a-button组件时,因两者命名相同,会有错误
image

自动引入组件部分 - 代码截图

image
image

将AntDesignVueResolver放在ArcoResolver之前即可正常使用。

大部分项目只会用到一个UI库,也不会遇到重命问题,所以项目中删除或替换位置即可;
提出这个issues,以免其他人踩坑,不知道作者大佬有什么其他更好的方式解决。

开发过程中模板更新了

假设使用你的1.0模板开发项目,但时候后续你的模板变成1.2了,改怎么更新呢?是运行命令还是直接覆盖某些文件就可以了?

请问路由元信息如何扩展?

本项目是基于文件路由的。
那么如果某些路由需要携带重要的 meta 信息(权限),标准做法是什么?
是 vite-plugin-pages插件的 extendRoute ?
还是重写路由文件?

使用iconfont的symbol引入方式时,无法打包

信息

nodejs 版本

TODO

(推荐使用 v16 以上)


包管理器及其版本

TODO

(推荐使用 pnpm)


系统

TODO

(该项目开发环境系统为 win11)



bug

描述

TODO


预期结果

TODO


最小测试仓库

TODO

tsx文件不能被自動按需導入

手動import tsx文件,不認。去掉.tsx尾,可以正常顯示。但是無法按需自動識別導入tsx 組件。
src/componets/XXX.tsx

i18n多语言例子

现有的例子多语言文件比较简单,实际翻译文件应该是多层嵌套的,如果可以能否进一步举例子?

The Vue Semantic Server server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.

信息

nodejs 版本

Node.js: 16.14.2

(推荐使用 v16 以上)


包管理器及其版本

pnpm 8.2.0

(推荐使用 pnpm)


系统

vscode Version: 1.77.3
OS: Windows_NT x64 10.0.19044

(该项目开发环境系统为 win11)



bug

描述

volar 报
at G:\Scoop\persist\vscode\data\extensions\vue.volar-1.2.0-win32-x64\dist\node\server.js:846:9951 at Array.map (<anonymous>) at ewe (G:\Scoop\persist\vscode\data\extensions\vue.volar-1.2.0-win32-x64\dist\node\server.js:846:9944) at Object.rwe (G:\Scoop\persist\vscode\data\extensions\vue.volar-1.2.0-win32-x64\dist\node\server.js:846:20241) at Object.kIe (G:\Scoop\persist\vscode\data\extensions\vue.volar-1.2.0-win32-x64\dist\node\server.js:7320:3900) at Object.resolveConfig (G:\Scoop\persist\vscode\data\extensions\vue.volar-1.2.0-win32-x64\dist\node\server.js:7324:8994) at Object.d [as getLanguageService] (G:\Scoop\persist\vscode\data\extensions\vue.volar-1.2.0-win32-x64\dist\node\server.js:510:1933) at G:\Scoop\persist\vscode\data\extensions\vue.volar-1.2.0-win32-x64\dist\node\server.js:510:32874 at Generator.next (<anonymous>) at a (G:\Scoop\persist\vscode\data\extensions\vue.volar-1.2.0-win32-x64\dist\node\server.js:510:24057) [Error - 10:05:46] The Vue Semantic Server server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.
错误,我使用vitess就不会出现这个错误。请问老师您是怎么配置的。


预期结果

TODO


最小测试仓库

TODO

api请求的错误封装

api请求的错误封装,一般api请求错误处理怎么弄比较好,可否给个例子?

pnpm install正常,但是npm install依赖报错

nodejs 版本: 18.12.1

包管理器及其版本 : npm

系统: macos-12.6

代码是最新main分支,npm install 输出:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/vite
npm ERR!   dev vite@"^4.0.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer vite@"^3.0.0" from @vitejs/[email protected]
npm ERR! node_modules/@vitejs/plugin-vue
npm ERR!   dev @vitejs/plugin-vue@"^3.2.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /Users/test1/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/test1/.npm/_logs/2022-12-29T02_37_09_121Z-debug-0.log

希望能解决。万分感谢

建议:类Nuxt3文件系统布局

传统vue项目入口都在src目录下,一旦搭配后端同时开发,你会发现src下可能要嵌套三四级目录才能找到组件。
Nuxt3干掉了src,大胆的把里面的组件、页面、布局放在第一级目录里,实际上大有好处,tov-template是个很前沿的项目,可以考虑干掉src

修改内容后刷新浏览器,路由元信息丢失

信息

nodejs 版本

v16.14.1

(推荐使用 v16 以上)


包管理器及其版本

pnpm6.32.8、npm8.5.0、yarn1.22.0

(推荐使用 pnpm)


系统

win11 chrome版本【 99.0.4844.82(正式版本) (64 位)】

(该项目开发环境系统为 win11)



bug

描述

修改页面热更新后F5刷新浏览器,layout匹配错误
eg:

  1. 给default Layout随便加点文案,例如加入一个 <h1>default</h1>
  2. 浏览器进入notFound页面
  3. 修改notFount页面中文案,例如404改为405,热更新后浏览器可见文案更新为405
  4. 浏览器F5刷新页面后可以看到刚刚再default layout中新增的元素,同时你再控制台打印router的meta信息会发现layout字段的信息丢失

预期结果

layout通过meta.layout正确匹配


最小测试仓库

tov-template

是否考虑出一个vite+react模板

信息

nodejs 版本

TODO

(推荐使用 v16 以上)


包管理器及其版本

TODO

(推荐使用 pnpm)


系统

TODO

(该项目开发环境系统为 win11)



bug

描述

TODO


预期结果

TODO


最小测试仓库

TODO

开发环境下 webview 无效

首先感谢您!因为跟着您分享的框架学习了好多!最近发现了一个问题,不知道别人是否也遇到了!开发环境下,webview是打不开的!只有build后发布到服务器后才能显示在webview中,当然,开发环境下浏览器是可以正常打开的!求指导!谢谢

能否升级到vite3.0

信息

nodejs 版本

TODO

(推荐使用 v16 以上)


包管理器及其版本

TODO

(推荐使用 pnpm)


系统

TODO

(该项目开发环境系统为 win11)



bug

描述

TODO


预期结果

TODO


最小测试仓库

TODO

布局系统在嵌套路由下无效

信息

使用default.vue布局没问题,当我添加登录页面时需用新的布局,但是新定义的custom.vue页面不生效,还是用的default。

自动导入自定义的api失效

自动导入自定义插件失效,在自己的项目中没有生成,用了模板项目“tov-template”,删除auto-import.d.ts后重新启动项目,会重新生成该文件,但是文件中无引入的自定义api
image
image

管理后台框架例子

一般管理后台框架,有个Header,Body,Footer,以及常用的菜单,是用tailwindcss来构建好,还是用ElementPlus好,大神你这边用的是啥样的,能够给个简单的例子。

BUG: 使用 element-plus v-loading 指令时,报错

信息

nodejs 版本

16.13.1

包管理器及其版本

pnpm

系统

macOS

bug

描述

使用目前最新的代码,然后执行 pnpm install element-plus 安装 element-plus,使用 v-loading 指令,会报错:

[plugin:vite:import-analysis] Failed to resolve import "element-plus/es/components/loading-directive/style/css" from "src/pages/Index.vue". Does the file exist?

预期结果

v-loading 功能正常运行

最小测试仓库

目前最新版执行 pnpm install element-plus 后,在任意元素上增加 v-loading="true" 即可复现

RFC (v2): 一切按需

回顾

数据由 Gitee + Github 提供 🤗

tov-template2022/1/8 日起开源至今 2023/1/10

已获得

  • 181 + 431 Star
  • 72 + 115 Fork

已处理

在这里由衷感谢每个 关注使用 甚至 贡献 该项目的靓仔和靓女们 🥰


问题

虽然 tov-template 目前已经具备足够多的 特性 👇

  1. Vite 的
  2. Vue3 的
  3. 文件路由
  4. 布局系统
  5. Mock 支持
  6. Api 自动引入
  7. 组件自动引入
  8. 图标自动引入
  9. VueUse 支持
  10. TypeScript 的
  11. Windi CSS 的
  12. 暗黑模式支持
  13. SWR 请求支持
  14. pinia 状态管理
  15. pnpm 包管理器
  16. 跳转进度条支持
  17. Inspect 调试支持
  18. 插件自动加载支持
  19. Vitest 单元测试支持
  20. 支持 Markdown 渲染
  21. 路径别名 ~ 支持
  22. 命令行自动创建与删除
  23. i18n 国际化支持
  24. 漂亮的 404 页 支持
  25. tsx 支持
  26. gzip 资源压缩支持
  27. 环境变量配置支持
  28. 统一的代码规范与风格支持
  29. 生产环境自动移除开发日志
  30. defineOptions 支持

除此之外,预设 内部也做了很多优化,为我们带来了好的 DX (开发体验)

但是这些也为项目引入了一些新的问题 👇

  1. 越来越多的配置文件,让人眼花缭乱 😵
  2. 越来越多的 vite 插件,让项目开发和编译卡顿 😢

而这一切的问题都来源于新的功能不断加入 😅

但大多数情况下,我们其实并不需要全部的功能才能满足业务需求 🤔


方案

基于上述问题,我们也许可以采用 按需的方式,只为项目加入自己需要的功能。

prepare

node 项目当中,我们拿到项目的第一步就是执行 npm install 执行项目依赖。

其实在安装完依赖之后,会执行 package.json里的 prepare 命令钩子。

例如在 package.json 中设置 👇

{
	"scripts": {
		"prepare": "node foo.js"
	}
}

并创建 foo.js 👇

console.log(1)

执行 npm install 后,将输出 1

由比如在 nuxt3 中,我们会设置 prepare 命令钩子在安装依赖后自动生成类型声明文件 👇

{
	"scripts": {
		"prepare": "nuxi prepare"
	}
}

通过这样的机制,我们就可以将现有的项目功能按需生成 🥰

这在 yarnpnpm 中也是通用的


break

在现有项目中,我们在更新时会保持原有功能的使用不变,但这一定程度上阻碍了我们引入更好的方案。

在新的版本中,一切都是按需生成的,所以新方案的引入会更加的顺畅自然。


unified

在现有项目中,我们可能会在运行时中引入通用的功能,例如动态修改 title,进度条等。

它们被零散地分布在各个文件,一方面这使得功能的分享变得复杂,一方面让维护变得困难。

所以在新的版本中,也许我们会有更规范的 modules 或者 plugins 机制统一地管理它们。


less

pnpm

在现有项目中,我们支持了 npmyarnpnpm

各个包管理器存在不一样的差异,这使得功能的测试和维护变得繁杂且困难。

而且由于项目环境基于 pnpm,我们很难保证在 npmyarn 使用过程中出现我们未测试到的 bug

所以为了对齐彼此的开发环境也为了让项目的维护变得简单,在新的版本中我们将有且仅支持 pnpm

config

在现有项目中,存在着非常非常多的配置文件。

这些配置文件对应着不同功能,即使这些功能并非我们所需要的,我们也不得不付出管理的成本。

即使我们 explorer.fileNesting 使得配置文件嵌套起来隐藏,但是这似乎并不算完美。

在新的版本中,我们希望我们保持尽量少的配置文件,让一切配置文件都是按需出现。


启发

该 RFC 受以下项目启发


组件按需引入build后发现组件没有编译

信息

nodejs 版本

16.16.0

(推荐使用 v16 以上)


包管理器及其版本

pnpm : 7.8.0

(推荐使用 pnpm)


系统

MacOS Monterey 12.5

(该项目开发环境系统为 win11)



bug

描述

项目中引入element-pius,build打包之后发现组件没有编译;另外项目中没有components文件夹,新建src/components,发现组件也没有经过编译;
image


预期结果

期望能正常编译。下面是本地Dev的时候,是正常的,期望build之后和Dev一致
image


最小测试仓库

我是用你本项目作为模板直接,pnpm add element-plus 之后跑的

打包时 removelog 报错

信息

nodejs 版本

v16.14.2

(推荐使用 v16 以上)


包管理器及其版本

pnpm

(推荐使用 pnpm)


系统

mac

(该项目开发环境系统为 win11)



bug

描述

pnpm build 错误
image


预期结果

解决打包问题


最小测试仓库

TODO

是否计划写成一个admin项目?

现在tov是个快速启动模板,跟通常的admin项目相比只有基础配置等;缺失基本的layout和router to menu;未来有没有计划完善这个项目,做成一个基础版本的admin

模板使用

假设我已经使用这个模板进行了开发,但是后面模板更新了,我改如何更新呢?

是否能适配一个electron模板

信息

nodejs 版本

TODO

(推荐使用 v16 以上)


包管理器及其版本

TODO

(推荐使用 pnpm)


系统

TODO

(该项目开发环境系统为 win11)



bug

描述

TODO


预期结果

TODO


最小测试仓库

TODO

执行pnpm add 警告

tov-template-main pnpm add ant-design-vue@next
Packages: +46 -12
++++++++++++++++++++++++++++++++++++++++++++++------------
Relinking /Users/redli/Downloads/tov-template-main/node_modules/.pnpm/[email protected]/node_modules/eslint-utils from the store
Relinking /Users/redli/Downloads/tov-template-main/node_modules/.pnpm/[email protected][email protected]/node_modules/acorn-jsx from the store
Relinking /Users/redli/Downloads/tov-template-main/node_modules/.pnpm/[email protected]/node_modules/graceful-fs from the store
Relinking /Users/redli/Downloads/tov-template-main/node_modules/.pnpm/@[email protected]/node_modules/@intlify/shared from the storeing registry.npmjs.org/ant-design-vue/2.2.8: 3.12 MB/9.06 MB
Relinking /Users/redli/Downloads/tov-template-main/node_modules/.pnpm/@[email protected]/node_modules/@intlify/message-compiler from the storerg/ant-design-vue/2.2.8: 3.12 MB/9.06 MB
Relinking /Users/redli/Downloads/tov-template-main/node_modules/.pnpm/[email protected]/node_modules/espree from the store
Relinking /Users/redli/Downloads/tov-template-main/node_modules/.pnpm/@[email protected][email protected]/node_modules/@intlify/bundle-utils from the storedesign-vue/2.2.8: 3.12 MB/9.06 MB
Relinking /Users/redli/Downloads/tov-template-main/node_modules/.pnpm/[email protected]/node_modules/eslint-visitor-keys from the storeing registry.npmjs.org/ant-design-vue/2.2.8: 3.12 MB/9.06 MB
Relinking /Users/redli/Downloads/tov-template-main/node_modules/.pnpm/[email protected]/node_modules/semver from the store
Relinking /Users/redli/Downloads/tov-template-main/node_modules/.pnpm/[email protected]/node_modules/acorn from the store
Relinking /Users/redli/Downloads/tov-template-main/node_modules/.pnpm/[email protected]/node_modules/lodash from the store
Relinking /Users/redli/Downloads/tov-template-main/node_modules/.pnpm/[email protected]/node_modules/yaml-eslint-parser from the storeading registry.npmjs.org/ant-design-vue/2.2.8: 3.12 MB/9.06 MB
Relinking /Users/redli/Downloads/tov-template-main/node_modules/.pnpm/[email protected]/node_modules/uglify-js from the store
Relinking /Users/redli/Downloads/tov-template-main/node_modules/.pnpm/[email protected]/node_modules/source-map from the store
Relinking /Users/redli/Downloads/tov-template-main/node_modules/.pnpm/[email protected]/node_modules/fsevents from the store
Relinking /Users/redli/Downloads/tov-template-main/node_modules/.pnpm/[email protected]/node_modules/esbuild-darwin-64 from the storeading registry.npmjs.org/ant-design-vue/2.2.8: 3.12 MB/9.06 MB
Relinking /Users/redli/Downloads/tov-template-main/node_modules/.pnpm/[email protected]/node_modules/esbuild-darwin-64 from the storeading registry.npmjs.org/ant-design-vue/2.2.8: 3.12 MB/9.06 MB
Relinking /Users/redli/Downloads/tov-template-main/node_modules/.pnpm/@[email protected]/node_modules/@ctrl/tinycolor from the store
Relinking /Users/redli/Downloads/tov-template-main/node_modules/.pnpm/[email protected]/node_modules/yaml from the store
Relinking /Users/redli/Downloads/tov-template-main/node_modules/.pnpm/[email protected]/node_modules/jsonc-eslint-parser from the storeing registry.npmjs.org/ant-design-vue/2.2.8: 3.38 MB/9.06 MB
Relinking /Users/redli/Downloads/tov-template-main/node_modules/.pnpm/[email protected]/node_modules/js-tokens from the store
Downloading registry.npmjs.org/ant-design-vue/2.2.8: 9.06 MB/9.06 MB, done
Progress: resolved 584, reused 526, downloaded 25, added 46, done
node_modules/.pnpm/[email protected]/node_modules/core-js: Running postinstall script, done in 95ms

dependencies:
+ ant-design-vue 2.2.8

 WARN  Issues with peer dependencies found
.
├─┬ ant-design-vue
│ └── ✕ missing peer @vue/compiler-sfc@>=3.1.0
├─┬ unplugin-icons
│ ├── ✕ missing peer @vue/compiler-sfc@^3.0.2
│ └─┬ unplugin
│   └── ✕ missing peer rollup@^2.50.0
├─┬ vite-plugin-pages
│ └── ✕ missing peer @vue/compiler-sfc@>=3
├─┬ markdown-it-anchor
│ ├── ✕ missing peer markdown-it@"*"
│ └── ✕ missing peer @types/markdown-it@"*"
├─┬ unplugin-auto-import
│ └─┬ unplugin
│   └── ✕ missing peer rollup@^2.50.0
└─┬ vite-plugin-mock
  └─┬ @rollup/plugin-node-resolve
    ├── ✕ missing peer rollup@^2.42.0
    └─┬ @rollup/pluginutils
      └── ✕ missing peer rollup@^1.20.0||^2.0.0
Peer dependencies that should be installed:
  @types/markdown-it@"*"              markdown-it@"*"                     
  @vue/compiler-sfc@">=3.1.0 <4.0.0"  rollup@">=2.50.0 <3.0.0"            
➜  tov-template-main 

动态路由

感觉这个框架 动态路由不太好弄呀?

希望提供一个调试配置

mac-12.6
node-16.19
pnpm

这个项目是目前最好的vue脚手架,希望能一直维护下去。我的调试配置.vscode/launch.json:

{
    "configurations": [
    {
        "name": "Launch Chrome",
        "request": "launch",
        "type": "chrome",
        "url": "http://localhost:5173",
        "webRoot": "${workspaceFolder}/src"
    }
    ]
}

有的断点可以正常,有的断到其它地方了,希望能提供一个官方的,万分感谢

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.