tailwindcss/packages
Jordan Pittman 8c6c291869
Make config resolution lazy (#14362)
The internal `registerPlugins()` API is used to enable backwards
compatibility with v3 plugins and configs and it is called on every
build even when no v3 plugins or configs are used. This function has a
non-trivial cost in that case — around 5ms.

So this PR does a few things:

## Implements a simpler, faster `theme(…)` function

We now have a much simpler `theme(…)` function that can be used when
backwards compatibility is not necessary. It still supports many of the
same features:
- The modern, v4 style CSS variable syntax `theme(--color-red-500)`
- The legacy, v3 path style `theme(colors.red.500)`
- And the v3-style alpha modifier `theme(colors.red.500 / 50%)`
- Path upgrades so things like `theme(accentColor.red.500)` pulls from
`--color-red-500` when no `--accent-color-red-500` theme key exists

When you do have plugins or configs the more advanced `theme(…)`
function is swapped in for more complete backwards compatibility.

## `registerPlugins` registers globs

Before `registerPlugins` passed the `ResolvedConfig` out so we could
register globs in `compile()`. Since that one function is really the
main driver for backwards compat we decided to move the content path
registration into `registerPlugins` itself when it comes to paths
provided by plugins and configs.

This is an internal implementation detail (well this entire PR is) but
it's worth mentioning. This method is used to resolve a theme value from
a theme key.

## `registerPlugins` is now only called when necessary

All of the above work made it so that `registerPlugins` can be called
only as needed. This means that when no v3 plugins or configs are used,
`registerPlugins` is never called thus elminating the performance impact
of config resolution.

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-09-07 13:18:30 -04:00
..
@tailwindcss-cli Improve the CLI output when nothing changed (#14351) 2024-09-05 17:00:57 -04:00
@tailwindcss-node v4.0.0-alpha.23 2024-09-05 10:43:07 -04:00
@tailwindcss-postcss v4.0.0-alpha.23 2024-09-05 10:43:07 -04:00
@tailwindcss-standalone v4.0.0-alpha.23 2024-09-05 10:43:07 -04:00
@tailwindcss-vite v4.0.0-alpha.23 2024-09-05 10:43:07 -04:00
internal-example-plugin Prefix internal modules with internal-* (#14074) 2024-07-29 10:58:07 -04:00
internal-postcss-fix-relative-paths Support loading config files via @config (#14239) 2024-09-02 18:03:16 +02:00
tailwindcss Make config resolution lazy (#14362) 2024-09-07 13:18:30 -04:00
tsconfig.base.json introduce v4 codebase 2024-03-05 14:29:15 +01:00