Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Only add a @theme block when there are theme keys
  • Loading branch information
philipp-spiess committed Oct 14, 2024
commit afb3d86b51979d36ec29af6a21e127c3df97949b
11 changes: 9 additions & 2 deletions packages/@tailwindcss-upgrade/src/migrate-js-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export async function migrateJsConfig(
}

if ('theme' in unresolvedConfig) {
cssConfigs.push(await migrateTheme(unresolvedConfig as any))
let themeConfig = await migrateTheme(unresolvedConfig as any)
if (themeConfig) cssConfigs.push(themeConfig)
}

return {
Expand All @@ -59,7 +60,7 @@ export async function migrateJsConfig(
}
}

async function migrateTheme(unresolvedConfig: Config & { theme: any }): Promise<string> {
async function migrateTheme(unresolvedConfig: Config & { theme: any }): Promise<string | null> {
let { extend: extendTheme, ...overwriteTheme } = unresolvedConfig.theme

let resetNamespaces = new Map<string, boolean>()
Expand All @@ -80,10 +81,12 @@ async function migrateTheme(unresolvedConfig: Config & { theme: any }): Promise<
let prevSectionKey = ''

let css = `@theme {`
let containsThemeKeys = false
for (let [key, value] of themeableValues(themeValues)) {
if (typeof value !== 'string' && typeof value !== 'number') {
continue
}
containsThemeKeys = true

let sectionKey = createSectionKey(key)
if (sectionKey !== prevSectionKey) {
Expand All @@ -99,6 +102,10 @@ async function migrateTheme(unresolvedConfig: Config & { theme: any }): Promise<
css += ` --${keyPathToCssProperty(key)}: ${value};\n`
}

if (!containsThemeKeys) {
return null
}

return css + '}\n'
}

Expand Down