Skip to content

Commit 9fc5aa1

Browse files
RobinMalfaitthecrypticaceadamwathan
authored
Inline the tailwindcss/index.css contents at publish time (#13233)
* add `pre-publish-optimizations` script * handle `@import` ourselves This implementation is fairly simple right now, because we don't have to worry about resolving folders or modules since we don't use them. * pretty print index.css file * update changelog * Revert "handle `@import` ourselves" This reverts commit 13a4640. * drop the `1.` * Update scripts/pre-publish-optimizations.mjs Co-authored-by: Jordan Pittman <jordan@cryptica.me> * Update CHANGELOG.md Co-authored-by: Adam Wathan <adam.wathan@gmail.com> * run prettier --------- Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
1 parent 44394b1 commit 9fc5aa1

File tree

5 files changed

+41
-9
lines changed

5 files changed

+41
-9
lines changed

.github/workflows/release-oxide.yml

+3
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ jobs:
219219
cp bindings-x86_64-unknown-linux-gnu/* ./npm/linux-x64-gnu/
220220
cp bindings-x86_64-unknown-linux-musl/* ./npm/linux-x64-musl/
221221
222+
- name: Run pre-publish optimizations scripts
223+
run: node ./scripts/pre-publish-optimizations.mjs
224+
222225
- name: Lock pre-release versions
223226
run: node ./scripts/lock-pre-release-versions.mjs
224227

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Nothing yet!
10+
### Changed
11+
12+
- Inline `@import` rules in `tailwindcss/index.css` at publish time for better performance ([#13233](https://github.com/tailwindlabs/tailwindcss/pull/13233))
1113

1214
## [4.0.0-alpha.9] - 2024-03-13
1315

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
"@playwright/test": "^1.41.2",
3939
"@types/node": "^20.11.19",
4040
"@vitest/coverage-v8": "^1.2.1",
41+
"postcss": "8.4.24",
42+
"postcss-import": "^16.0.0",
4143
"prettier": "^3.2.5",
4244
"prettier-plugin-organize-imports": "^3.2.4",
4345
"tsup": "^8.0.1",

pnpm-lock.yaml

+12-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/pre-publish-optimizations.mjs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import fs from 'node:fs/promises'
2+
import path from 'node:path'
3+
import postcss from 'postcss'
4+
import atImport from 'postcss-import'
5+
import prettier from 'prettier'
6+
7+
// Performance optimization: Inline the contents of the `tailwindcss/index.css`
8+
// file so that we don't need to handle imports at runtime.
9+
{
10+
let __dirname = path.dirname(new URL(import.meta.url).pathname)
11+
let file = path.resolve(__dirname, '../packages/tailwindcss/index.css')
12+
let contents = await fs.readFile(file, 'utf-8')
13+
let inlined = await prettier.format(
14+
await postcss()
15+
.use(atImport())
16+
.process(contents, { from: file })
17+
.then((result) => result.css),
18+
{ filepath: file },
19+
)
20+
await fs.writeFile(file, inlined, 'utf-8')
21+
}

0 commit comments

Comments
 (0)