get tailwindcss context at runtime!
- Install package
<yarn|npm|pnpm> add -D ts-patch
- Patch tailwindcss
npx tw-patch
- Add
prepare
script (keeps patch persisted after npm install)
package.json
{
/* ... */
"scripts": {
"prepare": "tw-patch"
}
}
import { getContexts, getClassCacheSet } from 'tailwindcss-patch'
// get all contexts at runtime
getContexts()
// get all class generated by tailwindcss utilities
getClassCacheSet()
getContexts
,getClassCacheSet
should be invoked after postcss-loader
's activation.
which means you may not get tailwindcss contexts at build start time.
you may call them at generateBundle
lifetime hook in vite/webpack plugin
.