pre-publish-optimizations.mjs 731 B

12345678910111213141516171819202122
  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. // Performance optimization: Inline the contents of the `tailwindcss/index.css`
  7. // file so that we don't need to handle imports at runtime.
  8. {
  9. let __dirname = path.dirname(new URL(import.meta.url).pathname)
  10. let file = path.resolve(__dirname, '../packages/tailwindcss/index.css')
  11. let contents = await fs.readFile(file, 'utf-8')
  12. let inlined = await prettier.format(
  13. await postcss()
  14. .use(atImport())
  15. .process(contents, { from: file })
  16. .then((result) => result.css),
  17. { filepath: file },
  18. )
  19. await fs.writeFile(file, inlined, 'utf-8')
  20. }