mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-23 16:30:45 +01:00
fix(module): handle theme HMR on dev (#84)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
@@ -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}`
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user