Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
56883e7
WIP
philipp-spiess Mar 26, 2025
747dacf
Do what needs to be done
philipp-spiess Mar 27, 2025
40ba52b
Improve Next.js playground
philipp-spiess Mar 28, 2025
5183f44
De-duplicate `lightningcss` configuration
philipp-spiess Mar 28, 2025
6937fef
Simplify `color-mix(…)` inlining and adding unit tests
philipp-spiess Mar 28, 2025
e7f48b6
Revert changes to tsconfig
philipp-spiess Mar 28, 2025
19e4beb
Update snapshots
philipp-spiess Mar 28, 2025
f3e2993
Make the `@property` stuff disable-able
philipp-spiess Mar 28, 2025
1460365
PostCSS should not polyfill `@property` for CSS module files
philipp-spiess Mar 28, 2025
f6f78b1
Update more snapshots
philipp-spiess Mar 28, 2025
4c01e6f
Update snapshots
philipp-spiess Mar 31, 2025
74c5cef
Emit `@property` fallbacks at the beginning of the file
philipp-spiess Mar 31, 2025
eb801de
Add test case to stuff
philipp-spiess Mar 31, 2025
77eb998
Update snapshots
philipp-spiess Mar 31, 2025
e4ecce7
Refactor `replaceShadowColors(…)` to print AST
philipp-spiess Mar 31, 2025
9bddc09
Add fallbacks for new relative color usage
philipp-spiess Mar 31, 2025
8f09cac
More snapshot updates and comments
philipp-spiess Mar 31, 2025
5be1398
Don't use regex for replacement
philipp-spiess Mar 31, 2025
78e10dc
Further reduce the precision of color values because lightningcss pre…
philipp-spiess Mar 31, 2025
cbcf42a
Fix regex
philipp-spiess Mar 31, 2025
0ad7aad
Fix Svelte tests
philipp-spiess Mar 31, 2025
0bbcd09
Still needs a layer and fix supports query
philipp-spiess Mar 31, 2025
7d6fabc
Even more snapshot updates
philipp-spiess Mar 31, 2025
66c2c48
So. Many. Snapshots
philipp-spiess Mar 31, 2025
ddace46
Apply cleanups and also flag `color-mix(…)` polyfills so they aren't …
philipp-spiess Apr 1, 2025
8e54832
Revert changes to `replaceShadowColors(…)` and move polyfill closer t…
philipp-spiess Apr 1, 2025
79144ce
Update color values in `colors.ts`
philipp-spiess Apr 1, 2025
9244037
Update snapshots
philipp-spiess Apr 1, 2025
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
De-duplicate lightningcss configuration
  • Loading branch information
