Skip to content

Commit 0ee3508

Browse files
authored
Move optimizeCss to the packages where it's used (#13230)
* add `@tailwindcss/optimize` as a separate package * remove lightningcss from `tailwindcss` * import `optimizeCss` from `@tailwindcss/optimize` * ensure we use `src/` files in development * move `devDependencies` after `dependencies` Just for consistency * inline `optimizeCss` in leaf packages Instead of introducing a custom `@tailwindcss/optimize` package * update changelog * fix changelog
1 parent 91fca13 commit 0ee3508

File tree

13 files changed

+141
-62
lines changed

13 files changed

+141
-62
lines changed

CHANGELOG.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
### Fixed
11-
12-
- Fix incorrect properties in line-clamp utilities ([#13220](https://github.com/tailwindlabs/tailwindcss/pull/13220))
13-
1410
### Added
1511

1612
- Support `@theme reference { … }` for defining theme values without emitting variables ([#13222](https://github.com/tailwindlabs/tailwindcss/pull/13222))
13+
- Move `optimizeCss` to the packages where it's used ([#13230](https://github.com/tailwindlabs/tailwindcss/pull/13230))
1714

1815
### Fixed
1916

17+
- Fix incorrect properties in line-clamp utilities ([#13220](https://github.com/tailwindlabs/tailwindcss/pull/13220))
2018
- Don't rely on existence of `--default-transition-*` variables in `transition-*` utilities ([#13219](https://github.com/tailwindlabs/tailwindcss/pull/13219))
2119

2220
## [4.0.0-alpha.8] - 2024-03-11

packages/@tailwindcss-cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"dependencies": {
3232
"@parcel/watcher": "^2.4.1",
3333
"@tailwindcss/oxide": "workspace:^",
34+
"lightningcss": "^1.24.0",
3435
"mri": "^1.2.0",
3536
"picocolors": "^1.0.0",
3637
"postcss": "8.4.24",

packages/@tailwindcss-cli/src/commands/build/index.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import watcher from '@parcel/watcher'
22
import { IO, Parsing, scanDir, scanFiles, type ChangedContent } from '@tailwindcss/oxide'
3+
import { Features, transform } from 'lightningcss'
34
import { existsSync } from 'node:fs'
45
import fs from 'node:fs/promises'
56
import path from 'node:path'
67
import postcss from 'postcss'
78
import atImport from 'postcss-import'
8-
import { compile, optimizeCss } from 'tailwindcss'
9+
import { compile } from 'tailwindcss'
910
import type { Arg, Result } from '../../utils/args'
1011
import {
1112
eprintln,
@@ -253,3 +254,27 @@ function handleImports(
253254
),
254255
])
255256
}
257+
258+
function optimizeCss(
259+
input: string,
260+
{ file = 'input.css', minify = false }: { file?: string; minify?: boolean } = {},
261+
) {
262+
return transform({
263+
filename: file,
264+
code: Buffer.from(input),
265+
minify,
266+
sourceMap: false,
267+
drafts: {
268+
customMedia: true,
269+
},
270+
nonStandard: {
271+
deepSelectorCombinator: true,
272+
},
273+
include: Features.Nesting,
274+
exclude: Features.LogicalProperties,
275+
targets: {
276+
safari: (16 << 16) | (4 << 8),
277+
},
278+
errorRecovery: true,
279+
}).code.toString()
280+
}

packages/@tailwindcss-postcss/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
},
3131
"dependencies": {
3232
"@tailwindcss/oxide": "workspace:^",
33+
"lightningcss": "^1.24.0",
3334
"postcss-import": "^16.0.0",
3435
"tailwindcss": "workspace:^"
3536
},

packages/@tailwindcss-postcss/src/index.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { scanDir } from '@tailwindcss/oxide'
22
import fs from 'fs'
3+
import { Features, transform } from 'lightningcss'
34
import postcss, { type AcceptedPlugin, type PluginCreator } from 'postcss'
45
import postcssImport from 'postcss-import'
5-
import { compile, optimizeCss } from 'tailwindcss'
6+
import { compile } from 'tailwindcss'
67

78
/**
89
* A Map that can generate default values for keys that don't exist.
@@ -150,4 +151,28 @@ function tailwindcss(opts: PluginOptions = {}): AcceptedPlugin {
150151
}
151152
}
152153

154+
function optimizeCss(
155+
input: string,
156+
{ file = 'input.css', minify = false }: { file?: string; minify?: boolean } = {},
157+
) {
158+
return transform({
159+
filename: file,
160+
code: Buffer.from(input),
161+
minify,
162+
sourceMap: false,
163+
drafts: {
164+
customMedia: true,
165+
},
166+
nonStandard: {
167+
deepSelectorCombinator: true,
168+
},
169+
include: Features.Nesting,
170+
exclude: Features.LogicalProperties,
171+
targets: {
172+
safari: (16 << 16) | (4 << 8),
173+
},
174+
errorRecovery: true,
175+
}).code.toString()
176+
}
177+
153178
export default Object.assign(tailwindcss, { postcss: true }) as PluginCreator<PluginOptions>

packages/@tailwindcss-vite/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
},
3030
"dependencies": {
3131
"@tailwindcss/oxide": "workspace:^",
32+
"lightningcss": "^1.24.0",
3233
"tailwindcss": "workspace:^"
3334
},
3435
"devDependencies": {

packages/@tailwindcss-vite/src/index.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { IO, Parsing, scanFiles } from '@tailwindcss/oxide'
2+
import { Features, transform } from 'lightningcss'
23
import path from 'path'
3-
import { compile, optimizeCss } from 'tailwindcss'
4+
import { compile } from 'tailwindcss'
45
import type { Plugin, Update, ViteDevServer } from 'vite'
56

67
export default function tailwindcss(): Plugin[] {
@@ -181,3 +182,27 @@ export default function tailwindcss(): Plugin[] {
181182
},
182183
] satisfies Plugin[]
183184
}
185+
186+
function optimizeCss(
187+
input: string,
188+
{ file = 'input.css', minify = false }: { file?: string; minify?: boolean } = {},
189+
) {
190+
return transform({
191+
filename: file,
192+
code: Buffer.from(input),
193+
minify,
194+
sourceMap: false,
195+
drafts: {
196+
customMedia: true,
197+
},
198+
nonStandard: {
199+
deepSelectorCombinator: true,
200+
},
201+
include: Features.Nesting,
202+
exclude: Features.LogicalProperties,
203+
targets: {
204+
safari: (16 << 16) | (4 << 8),
205+
},
206+
errorRecovery: true,
207+
}).code.toString()
208+
}

packages/tailwindcss/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,9 @@
5858
"theme.css",
5959
"utilities.css"
6060
],
61-
"dependencies": {
62-
"lightningcss": "^1.24.0"
63-
},
6461
"devDependencies": {
6562
"@tailwindcss/oxide": "workspace:^",
66-
"@types/node": "^20.10.8"
63+
"@types/node": "^20.10.8",
64+
"lightningcss": "^1.24.0"
6765
}
6866
}

packages/tailwindcss/src/index.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Features, transform } from 'lightningcss'
21
import { version } from '../package.json'
32
import { WalkAction, comment, decl, rule, toCss, walk, type AstNode, type Rule } from './ast'
43
import { compileCandidates } from './compile'
@@ -230,30 +229,6 @@ export function compile(css: string): {
230229
}
231230
}
232231

233-
export function optimizeCss(
234-
input: string,
235-
{ file = 'input.css', minify = false }: { file?: string; minify?: boolean } = {},
236-
) {
237-
return transform({
238-
filename: file,
239-
code: Buffer.from(input),
240-
minify,
241-
sourceMap: false,
242-
drafts: {
243-
customMedia: true,
244-
},
245-
nonStandard: {
246-
deepSelectorCombinator: true,
247-
},
248-
include: Features.Nesting,
249-
exclude: Features.LogicalProperties,
250-
targets: {
251-
safari: (16 << 16) | (4 << 8),
252-
},
253-
errorRecovery: true,
254-
}).code.toString()
255-
}
256-
257232
export function __unstable__loadDesignSystem(css: string) {
258233
// Find all `@theme` declarations
259234
let theme = new Theme()
Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { compile, optimizeCss } from '..'
1+
import { Features, transform } from 'lightningcss'
2+
import { compile } from '..'
23

34
export function compileCss(css: string, candidates: string[] = []) {
45
return optimizeCss(compile(css).build(candidates)).trim()
@@ -7,3 +8,27 @@ export function compileCss(css: string, candidates: string[] = []) {
78
export function run(candidates: string[]) {
89
return optimizeCss(compile('@tailwind utilities;').build(candidates)).trim()
910
}
11+
12+
export function optimizeCss(
13+
input: string,
14+
{ file = 'input.css', minify = false }: { file?: string; minify?: boolean } = {},
15+
) {
16+
return transform({
17+
filename: file,
18+
code: Buffer.from(input),
19+
minify,
20+
sourceMap: false,
21+
drafts: {
22+
customMedia: true,
23+
},
24+
nonStandard: {
25+
deepSelectorCombinator: true,
26+
},
27+
include: Features.Nesting,
28+
exclude: Features.LogicalProperties,
29+
targets: {
30+
safari: (16 << 16) | (4 << 8),
31+
},
32+
errorRecovery: true,
33+
}).code.toString()
34+
}

0 commit comments

Comments
 (0)