Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Do not generate `grid-row` utilities when configuring `grid-row-start` or `grid-row-end` ([#18907](https://github.com/tailwindlabs/tailwindcss/pull/18907))
- Prevent duplicate CSS when overwriting a static utility with a theme key ([#18056](https://github.com/tailwindlabs/tailwindcss/pull/18056))
- Do not migrate `variant = 'outline'` during upgrades ([#18922](https://github.com/tailwindlabs/tailwindcss/pull/18922))
- Show Lightning CSS warnings (if any) when optimizing/minifying ([#18918](https://github.com/tailwindlabs/tailwindcss/pull/18918))

## [4.1.13] - 2025-09-03

Expand Down
50 changes: 50 additions & 0 deletions packages/@tailwindcss-node/src/optimize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,48 @@ export function optimize(
let result = optimize(Buffer.from(input), map)
map = result.map?.toString()

// Because of `errorRecovery: true`, there could be warnings, so let's let the
// user know about them.
if (process.env.NODE_ENV !== 'test' && result.warnings.length > 0) {
let lines = input.split('\n')

let output = [
`Found ${result.warnings.length} ${result.warnings.length === 1 ? 'warning' : 'warnings'} while optimizing generated CSS:`,
]

for (let [idx, warning] of result.warnings.entries()) {
output.push('')
if (result.warnings.length > 1) {
output.push(`Issue #${idx + 1}:`)
}

let context = 2

let start = Math.max(0, warning.loc.line - context - 1)
let end = Math.min(lines.length, warning.loc.line + context)

let snippet = lines.slice(start, end).map((line, idx) => {
if (start + idx + 1 === warning.loc.line) {
return `${dim(`\u2502`)} ${line}`
} else {
return dim(`\u2502 ${line}`)
}
})

snippet.splice(
warning.loc.line - start,
0,
`${dim('\u2506')}${' '.repeat(warning.loc.column - 1)} ${yellow(`${dim('^--')} ${warning.message}`)}`,
`${dim('\u2506')}`,
)

output.push(...snippet)
}
output.push('')

console.warn(output.join('\n'))
}

result = optimize(result.code, map)
map = result.map?.toString()

Expand Down Expand Up @@ -88,3 +130,11 @@ export function optimize(
map,
}
}

function dim(str: string) {
return `\x1B[2m${str}\x1B[22m`
}

function yellow(str: string) {
return `\x1B[33m${str}\x1B[39m`
}
12 changes: 12 additions & 0 deletions packages/@tailwindcss-node/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,35 @@ export default defineConfig([
minify: true,
dts: true,
entry: ['src/index.cts'],
define: {
'process.env.NODE_ENV': '"production"',
},
},
{
format: ['esm'],
minify: true,
dts: true,
entry: ['src/index.ts'],
define: {
'process.env.NODE_ENV': '"production"',
},
},
{
format: ['esm'],
minify: true,
dts: true,
entry: ['src/esm-cache.loader.mts'],
define: {
'process.env.NODE_ENV': '"production"',
},
},
{
format: ['cjs'],
minify: true,
dts: true,
entry: ['src/require-cache.cts'],
define: {
'process.env.NODE_ENV': '"production"',
},
},
])