philipp-spiess committed Apr 1, 2025
commit 5183f44d002cf8934b9b0f215a79025b418ebedb
1 change: 0 additions & 1 deletion packages/@tailwindcss-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"@tailwindcss/node": "workspace:*",
"@tailwindcss/oxide": "workspace:*",
"enhanced-resolve": "^5.18.1",
"lightningcss": "catalog:",
"mri": "^1.2.0",
"picocolors": "^1.1.1",
"tailwindcss": "workspace:*"
Expand Down
37 changes: 2 additions & 35 deletions packages/@tailwindcss-cli/src/commands/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import watcher from '@parcel/watcher'
import { compile, env, Instrumentation } from '@tailwindcss/node'
import { clearRequireCache } from '@tailwindcss/node/require-cache'
import { Scanner, type ChangedContent } from '@tailwindcss/oxide'
import { Features, transform } from 'lightningcss'
import { existsSync, type Stats } from 'node:fs'
import fs from 'node:fs/promises'
import path from 'node:path'
import { optimize } from '../../../../@tailwindcss-node/src'
import type { Arg, Result } from '../../utils/args'
import { Disposables } from '../../utils/disposables'
import {
Expand Down Expand Up @@ -128,7 +128,7 @@ export async function handle(args: Result<ReturnType<typeof options>>) {
if (args['--minify'] || args['--optimize']) {
if (css !== previous.css) {
DEBUG && I.start('Optimize CSS')
let optimizedCss = optimizeCss(css, {
let optimizedCss = optimize(css, {
file: args['--input'] ?? 'input.css',
minify: args['--minify'] ?? false,
})
Expand Down Expand Up @@ -430,39 +430,6 @@ async function createWatchers(dirs: string[], cb: (files: string[]) => void) {
}
}

function optimizeCss(
input: string,
{ file = 'input.css', minify = false }: { file?: string; minify?: boolean } = {},
) {
function optimize(code: Buffer | Uint8Array) {
return transform({
filename: file,
code,
minify,
sourceMap: false,
drafts: {
customMedia: true,
},
nonStandard: {
deepSelectorCombinator: true,
},
include: Features.Nesting | Features.MediaQueries,
exclude: Features.LogicalProperties | Features.DirSelector | Features.LightDark,
targets: {
safari: (16 << 16) | (4 << 8),
ios_saf: (16 << 16) | (4 << 8),
firefox: 128 << 16,
chrome: 111 << 16,
},
errorRecovery: true,
}).code
}

// Running Lightning CSS twice to ensure that adjacent rules are merged after
// nesting is applied. This creates a more optimized output.
return optimize(optimize(Buffer.from(input))).toString()
}

function watchDirectories(scanner: Scanner) {
return [...new Set(scanner.normalizedSources.flatMap((globEntry) => globEntry.base))]
}
3 changes: 2 additions & 1 deletion packages/@tailwindcss-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"dependencies": {
"enhanced-resolve": "^5.18.1",
"jiti": "^2.4.2",
"tailwindcss": "workspace:*"
"tailwindcss": "workspace:*",
"lightningcss": "catalog:"
}
}
1 change: 1 addition & 0 deletions packages/@tailwindcss-node/src/index.cts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as env from './env'
export * from './compile'
export * from './instrumentation'
export * from './normalize-path'
export * from './optimize'
export { env }

// In Bun, ESM modules will also populate `require.cache`, so the module hook is
Expand Down
3 changes: 2 additions & 1 deletion packages/@tailwindcss-node/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as Module from 'node:module'
import { pathToFileURL } from 'node:url'
import * as env from './env'
export { __unstable__loadDesignSystem, compile, compileAst, Features } from './compile'
export * from './compile'
export * from './instrumentation'
export * from './normalize-path'
export * from './optimize'
export { env }

// In Bun, ESM modules will also populate `require.cache`, so the module hook is
Expand Down
40 changes: 40 additions & 0 deletions packages/@tailwindcss-node/src/optimize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Features, transform } from 'lightningcss'

export function optimize(
input: string,
{ file = 'input.css', minify = false }: { file?: string; minify?: boolean } = {},
): string {
function optimize(code: Buffer | Uint8Array) {
return transform({
filename: file,
code: code as any,
minify,
sourceMap: false,
drafts: {
customMedia: true,
},
nonStandard: {
deepSelectorCombinator: true,
},
include: Features.Nesting | Features.MediaQueries,
exclude: Features.LogicalProperties | Features.DirSelector | Features.LightDark,
targets: {
safari: (16 << 16) | (4 << 8),
ios_saf: (16 << 16) | (4 << 8),
firefox: 128 << 16,
chrome: 111 << 16,
},
errorRecovery: true,
}).code
}

// Running Lightning CSS twice to ensure that adjacent rules are merged after
// nesting is applied. This creates a more optimized output.
let out = optimize(optimize(Buffer.from(input))).toString()

// Work around an issue where the media query range syntax transpilation
// generates code that is invalid with `@media` queries level 3.
out = out.replaceAll(/\@media not \(/g, '@media not all and (')

return out
}
1 change: 0 additions & 1 deletion packages/@tailwindcss-postcss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"@alloc/quick-lru": "^5.2.0",
"@tailwindcss/node": "workspace:*",
"@tailwindcss/oxide": "workspace:*",
"lightningcss": "catalog:",
"postcss": "^8.4.41",
"tailwindcss": "workspace:*"
},
Expand Down
49 changes: 8 additions & 41 deletions packages/@tailwindcss-postcss/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import QuickLRU from '@alloc/quick-lru'
import { compileAst, env, Features, Instrumentation } from '@tailwindcss/node'
import {
compileAst,
env,
Features,
Instrumentation,
optimize as optimizeCss,
} from '@tailwindcss/node'
import { clearRequireCache } from '@tailwindcss/node/require-cache'
import { Scanner } from '@tailwindcss/oxide'
import { Features as LightningCssFeatures, transform } from 'lightningcss'
import fs from 'node:fs'
import path, { relative } from 'node:path'
import postcss, { type AcceptedPlugin, type PluginCreator } from 'postcss'
Expand Down Expand Up @@ -268,6 +273,7 @@ function tailwindcss(opts: PluginOptions = {}): AcceptedPlugin {
DEBUG && I.end('AST -> CSS')

DEBUG && I.start('Lightning CSS')
// @ts-ignore
let ast = optimizeCss(css, {
minify: typeof optimize === 'object' ? optimize.minify : true,
})
Expand Down Expand Up @@ -308,43 +314,4 @@ function tailwindcss(opts: PluginOptions = {}): AcceptedPlugin {
}
}

function optimizeCss(
input: string,
{ file = 'input.css', minify = false }: { file?: string; minify?: boolean } = {},
) {
function optimize(code: Buffer | Uint8Array) {
return transform({
filename: file,
code,
minify,
sourceMap: false,
drafts: {
customMedia: true,
},
nonStandard: {
deepSelectorCombinator: true,
},
include: LightningCssFeatures.Nesting | LightningCssFeatures.MediaRangeSyntax,
exclude:
LightningCssFeatures.LogicalProperties |
LightningCssFeatures.DirSelector |
LightningCssFeatures.LightDark,
targets: {
safari: (15 << 16) | (4 << 8),
ios_saf: (16 << 16) | (4 << 8),
firefox: 128 << 16,
chrome: 111 << 16,
},
errorRecovery: true,
}).code
}

let out = optimize(optimize(Buffer.from(input))).toString()
out = out.replaceAll(/\@media (\()?not /g, '@media $1not all and ')

// Running Lightning CSS twice to ensure that adjacent rules are merged after
// nesting is applied. This creates a more optimized output.
return out
}

export default Object.assign(tailwindcss, { postcss: true }) as PluginCreator<PluginOptions>
1 change: 0 additions & 1 deletion packages/@tailwindcss-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"dependencies": {
"@tailwindcss/node": "workspace:*",
"@tailwindcss/oxide": "workspace:*",
"lightningcss": "catalog:",
"tailwindcss": "workspace:*"
},
"devDependencies": {
Expand Down
41 changes: 2 additions & 39 deletions packages/@tailwindcss-vite/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { compile, env, Features, Instrumentation, normalizePath } from '@tailwindcss/node'
import { compile, env, Features, Instrumentation, normalizePath, optimize } from '@tailwindcss/node'
import { clearRequireCache } from '@tailwindcss/node/require-cache'
import { Scanner } from '@tailwindcss/oxide'
import { Features as LightningCssFeatures, transform } from 'lightningcss'
import fs from 'node:fs/promises'
import path from 'node:path'
import type { Plugin, ResolvedConfig, ViteDevServer } from 'vite'
Expand Down Expand Up @@ -102,7 +101,7 @@ export default function tailwindcss(): Plugin[] {
DEBUG && I.end('[@tailwindcss/vite] Generate CSS (build)')

DEBUG && I.start('[@tailwindcss/vite] Optimize CSS')
generated = optimizeCss(generated, { minify })
generated = optimize(generated, { minify })
DEBUG && I.end('[@tailwindcss/vite] Optimize CSS')

return { code: generated }
Expand All @@ -127,42 +126,6 @@ function isPotentialCssRootFile(id: string) {
return isCssFile
}

function optimizeCss(
input: string,
{ file = 'input.css', minify = false }: { file?: string; minify?: boolean } = {},
) {
function optimize(code: Buffer | Uint8Array | any) {
return transform({
filename: file,
code,
minify,
sourceMap: false,
drafts: {
customMedia: true,
},
nonStandard: {
deepSelectorCombinator: true,
},
include: LightningCssFeatures.Nesting | LightningCssFeatures.MediaQueries,
exclude:
LightningCssFeatures.LogicalProperties |
LightningCssFeatures.DirSelector |
LightningCssFeatures.LightDark,
targets: {
safari: (16 << 16) | (4 << 8),
ios_saf: (16 << 16) | (4 << 8),
firefox: 128 << 16,
chrome: 111 << 16,
},
errorRecovery: true,
}).code
}

// Running Lightning CSS twice to ensure that adjacent rules are merged after
// nesting is applied. This creates a more optimized output.
return optimize(optimize(Buffer.from(input))).toString()
}

function idToPath(id: string) {
return path.resolve(id.replace(/\?.*$/, ''))
}
Expand Down
39 changes: 4 additions & 35 deletions packages/tailwindcss/src/test-utils/run.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,18 @@
import { Features, transform } from 'lightningcss'
import { compile } from '..'
import { optimize } from '../../../@tailwindcss-node/src/optimize'

export async function compileCss(
css: string,
candidates: string[] = [],
options: Parameters<typeof compile>[1] = {},
) {
let { build } = await compile(css, options)
return optimizeCss(build(candidates)).trim()
return optimize(build(candidates)).trim()
}

export async function run(candidates: string[]) {
let { build } = await compile('@tailwind utilities;')
return optimizeCss(build(candidates)).trim()
return optimize(build(candidates)).trim()
}

export function optimizeCss(
input: string,
{ file = 'input.css', minify = false }: { file?: string; minify?: boolean } = {},
) {
function optimize(code: Buffer | Uint8Array) {
return transform({
filename: file,
code,
minify,
sourceMap: false,
drafts: {
customMedia: true,
},
nonStandard: {
deepSelectorCombinator: true,
},
include: Features.Nesting | Features.MediaQueries,
exclude: Features.LogicalProperties | Features.DirSelector | Features.LightDark,
targets: {
safari: (16 << 16) | (4 << 8),
ios_saf: (16 << 16) | (4 << 8),
firefox: 128 << 16,
chrome: 111 << 16,
},
errorRecovery: true,
}).code
}

// Running Lightning CSS twice to ensure that adjacent rules are merged after
// nesting is applied. This creates a more optimized output.
return optimize(optimize(Buffer.from(input))).toString()
}
export const optimizeCss = optimize
Loading