File tree Expand file tree Collapse file tree 4 files changed +59
-3
lines changed
Expand file tree Collapse file tree 4 files changed +59
-3
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ export default defineBuildConfig({
1010 { input : 'src/index' } ,
1111 { input : 'src/vitesse' } ,
1212 { input : 'src/vitepress' } ,
13+ { input : 'src/vite' } ,
1314 ] ,
1415 externals : [
1516 '@vueuse/schema-org' ,
Original file line number Diff line number Diff line change 2828 "require" : " ./dist/index.cjs" ,
2929 "import" : " ./dist/index.mjs"
3030 },
31+ "./vite" : {
32+ "types" : " ./dist/vite.d.ts" ,
33+ "require" : " ./dist/vite.cjs" ,
34+ "import" : " ./dist/vite.mjs"
35+ },
3136 "./vitesse" : {
3237 "types" : " ./dist/vitesse.d.ts" ,
3338 "require" : " ./dist/vitesse.cjs" ,
7883 "unplugin-vue-components" : " ^0.22.4" ,
7984 "vite" : " ^3.0.8" ,
8085 "vite-ssg" : " ^0.20.2" ,
81- "vitepress" : " 1.0.0-alpha.8"
86+ "vitepress" : " 1.0.0-alpha.8" ,
87+ "vue-router" : " ^4.1.4"
8288 }
8389}
Original file line number Diff line number Diff line change @@ -119,5 +119,6 @@ export const AliasRuntimePlugin = () => createUnplugin<AliasPluginOptions>((user
119119 }
120120} )
121121
122- export const AliasRuntimePluginWebpack = ( args : AliasPluginOptions ) => AliasRuntimePlugin ( ) . webpack ( args )
123- export const AliasRuntimePluginVite = ( args : AliasPluginOptions ) => AliasRuntimePlugin ( ) . vite ( args )
122+ export const AliasRuntimePluginWebpack = ( args ?: AliasPluginOptions ) => AliasRuntimePlugin ( ) . webpack ( args || { } )
123+ export const AliasRuntimePluginVite = ( args ?: AliasPluginOptions ) => AliasRuntimePlugin ( ) . vite ( args || { } )
124+ export const SchemaOrg = AliasRuntimePluginVite
Original file line number Diff line number Diff line change 1+ import { createSchemaOrg , resolveUserConfig } from '@vueuse/schema-org'
2+ import type { UserConfig } from '@vueuse/schema-org'
3+ import type { App } from 'vue'
4+ import { createHead } from '@vueuse/head'
5+ import type { Router } from 'vue-router'
6+
7+ export function installSchemaOrg ( ctx : { app : App ; router ?: Router } , config : UserConfig ) {
8+ const resolvedConfig = resolveUserConfig ( config )
9+
10+ let head = ctx . app . _context . provides . usehead
11+ if ( ! head ) {
12+ head = createHead ( )
13+ ctx . app . use ( head )
14+ }
15+
16+ const client = createSchemaOrg ( {
17+ updateHead ( fn ) {
18+ head . addHeadObjs ( fn )
19+ if ( typeof document !== 'undefined' )
20+ head . updateDOM ( )
21+ } ,
22+ meta ( ) {
23+ // const inferredMeta: Record<string, any> = {}
24+
25+ return {
26+ path : ctx . router ?. currentRoute . value . path || '/' ,
27+ ...resolvedConfig . meta ,
28+ ...ctx . router ?. currentRoute . value . meta || { } ,
29+ }
30+ } ,
31+ } )
32+
33+ ctx . app . use ( client )
34+
35+ if ( typeof document === 'undefined' ) {
36+ client . generateSchema ( )
37+ client . setupDOM ( )
38+ return
39+ }
40+
41+ if ( ctx . router ) {
42+ ctx . router . afterEach ( ( ) => {
43+ client . generateSchema ( )
44+ client . setupDOM ( )
45+ } )
46+ }
47+ return client
48+ }
You can’t perform that action at this time.
0 commit comments