Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: try to only parse meta once during ssr build #54

Merged
merged 5 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,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
if (_configResolved && !_configResolved.build.ssr) {
stafyniaksacha marked this conversation as resolved.
Show resolved Hide resolved
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