schema-org
schema-org copied to clipboard
Nuxt module improvements
Hi @harlan-zw and thanks for nice Nuxt module! Following up #374, I've made a quick review over the code and here are some improvement suggestions:
- With hybrid rendering, both SSR and SPA modes can happen. Please avoid to depend on
ssr
option to conditionally inject plugin here. You can use runtime logic andserverRendered
flag in the payloadto make a difference in the behavior - Since
@vueuse/schema-org
is an implicit dependency for Nuxt users (they installnuxt-schema-org
), I would make an alias for@vueuse/schema-org
to it's full path to avoid unwanted behavior with different package managers
Hey @pi0
Appreciate your time in looking over the module, thanks! I've fixed up the first issue you mentioned, it makes a lot more sense to do it like this.
Would you mind elaborating on what you mean by the second point? I understand the issue but not too sure what you're recommending as the fix.
I tried this but it ended up throwing a lot of errors, seemingly the import breaks.
const { resolve } = createResolver(import.meta.url)
nuxt.options.alias['@vueuse/schema-org'] = resolve('@vueuse/schema-org')
The naming might be confusing but resolve is similar to path.resolve
(await resolver.resolvePath
is the one you are looking for)
Ah of course, thanks.
I added the alias, I had an error when it was resolving to the index.cjs
file though:
[nuxt] [request error] Object.defineProperty called on non-object
at Function.defineProperty (<anonymous>)
at $id_16230e0f (./.nuxt/dist/server/server.mjs:3011:8)
at __instantiateModule__ (./.nuxt/dist/server/server.mjs:6319:9)
at __ssrLoadModule__ (./.nuxt/dist/server/server.mjs:6257:25)
at ssrImport (./.nuxt/dist/server/server.mjs:6282:13)
at $id_a3506958 (./.nuxt/dist/server/server.mjs:2982:37)
at async __instantiateModule__ (./.nuxt/dist/server/server.mjs:6319:3)
So I changed it to resolve to the dist
directory. Testing it seemed all good, but do you foresee any issues?
const schemaOrgPath = dirname(await resolvePath('@vueuse/schema-org'))
nuxt.options.alias['@vueuse/schema-org'] = schemaOrgPath
https://github.com/vueuse/schema-org/commit/bca8fea37c7810b439ba3f78256592e531356dae#diff-be7ecc6bc17358942938e025d26bee5e5c3664db77e2be717b644d96d3222172R52
Going to close this off as all the above issues were resolved, although have now been superseded by v1.
If you want to review the latest module, that would be awesome, but understand if you have limited capacity.