Skip to content

Commit

Permalink
fix: try to only parse meta once during ssr build (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
stafyniaksacha committed Mar 21, 2023
1 parent 0d7d1df commit e7e61fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export function useComponentMetaParser (
const startTime = performance.now()
await Promise.all(Object.values(components).map(fetchComponent))
const endTime = performance.now()
if (!debug) { logger.success(`Components metas parsed in ${(endTime - startTime).toFixed(2)}ms`) }
if (!debug || debug === 2) { logger.success(`Components metas parsed in ${(endTime - startTime).toFixed(2)}ms`) }
}

return {
Expand Down
8 changes: 8 additions & 0 deletions src/unplugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@ type ComponentMetaUnpluginOptions = { parser?: ComponentMetaParser } & ModuleOpt
export const metaPlugin = createUnplugin<ComponentMetaUnpluginOptions>(
({ parser, ...options }) => {
const instance = (parser || useComponentMetaParser(options)) as ComponentMetaParser
let _configResolved: any

return {
name: 'vite-plugin-nuxt-component-meta',
enforce: 'post',
async buildStart () {
// avoid parsing meta twice in SSR
if (_configResolved?.build.ssr) {
return
}
await instance.fetchComponents()
await instance.updateOutput()
},
vite: {
configResolved (config) {
_configResolved = config
},
async handleHotUpdate ({ file }) {
if (Object.entries(instance.components).some(([, comp]: any) => comp.fullPath === file)) {
await instance.fetchComponent(file)
Expand Down

0 comments on commit e7e61fe

Please sign in to comment.