tailwindcss/scripts/pre-publish-optimizations.mjs
Robin Malfait 9fc5aa16a3
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 13a46404c16ee67e4e1b7eaf58ae67321113eb07.

* 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>
2024-03-13 22:26:10 +01:00

22 lines
731 B
JavaScript

import fs from 'node:fs/promises'
import path from 'node:path'
import postcss from 'postcss'
import atImport from 'postcss-import'
import prettier from 'prettier'
// Performance optimization: Inline the contents of the `tailwindcss/index.css`
// file so that we don't need to handle imports at runtime.
{
let __dirname = path.dirname(new URL(import.meta.url).pathname)
let file = path.resolve(__dirname, '../packages/tailwindcss/index.css')
let contents = await fs.readFile(file, 'utf-8')
let inlined = await prettier.format(
await postcss()
.use(atImport())
.process(contents, { from: file })
.then((result) => result.css),
{ filepath: file },
)
await fs.writeFile(file, inlined, 'utf-8')
}