chore: simplify theme imports in dev (#3851)

This commit is contained in:
Sandro Circi
2025-04-10 15:59:04 +02:00
committed by GitHub
parent 8c68af5e3b
commit fb4c210b41
3 changed files with 8 additions and 6 deletions

View File

@@ -10,7 +10,8 @@ export default defineBuildConfig({
replace: { replace: {
delimiters: ['', ''], delimiters: ['', ''],
values: { values: {
'process.argv.at(-1) === \'--uiDev\'': 'false' // Used in development to import directly from theme
'const isUiDev = true': 'const isUiDev = false'
} }
} }
}, },

View File

@@ -96,12 +96,12 @@
"scripts": { "scripts": {
"build": "nuxt-module-build build", "build": "nuxt-module-build build",
"prepack": "pnpm build", "prepack": "pnpm build",
"dev": "nuxi dev playground --uiDev", "dev": "nuxi dev playground",
"dev:build": "nuxi build playground", "dev:build": "nuxi build playground",
"dev:vue": "vite playground-vue -- --uiDev", "dev:vue": "vite playground-vue",
"dev:vue:build": "vite build playground-vue", "dev:vue:build": "vite build playground-vue",
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground && nuxi prepare docs && vite build playground-vue", "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground && nuxi prepare docs && vite build playground-vue",
"docs": "nuxi dev docs --uiDev", "docs": "nuxi dev docs",
"docs:build": "nuxi build docs", "docs:build": "nuxi build docs",
"docs:prepare": "nuxt-component-meta docs", "docs:prepare": "nuxt-component-meta docs",
"lint": "eslint .", "lint": "eslint .",

View File

@@ -50,12 +50,13 @@ export function getTemplates(options: ModuleOptions, uiConfig: Record<string, an
} }
// For local development, import directly from theme // For local development, import directly from theme
if (process.argv.at(-1) === '--uiDev') { const isUiDev = true
if (isUiDev) {
const templatePath = fileURLToPath(new URL(`./theme/${kebabCase(component)}`, import.meta.url)) const templatePath = fileURLToPath(new URL(`./theme/${kebabCase(component)}`, import.meta.url))
return [ return [
`import template from ${JSON.stringify(templatePath)}`, `import template from ${JSON.stringify(templatePath)}`,
...generateVariantDeclarations(variants), ...generateVariantDeclarations(variants),
`const result = typeof template === 'function' ? template(${JSON.stringify(options, null, 2)}) : template`, `const result = typeof template === 'function' ? (template as Function)(${JSON.stringify(options, null, 2)}) : template`,
`const theme = ${json}`, `const theme = ${json}`,
`export default result as typeof theme` `export default result as typeof theme`
].join('\n\n') ].join('\n\n')