Skip to content

Commit c776f49

Browse files
committed
feat: New layout system (#62)
1 parent 08a0b25 commit c776f49

File tree

24 files changed

+198
-83
lines changed

24 files changed

+198
-83
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
- 🍍 [State Management via Pinia](https://pinia.vuejs.org)
3636

37+
- 📑 [Layout system](./src/layouts)
38+
3739
- 🎨 [UnoCSS](https://github.com/antfu/unocss) - the instant on-demand atomic CSS engine
3840

3941
- 🔥 Use the [new `<script setup>` syntax](https://github.com/vuejs/rfcs/pull/227)
@@ -79,13 +81,17 @@
7981

8082
- [Vue Router](https://github.com/vuejs/router)
8183
- [`unplugin-vue-router`](https://github.com/posva/unplugin-vue-router) - file system based routing
84+
- [`vite-plugin-vue-layouts`](https://github.com/JohnCampionJr/vite-plugin-vue-layouts) - layouts for pages
8285
- [Pinia](https://pinia.vuejs.org) - Intuitive, type safe, light and flexible Store for Vue using the composition api
8386
- [`pinia-plugin-persistedstate`](https://github.com/prazdevs/pinia-plugin-persistedstate) - Configurable persistence and rehydration of Pinia stores
8487
- [unplugin-vue-components](https://github.com/antfu/unplugin-vue-components) - components auto import
8588
- [unplugin-auto-import](https://github.com/antfu/unplugin-auto-import) - Directly use Vue Composition API and others without importing
8689
- [vite-plugin-vconsole](https://github.com/vadxq/vite-plugin-vconsole) - A lightweight, extendable front-end developer tool for mobile web page
8790
- [vite-plugin-mock-dev-server](https://github.com/pengzhanbo/vite-plugin-mock-dev-server) - Vite Plugin for API mock dev server
8891
- [postcss-mobile-forever](https://github.com/wswmsword/postcss-mobile-forever) - To adapt different displays by one mobile viewport
92+
- [vite-plugin-vue-devtools](https://github.com/vuejs/devtools-next) - Designed to enhance the Vue developer experience
93+
- [vueuse](https://github.com/antfu/vueuse) - collection of useful composition APIs
94+
- [@unhead/vue](https://github.com/unjs/unhead) - manipulate document head reactively
8995

9096
### Coding Style
9197

README.zh-CN.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
- 🍍 [使用 Pinia 的状态管理](https://pinia.vuejs.org)
3636

37+
- 📑 [布局系统](./src/layouts)
38+
3739
- 🎨 [UnoCSS](https://github.com/antfu/unocss) - 高性能且极具灵活性的即时原子化 CSS 引擎
3840

3941
- 🔥 使用 [新的 `<script setup>` 语法](https://github.com/vuejs/rfcs/pull/227)
@@ -79,13 +81,17 @@
7981

8082
- [Vue Router](https://github.com/vuejs/router)
8183
- [`unplugin-vue-router`](https://github.com/posva/unplugin-vue-router) - 以文件系统为基础的路由
84+
- [`vite-plugin-vue-layouts`](https://github.com/JohnCampionJr/vite-plugin-vue-layouts) - 页面布局系统
8285
- [Pinia](https://pinia.vuejs.org) - 直接的, 类型安全的, 使用 Composition API 的轻便灵活的 Vue 状态管理库
8386
- [`pinia-plugin-persistedstate`](https://github.com/prazdevs/pinia-plugin-persistedstate) - 适用于 Pinia 的持久化存储插件
8487
- [unplugin-vue-components](https://github.com/antfu/unplugin-vue-components) - 自动加载组件
8588
- [unplugin-auto-import](https://github.com/antfu/unplugin-auto-import) - 直接使用 Composition API 等,无需导入
8689
- [vite-plugin-vconsole](https://github.com/vadxq/vite-plugin-vconsole) - vConsole 的 vite 插件
8790
- [vite-plugin-mock-dev-server](https://github.com/pengzhanbo/vite-plugin-mock-dev-server) - vite mock 开发服务(mock-dev-server)插件
8891
- [postcss-mobile-forever](https://github.com/wswmsword/postcss-mobile-forever) - 一款 PostCSS 插件,将固定尺寸的移动端视图转为具有最大宽度的可伸缩的移动端视图
92+
- [vite-plugin-vue-devtools](https://github.com/vuejs/devtools-next) - 旨在增强Vue开发者体验的Vite插件
93+
- [vueuse](https://github.com/antfu/vueuse) - 实用的 Composition API 工具合集
94+
- [@unhead/vue](https://github.com/unjs/unhead) - 响应式地操作文档头信息
8995

9096
### 编码风格
9197

build/vite/index.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,36 @@ import { VantResolver } from 'unplugin-vue-components/resolvers'
1010
import { unheadVueComposablesImports } from '@unhead/vue'
1111
import VueDevTools from 'vite-plugin-vue-devtools'
1212
import mockDevServerPlugin from 'vite-plugin-mock-dev-server'
13+
import Layouts from 'vite-plugin-vue-layouts'
1314
import UnoCSS from 'unocss/vite'
1415
import { createViteVConsole } from './vconsole'
1516

1617
export function createVitePlugins() {
1718
return [
19+
// https://github.com/posva/unplugin-vue-router
1820
VueRouter({
19-
routesFolder: 'src/views',
21+
extensions: ['.vue'],
22+
routesFolder: 'src/pages',
2023
dts: 'src/typed-router.d.ts',
2124
}),
2225

2326
vue(),
24-
vueJsx(),
25-
visualizer(),
26-
UnoCSS(),
27-
mockDevServerPlugin(),
2827

29-
legacy({
30-
targets: ['defaults', 'not IE 11'],
31-
}),
28+
// https://github.com/JohnCampionJr/vite-plugin-vue-layouts
29+
Layouts(),
30+
31+
// https://github.com/pengzhanbo/vite-plugin-mock-dev-server
32+
mockDevServerPlugin(),
3233

34+
// https://github.com/antfu/unplugin-vue-components
3335
Components({
3436
extensions: ['vue'],
3537
resolvers: [VantResolver()],
3638
include: [/\.vue$/, /\.vue\?vue/],
3739
dts: 'src/components.d.ts',
3840
}),
3941

42+
// https://github.com/antfu/unplugin-auto-import
4043
AutoImport({
4144
include: [
4245
/\.[tj]sx?$/,
@@ -59,8 +62,21 @@ export function createVitePlugins() {
5962
],
6063
}),
6164

65+
// https://github.com/antfu/unocss
66+
// see uno.config.ts for config
67+
UnoCSS(),
68+
69+
// https://github.com/vadxq/vite-plugin-vconsole
6270
createViteVConsole(),
6371

72+
// https://github.com/webfansplz/vite-plugin-vue-devtools
6473
VueDevTools(),
74+
75+
vueJsx(),
76+
visualizer(),
77+
78+
legacy({
79+
targets: ['defaults', 'not IE 11'],
80+
}),
6581
]
6682
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"vite-plugin-mock-dev-server": "^1.4.7",
6969
"vite-plugin-vconsole": "^2.1.1",
7070
"vite-plugin-vue-devtools": "^7.0.14",
71+
"vite-plugin-vue-layouts": "^0.11.0",
7172
"vitest": "^1.2.2",
7273
"vue-tsc": "^1.8.27"
7374
},

pnpm-lock.yaml

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ declare module 'vue' {
1616
VanCellGroup: typeof import('vant/es')['CellGroup']
1717
VanConfigProvider: typeof import('vant/es')['ConfigProvider']
1818
VanEmpty: typeof import('vant/es')['Empty']
19+
VanIcon: typeof import('vant/es')['Icon']
1920
VanNavBar: typeof import('vant/es')['NavBar']
2021
VanSpace: typeof import('vant/es')['Space']
2122
VanSwitch: typeof import('vant/es')['Switch']

src/components/container/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<main class="h-full w-full p-16 py-60">
2+
<div class="p-16 py-60">
33
<slot />
4-
</main>
4+
</div>
55
</template>

src/layouts/404.vue

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script setup lang="ts">
2+
const router = useRouter()
3+
</script>
4+
5+
<template>
6+
<main p="x4 y16" text-18 text="center gray-300 dark:gray-200">
7+
<van-icon name="warn-o" size="3em" />
8+
9+
<RouterView />
10+
11+
<div class="mt-10">
12+
<button van-haptics-feedback btn m="3 t8" @click="router.back()">
13+
Back
14+
</button>
15+
</div>
16+
</main>
17+
</template>
18+
19+
<style scoped>
20+
21+
</style>

src/layouts/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Layouts
2+
3+
Vue components in this dir are used as layouts.
4+
5+
By default, `default.vue` will be used unless an alternative is specified in the route meta.
6+
7+
With [`unplugin-vue-router`](https://github.com/posva/unplugin-vue-router) and [`vite-plugin-vue-layouts`](https://github.com/JohnCampionJr/vite-plugin-vue-layouts), you can specify the layout in the page's SFCs like this:
8+
9+
```vue
10+
<route lang="yaml">
11+
meta:
12+
layout: home
13+
</route>
14+
```

src/layouts/default.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<template>
2+
<main text="gray-700 dark:gray-200">
3+
<RouterView />
4+
5+
<div mx-auto mt-15 text-center text-14 opacity-50>
6+
Default Layout
7+
</div>
8+
</main>
9+
</template>

0 commit comments

Comments
 (0)