Add new plugin and plugin.withOptions functions for creating plugins
#1268
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.
This PR adds support for a new way of creating plugins using a new
pluginfunction exposed attailwindcss/plugin.It allows you to create plugins like this:
The first argument to
pluginis the traditional Tailwind plugin function. The second argument is your plugin's config object that should be merged with the user's config.This API replaces the unstable API introduced in #1162 that allowed you to write your plugins as an object with a
configandhandlerproperty:This PR also introduces a
plugin.withOptionfunction that allows you to author plugins that accept top-level non-config options:These sorts of plugins are used by end-users like this:
This is implemented in such a way that if your plugin takes top-level options but those options are optional, the end-user doesn't need to invoke your plugin with no arguments when adding it to their Tailwind config:
It's worth noting that under the hood we are still using the
{ config: ..., handler: .... }format (that's what this helper function spits out) so functions authored that way will continue to work, although you're encouraged to migrate to this new API.