@@ -35,7 +35,8 @@ export interface ModuleHooks {
3535
3636}
3737
38- const SchemaOrgPkg = '@vueuse/schema-org'
38+ const Pkg = '@vueuse/schema-org'
39+ const RuntimeDir = '#vueuse/schema-org/runtime'
3940
4041export default defineNuxtModule < ModuleOptions > ( {
4142 meta : {
@@ -48,33 +49,30 @@ export default defineNuxtModule<ModuleOptions>({
4849 const { resolve, resolvePath } = createResolver ( import . meta. url )
4950
5051 // avoid unwanted behavior with different package managers
51- const schemaOrgPath = dirname ( await resolvePath ( SchemaOrgPkg ) )
52+ const schemaOrgPath = dirname ( await resolvePath ( Pkg ) )
5253
53- const runtimeDir = resolve ( './runtime' )
54- const coreRuntimeDir = await resolvePath ( `${ schemaOrgPath } /runtime` )
55- nuxt . options . build . transpile . push ( runtimeDir )
56- nuxt . options . build . transpile . push ( coreRuntimeDir )
54+ const moduleRuntime = resolve ( './runtime' )
55+ nuxt . options . build . transpile . push ( ...[ moduleRuntime , RuntimeDir ] )
5756
58- // if (nuxt.options.dev )
59- // config.loadClientSide = true
57+ if ( typeof moduleOptions . client === 'undefined' )
58+ moduleOptions . client = ! ! nuxt . options . dev
6059
61- // allow users to opt-out of client side scripts, if it's not dev
60+ // fallback clears schema on route change
6261 if ( ! moduleOptions . client )
63- addPlugin ( resolve ( runtimeDir , 'plugin-fallback.client' ) )
62+ addPlugin ( resolve ( moduleRuntime , 'plugin-fallback.client' ) )
6463
6564 addPlugin ( {
66- src : resolve ( runtimeDir , 'plugin' ) ,
65+ src : resolve ( moduleRuntime , 'plugin' ) ,
6766 mode : moduleOptions . client ? 'all' : 'server' ,
6867 } )
6968
7069 // might need this again
71- nuxt . options . alias [ SchemaOrgPkg ] = schemaOrgPath
70+ nuxt . options . alias [ Pkg ] = schemaOrgPath
71+ // set the alias for the types
72+ nuxt . options . alias [ '#vueuse/schema-org/provider' ] = await resolvePath ( `${ schemaOrgPath } /providers/full` )
73+ nuxt . options . alias [ '#vueuse/schema-org/runtime' ] = await resolvePath ( `${ schemaOrgPath } /runtime` )
7274
7375 nuxt . hook ( 'vite:extendConfig' , ( config , { isClient } ) => {
74- config . optimizeDeps = config . optimizeDeps || { }
75- config . optimizeDeps . exclude = config . optimizeDeps . exclude || [ ]
76- config . optimizeDeps . exclude . push ( SchemaOrgPkg )
77-
7876 config . plugins = config . plugins || [ ]
7977 config . plugins . push ( SchemaOrgVitePlugin ( {
8078 mock : ! moduleOptions . client && isClient ,
@@ -89,15 +87,23 @@ export default defineNuxtModule<ModuleOptions>({
8987
9088 nuxt . hooks . hook ( 'autoImports:sources' , ( autoImports ) => {
9189 autoImports . unshift ( {
92- from : `${ runtimeDir } /composables` ,
90+ from : `${ moduleRuntime } /composables` ,
9391 imports : [
94- 'useSchemaOrg' ,
9592 'injectSchemaOrg' ,
96- ...RootSchemas
97- . map ( schema => [ `define${ schema } ` ] )
98- . flat ( ) ,
9993 ] ,
10094 } )
95+ autoImports . unshift ( {
96+ from : '#vueuse/schema-org/runtime' ,
97+ imports : [
98+ 'useSchemaOrg' ,
99+ ] ,
100+ } )
101+ autoImports . unshift ( {
102+ from : '#vueuse/schema-org/provider' ,
103+ imports : RootSchemas
104+ . map ( schema => [ `define${ schema } ` ] )
105+ . flat ( ) ,
106+ } )
101107 } )
102108
103109 schemaOrgComponents . forEach ( ( component ) => {
0 commit comments