-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
New Tailwind theme #2961
Comments
Hi, I'm not very familar with Tailwind yet. Currently Infima is a css lib with a few postcss. But it also includes some lightweight vanilla JS components If I understand correctly, you mean we could implement current Infima CSS classes as a Tailwind preset, instead of the existing css/postcss ? So we would publish that preset and enable users to extend / customize it more easily? I see the value of Tailwind, and a similar goal of styling co-located to the markup. Its scope is larger than current Infima:
|
Yes you can and should always purge unused tailwind css. Only the classes actually used in the codebase are kept. |
Hoping this is helpful information, as I got TailwindCSS v2 to properly work with the PostCSS config that Docusaurus v2 already uses. I'm using a custom module.exports = function (context, options) {
return {
name: 'postcss-tailwindcss-loader',
configureWebpack(config, isServer, utils) {
return {
module: {
rules: [
{
test: /\.css$/,
use: [
{
loader: require.resolve('postcss-loader'),
options: {
ident: 'postcss',
plugins: () => [
require('postcss-import'),
require('tailwindcss'),
require('postcss-preset-env')({
autoprefixer: {
flexbox: 'no-2009',
},
stage: 4,
}),
],
},
},
],
},
],
},
}
},
}
} with And a module.exports = {
purge: ['./src/**/*.html', './src/**/*.js', './src/**/*.tsx'],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
} A reference commit summarizing the above info: Discord4J/documentation@2019279 Note that the PostCSS version in which Docusaurus v2 currently uses is 7.0.XX, while the latest version of PostCSS is 8.0.X and TailwindCSS v2 by default uses PostCSS V8. I had to use a v7 compatibility install of TailwindCSS v2 for this to all work: I'm thinking that maybe tailwindcss can be added directly to the https://github.com/facebook/docusaurus/blob/master/packages/docusaurus/src/webpack/utils.ts#L64-L71 plugin block for EDIT: With the newer versions of Docusaurus v2 supporting a configurePostCss option in a plugin, the above code snippet should be changed to the following: module.exports = function (context, options) {
return {
name: 'postcss-tailwindcss-loader',
configurePostCss(postcssOptions) {
postcssOptions.plugins.push(
require('postcss-import'),
require('tailwindcss'),
require('postcss-preset-env')({
autoprefixer: {
flexbox: 'no-2009',
},
stage: 4,
}),
)
return postcssOptions
},
}
} |
Thanks for these infos. We'll look at this more in depth soon, as we'll work on our theme gallery (#3522) and Tailwind support is part of it |
@kvnxiao I tried your config for tailwind and can't seem to get past this error (looks like it's still looking for postcss 8):
Do you have a working repo I could take a look at? |
@clairefro https://github.com/Discord4J/documentation You will need to install postcss-import |
@kvnxiao's solution is great! I just want to add an improvement to it. If you add the following to your |
@kvnxiao also the install guide on tailwindcss does not mention the postcss-import module why did you made it a dependency on your module? |
@wibed This is if you want to have build time imports: https://tailwindcss.com/docs/using-with-preprocessors#build-time-imports It's not a requirement but I enabled it in case I take advantage of it. It's also build time processing so it doesn't affect the output size regardless of whether it's included or not. You may remove the |
FYI the next release will have a |
@nahtnam The one with |
Any idea on a timeline for first-class support? |
@Romstar no timeline to be defined, as it requires a significant amount of refactoring work to avoid duplicating everything between the themes. It's not a short term priority but more mid-term. |
@slorber if someone wanted a tailwind theme now-ish, would you suggest waiting a bit more, or plowing ahead and making their own (knowing the work will be obsoleted eventually). Is it still a mid term goal? It seems like abstracting common logic from themes, is a fairly significant undertaking and likely requires some rethinking of how themes work? |
@jquense I think you'd better implement that theme yourself for now, and we may be able to benefit from this third-party implementation once Docusaurus has refactored its theme system. The goal is to share the same UX across all the official themes, and just have to implement the UI / head / styled components for each theme. We should also try to make it so that theme refactors are less likely to break sites of users that have implemented a custom theme or swizzled a component. I don't like too much the way swizzling works currently, as it creates a quite implicit API surface for which it's hard to be retrocompatible, so yeah it requires a decent amount of work to prepare all that. The goal is not just to have a Tailwind theme: it's also to make sure that it's easy to maintain, does not break and stays in sync with the classic theme over time. We have seen what happens to the "bootstrap" theme over time. As there's currently a lot of code duplication, it became unmaintained and a burden and is now in a very bad state. If we have a Tailwind theme, we don't want that to happen. |
Actually, can you try this: // tailwind.config.js The prefix solved the collision issue for me. |
Use this comment to add a custom docusaurus plugin facebook/docusaurus#2961 (comment)
@slorber Kind regards |
We are continuously extracting technical / non-ui code from the classic theme so that producing a new Tailwind does not lead to a ton of duplication. Unfortunately, it's hard to estimate. We'll first cleanup the theme to make it easier to customize, release 2.0 asap, and only then start working on this new official Tailwind theme. And as part of an open-source project, there is also general maintenance work, community PRs and other quality of life improvements to ship so it's hard to dedicate 100% of the efforts to this single project. But it is definitively something that we try to slowly make happen in the background |
I strongly advise making Tailwind optional. |
I don't know if anyone has the same problem, but for me the tailwind installation had lead to the whole site being ugly. After a lot of searching I found that simply disabling preflight solves it because it doesn't change the html defaults. You can add this in your
|
How did you import tailwind? |
Is there an umbrella task or list somewhere for the work to extract logic out of the classic theme and into theme-common to help out on making more themes possible? |
No umbrella issue but you could look at theme components and see if there is some code that is technical and not really related to theming/styles/CSS. Sometimes it's hard to extract, but there are still a few low-hanging fruits that contributors can help moving ;) |
Hey @slorber , We love Docusaurus, and we're building our documentation website on top of it. We're also looking at using Tailwind, so I'm just wondering if you could shed some light on when the Tailwind theme will be available. I understand that you don't have an ETA, but it would be helpful to know whether it'll take weeks, months, or maybe even more. We're not sure if we'd be better off implementing the key features now and wait for the new theme to be ready before we polish the website or if we should just hack our way through the existing codebase and get all the features implemented on top of the existing classic theme. The main concern is that we have to swizzle a large number of components, and this could cause issues when upgrading our version of Docusaurus. Thank you, |
Hey, I'm sorry but I have limited bandwidth, only work on Docusaurus 3d/week, also take holidays, have to spend like 50% of my time doing support and answering issues (like this one). In conclusion, I have not much more than 1d/week to work on ambitious features for Docusaurus, and it's hard for me to tell you how much time it will take considering there are more urgent things to handle such as migrating to React 18, MDX 2.0, ESM, fixing important bugs, DX issues and pending PRs to reviews. So no, I really can't answer you on when a Tailwind theme will land, nor what decision you should make. Please assume it will take time, and that you should rather take a decision based on the current state of Docusaurus instead of waiting for official support. If you really want Docusaurus with Tailwind support today, it remains possible to implement in userland, as @jquense did in his POC above. And doing so will help us: once the time comes, we'll be able to copy your existing JSX+className markup to create the official version. For sure it requires a lot of effort to create it and keep it on par with the existing classic theme, but it is definitively possible. Note that you can still contribute to our opencollective if you want to give us more bandwidth to implement things faster. |
Hi, We appreciate you taking the time to answer our question. We just wanted to get more insight into this. Thanks for sharing all the useful information! Best, |
In my team, we prefer to keep the preflight styles but, in order to avoid collisions with Docusaurus styles, we need to load Unfortunately, if we add So, is there any other file we could use to load @slorber I think one solution would be to make Docusaurus a headless documentation lib. In that way, everyone could choose their preferred CSS architecture to style the UI. Or keep infima for the default CSS architecture but allow users to completely remove it easily. |
That's already the direction we take by moving most client code not related to styling to a
It is already possible to implement your own theme, not using Infima. The problem is that you'll have to reimplement many things. The goal of I can't help much on the Tailwind side, I don't have much experience using it so far. |
Is it possible to apply styling to only one page? I'm working on this use-case in this PR |
@gazpachu I found a workaround for loading the preflight before the Docusaurus styles. I disabled preflight in the tailwind.config.js and then Injected the preflight CSS with the async function pluginTailwindCSS(context, options) {
return {
name: "docusaurus-tailwindcss",
injectHtmlTags() {
return {
headTags: [
{
tagName: "link",
attributes: {
rel: "stylesheet",
href: "https://cdn.jsdelivr.net/npm/tailwindcss/dist/preflight.min.css",
},
},
],
};
},
configurePostCss(postcssOptions) {
// Appends TailwindCSS and AutoPrefixer.
postcssOptions.plugins.push(require("tailwindcss"));
postcssOptions.plugins.push(require("autoprefixer"));
return postcssOptions;
},
};
}, |
Have this one been resolved? |
This hasn't been resolved and is not currently being worked on. I'm currently working on making Docusaurus much faster, notably by adopting Rust tools like Rspack, SWC, and LightningCSS. For that, we need to get rid of PostCSS, which is currently needed for Tailwind. In v4 with Oxide Tailwind will also adopt LightningCSS (details). We'll look into adding first-class Tailwind support, and a Tailwind theme, once we both successfully adopt LightningCSS. |
@kvnxiao's (revised/edited) recipe in #2961 (comment) works quite well (better to snoop around in the Discord4J project they linked IMO to see how everything is laid out), with the addition that
This is standard fare for a tailwind project ofc, but I neglected to do this at first (I guess I thought postcss would somehow roll things up without those rules), and so thought the tailwind+docusaurus integration wasn't working for a while. |
I have setup Tailwind recently on Docusaurus 3.5, here is the commit: betalectic/betalectic.github.io@55a5c53 Thanks to various contributors above.
Change on 16th Oct, need to add following before for before/after of tailwindcss to work In plugin use the latest tailwind preflight file: injectHtmlTags() {
return {
headTags: [
{
tagName: "link",
attributes: {
rel: "stylesheet",
href: "https://unpkg.com/[email protected]/src/css/preflight.css",
},
},
],
};
}, |
💥 Proposal
This may be belong in the Infima repo, but I strongly suggest Docusaurus consider Tailwind. Tailwind already solves for theming out of the box. It also gives developers much more freedom. You can still re-implement Infima's core classes with tailwind, so this actually wouldn't need to be a breaking change.
The benefits:
Next Steps
Have you read the Contributing Guidelines on issues?
Yes
The text was updated successfully, but these errors were encountered: