Skip to content

Commit 34c5bf3

Browse files
authored
feat: support head updating by @vueuse/head (antfu-collective#7)
* wip: @vueuse/head * feat: support @vueuse/head * chore: update readme
1 parent 0db47e5 commit 34c5bf3

File tree

13 files changed

+374
-235
lines changed

13 files changed

+374
-235
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules
22
.DS_Store
33
dist
44
example/README.md
5+
.vite-ssg-temp

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
shamefully-hoist = true
2+
ignore-workspace-root-check = true

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,34 @@ export default {
6464

6565
Component `ClientOnly` is registered globally along with the app creation.
6666

67+
## Document head
68+
69+
From `v0.4.0`, we ships [`@vueuse/head`](https://github.com/vueuse/head) to manage the document head out-of-box. You can directly use it in your pages/components, for example:
70+
71+
```vue
72+
<template>
73+
<button @click="count++">Click</button>
74+
</template>
75+
76+
<script setup>
77+
import { useHead } from '@vueuse/head'
78+
79+
useHead({
80+
title: 'Website Title',
81+
meta: [
82+
{
83+
name: `description`,
84+
content: `Website description`,
85+
},
86+
],
87+
})
88+
</script>
89+
```
90+
91+
That's all, no configuration needed. Vite SSG will handle the server-side rendering and merging automatically.
92+
93+
Refer to [`@vueuse/head`'s docs](https://github.com/vueuse/head) for more usage about `useHead`.
94+
6795
## Comparsion
6896

6997
### Use [Vitepress](https://github.com/vuejs/vitepress) when you want:

bin/vite-ssg.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env node
22
'use strict'
3-
require('../dist/cli')
3+
require('../dist/node/cli')

example/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
"vue": "^3.0.5"
99
},
1010
"devDependencies": {
11-
"@vitejs/plugin-vue": "^1.0.4",
11+
"@vitejs/plugin-vue": "^1.0.6",
1212
"@vue/compiler-sfc": "^3.0.5",
1313
"cross-env": "^7.0.3",
1414
"typescript": "^4.1.3",
15-
"vite": "^2.0.0-beta.10",
16-
"vite-plugin-components": "^0.6.1",
17-
"vite-plugin-md": "^0.2.0",
15+
"vite": "^2.0.0-beta.31",
16+
"vite-plugin-components": "^0.6.6",
17+
"vite-plugin-md": "^0.2.1",
1818
"vite-plugin-voie": "npm:@antfu/vite-plugin-voie@^0.7.1",
1919
"vite-ssg": "workspace:*",
2020
"voie-pages": "^0.4.0",
21-
"vue-router": "^4.0.2"
21+
"vue-router": "^4.0.3"
2222
}
2323
}

example/src/pages/b.vue

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<template>
2+
<p>Hello I am B</p>
3+
</template>
4+
5+
<script setup lang="ts">
6+
import { useHead } from '@vueuse/head'
7+
8+
useHead({
9+
title: 'Hello',
10+
meta: [
11+
{
12+
name: 'description',
13+
content: 'Website description',
14+
},
15+
],
16+
style: [
17+
{
18+
children: 'body {color: #567839}',
19+
},
20+
],
21+
})
22+
</script>

package.json

+8-7
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@
2828
"dev": "npm run build -- --watch",
2929
"example:dev": "cp README.md example/README.md && npm -C example run dev",
3030
"example:build": "cp README.md example/README.md && npm -C example run build",
31-
"build": "tsup src/index.ts src/cli.ts --dts --format cjs,esm",
31+
"build": "tsup src/index.ts src/node/cli.ts --dts --format cjs,esm",
3232
"prepublishOnly": "npm run build",
3333
"release": "npx bumpp --commit --tag && npm publish && git push"
3434
},
3535
"dependencies": {
36+
"@vueuse/head": "^0.2.1",
3637
"chalk": "^4.1.0",
3738
"fs-extra": "^9.0.1",
3839
"jsdom": "^16.4.0",
@@ -48,18 +49,18 @@
4849
"devDependencies": {
4950
"@antfu/eslint-config": "^0.4.3",
5051
"@types/fs-extra": "^9.0.6",
51-
"@types/jsdom": "^16.2.5",
52+
"@types/jsdom": "^16.2.6",
5253
"@types/yargs": "^15.0.12",
53-
"@typescript-eslint/eslint-plugin": "^4.12.0",
54+
"@typescript-eslint/eslint-plugin": "^4.14.0",
5455
"@vue/compiler-sfc": "^3.0.5",
5556
"@vue/server-renderer": "^3.0.5",
56-
"eslint": "^7.17.0",
57-
"rollup": "^2.36.1",
57+
"eslint": "^7.18.0",
58+
"rollup": "^2.37.0",
5859
"standard-version": "^9.1.0",
5960
"tsup": "^3.11.0",
6061
"typescript": "^4.1.3",
61-
"vite": "^2.0.0-beta.12",
62+
"vite": "^2.0.0-beta.31",
6263
"vue": "^3.0.5",
63-
"vue-router": "^4.0.2"
64+
"vue-router": "^4.0.3"
6465
}
6566
}

0 commit comments

Comments
 (0)