Support loading plugins by package / file name #12087
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Today we require that plugins be required in the config (or imported in some cases) to be used. Additionally, when passing options to a plugin you have to call that plugin as a function to pass in the options.
Today, you have to write this:
This PR allows us to simplify this a bit such that, if you have no options to pass, you can specify just the name of the package or file and Tailwind CSS will
require()
it for you. And, if you need to pass options, you can use a tuple with the name of the package and the options you want to pass.Turning the above config into this:
Now, the old plugin format is still supported — and you can freely mix and match!
A note about TypeScript and ES Modules support
Due to implementation details this way of loading plugins does not support plugins written in TypeScript or ESM. ESM is not supported because many of the things that would need to be async are not and doing so would be a breaking change for people relying on APIs like
resolveConfig
. Similarly, for TS support — we use Jiti to compile our config to TypeScript and would not want to packagejiti
in every bundle that happens to useresolveConfig
.In these cases we recommend you stick to using the typical
import
syntax you are using today!