Code Monkey home page Code Monkey logo

Comments (6)

ky-is avatar ky-is commented on July 17, 2024 3

Vite uses https://github.com/michael-ciniawsky/postcss-load-config so you can install Tailwind and add it to your postcss config's plugin list. It's working for me in Vitepress without any further tweaks!

from vitepress.

ky-is avatar ky-is commented on July 17, 2024 2

@neilmispelaar Sure, there's a few gotchas right now between Vite not supporting PostCSS 8 yet or being able to optimize certain dependencies.

https://github.com/ky-is/vitepress-starter-tailwind

Note that the order of import statements for vitepress/dist/client/theme-default and tailwind.postcss matters if you want to preserve VuePress's styles. I haven't really used the default theme, there might be a simpler way to import CSS if you aren't customizing it otherwise.

from vitepress.

wheatjs avatar wheatjs commented on July 17, 2024 1

Currently it doesn't seem like this is possible, but if you are okay with using the tailwind CDN it should be possible.

If you edit your config file in .vitepress/config.js then you add the following to import tailwind

module.exports = {
    head: [
        ['link', { rel: 'stylesheet', href='https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css' }]
    ]
};

I'm not sure how useful this will be for you if you are attempting to create a custom theme though.

from vitepress.

Sharvadze avatar Sharvadze commented on July 17, 2024

Thanks @jacobclevenger it was helpful. The project is under a heavy development, so let's hope this feature will become available at some point

from vitepress.

neilmispelaar avatar neilmispelaar commented on July 17, 2024

@ky-is
Would it be possible to share a code sample of how to get this to work?

I’ve tried integrating some code from the vite starter projects with tailwindcss working and sadly was getting errors when running the npm run docs:dev command.

from vitepress.

neilmispelaar avatar neilmispelaar commented on July 17, 2024

@ky-is

Thank you so much! This was immensely helpful!

For anyone else that stumbles on this issue in the future a couple of things in regards to TailwindCSS and vitepress:

  1. Make sure to put TailwindCss in the package.json under devDependencies (not dependencies).

  2. When you configure TailwindCSS, in the tailwind.config.js file you have to specify the hidden vitepress folders under the purge content list. If you just leave it as ./docs/**/*.vue nothing will be purged.

module.exports = {
  purge: {
    enabled: process.env.NODE_ENV === 'production',
    content: [
      './docs/.vitepress/**/*.js',
      './docs/.vitepress/**/*.vue',
      './docs/.vitepress/**/*.ts',
    ],
    options: {
      safelist: ['html', 'body'],
    }
  }
}
  1. At time of writing, somewhere in the project dependencies postCSS version 7 is being referenced, but TailwindCSS uses PostCSS version 8. This is why in your package.json you have to reference a version of TailwindCSS that is compatible with PostCSS version 7. Fun Bonus: If you use this compatible version of TailwindCSS then you can not use AutoPrefixer past version 9.

from vitepress.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.