fix(module): handle theme HMR on dev (#84)

Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
Anthony Fu
2024-06-07 20:47:59 +03:00
committed by GitHub
parent efb7582b37
commit 12ba480d34
6 changed files with 15 additions and 54 deletions

View File

@@ -1,3 +1,4 @@
import { fileURLToPath } from 'node:url'
import { kebabCase } from 'scule'
import { addTemplate, addTypeTemplate } from '@nuxt/kit'
import type { Nuxt } from '@nuxt/schema'
@@ -298,6 +299,16 @@ export function addTemplates(options: ModuleOptions, nuxt: Nuxt) {
})
}
// For local development, directly import from theme
if (process.env.DEV) {
return [
`import template from ${JSON.stringify(fileURLToPath(new URL(`./theme/${kebabCase(component)}`, import.meta.url)))}`,
`const result = typeof template === 'function' ? template(${JSON.stringify({ colors: options.colors })}) : template`,
`export default result`,
`/* export default ${json} */`
].join('\n')
}
return `export default ${json}`
}
})