-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow plugins to add their own config file to be resolved with the user's custom config #1162
Conversation
71d59b9
to
53dff62
Compare
This is now available to preview in |
|
Issue must be coming from #1072 like I mentioned on Discord. I guess this is the line causing the issue. That's one of the reasons I don't like |
Can you create a GitHub repo similar to your project that I can use to test performance and try and solve it? |
Can you show me some example code so I can make sure I'm understanding correctly? This should work for example: // tailwind.config.js
module.exports = {
plugins: [
{
config: {
theme: {
extend: {
screens: {
xxl: '1440px',
}
}
}
}
}
]
} |
Here's the plugin content: module.exports = {
config: {
theme: {
extend: {
screens: {
dark: {raw: '(prefers-color-scheme: dark)'},
light: {raw: '(prefers-color-scheme: light)'},
},
}
}
}
} In Bundling plugin looks like this: const postcss = require('postcss')
module.exports = function ({addComponents, addUtilities, addVariant, theme, variants, e}) {
require("tailwindcss-plugin-prefers-color-scheme");
require("tailwindcss-plugin-animated")({addUtilities, addComponents, e, theme, variants});
require("tailwindcss-plugin-transitions")({addUtilities, variants});
require("tailwindcss-plugin-content")({addComponents, addUtilities, addVariant, e});
require("tailwindcss-plugin-aspect")({addUtilities, variants});
require("tailwindcss-plugin-decoration")({addUtilities, variants, theme});
require("@tailwindcss/custom-forms")({addUtilities, addComponents, theme, postcss})
} The use of postcss as shown above will make canary hang, so I had to comment those lines out in testing. |
Not sure why you need to import Have you tried turning this into a Tailwind plugin and use |
Docs were written before that was added to the BOC™. |
Can we officially get it named bagOfCrap? 😀 |
OK, here's the magic formula… module.exports = {
...require("tailwindcss-plugin-prefers-color-scheme"),
handler(bagOfCrap) {
require("tailwindcss-plugin-animated")(bagOfCrap)
require("tailwindcss-plugin-transitions")(bagOfCrap)
require("tailwindcss-plugin-content")(bagOfCrap)
require("tailwindcss-plugin-aspect")(bagOfCrap)
require("tailwindcss-plugin-decoration")(bagOfCrap)
require("@tailwindcss/custom-forms")(bagOfCrap)
}
} If you're using the object versions in The above totally works, perf not bad. I'm satisfied with this. |
I have been testing this new feature in an existing app and everything is working fine but with a notable performance issue. tried to demo the issues in this repository, The performance issue can be seen when adding the The resume: tailwindcss v1.2.0-canary.0
tailwindcss v1.1.2
|
I can second those slower numbers. The slowdown from each successive plugin is definitely worse than before. |
Just tagged a new canary release that should fix this: Grab v1.2.0-canary.1 and test if you don't mind! Thanks. |
Awesome Looks fine to me, some stats: Dummy appUsing @latest
Using @1.2.0-canary.0
Using @1.2.0-canary.1
My appUsing @1.2.0-canary.0
Using @1.2.0-canary.1
Thank you so much Adam! |
Just wondering if 1.2 is ever coming out, or the updates here won't be seen until 2.0 in February. Also, if you try to use @canary without a full-on build pipeline (just npx-ing it, even when installed locally), it can't find the |
This PR makes it possible for third-party plugins to provide a config object in the same format as Tailwind's regular config object that will be intelligently merged with the user's config as part of the config resolution process.
This is useful when a plugin is adding new utilities and wants to provide default theme values for those utilities that the user can still override or extend the same way they would built-in utilities in Tailwind.
To understand why this is helpful, consider this hypothetical
@tailwindcss/rotate
plugin:It looks in the user's config for a
rotate
key, and if not present, provides four default rotate values.Now consider this Tailwind config file that uses this plugin:
You might think that because the user has specified the new
45
value in theextend
section, this would add therotate-45
utility in addition to the default utilities provided by the plugin, but it doesn't. Instead, therotate-45
utility is the only one generated, because thetheme()
function exposed to plugins only allows a plugin author to check for the presence of a key and provide a default if the key isn't there.This PR fixes this problem by allowing plugins to provide a configuration object that Tailwind should intelligently merge into the final config representation, before plugins are properly processed so that features like
extend
work as you might expect even with custom theme keys depended on by plugins.This is made possible by allowing plugins to now be represented as objects in addition to functions, where the object can have a
config
key, and ahandler
key, which is where you'd put the code you'd normally put directly in the plugin functionFor example, here's a plugin that adds
rotate
utilities:By using this new feature and writing this plugin this way, the user can extend or override the default rotate values just like they can with Tailwind's default config:
Override the defaults
Extend the defaults
This was implemented by making it possible for Tailwind to resolve multiple config objects under the hood, which is now also exposed to userland in the
resolveConfig
function.Config objects need to passed in to the
resolveConfig
function starting with the highest priority config, and ending with the lowest priority:In the
resolveConfig
function available by importingtailwindcss/resolveConfig
, the default config object is always added to the end of the list. Eventually you will be able to override this, likely using a newextends
property or similar directly in your config where you can specify which configs your config should extend.