How do I get Tailwind and Vuetify to work together without causing style artifacts?
Asked Answered
C

3

20

I worked all day yesterday to finish a google cloud function to power an appointment maker vue component. The last step is actually UI using the returned object. I was planning on using the vuetify date/time pickers with allowed dates and times.

After spending much of today trying to add vuetify to an existing project to only use those to components, it is causing style errors with some classes(margin, etc) that are coming from main.sass.

I thought of adding a prefix to tailwind, but I don't have the time or inclination to go back to all of my components and files to add the prefix to all of my tailwind classes.

Is there something I can do to scope the vuetify classes/css so as not to cause problems outside of the two components I am trying to use?

Can I add the vuetify css after my tailwind is compiled and assembled so the tailwind classes win take precedent?

I don't have code to show as it is fairly straight forward. I thought the google calendar API would be the hardest part of this component, but it is proving to be the easier.

Counterwork answered 11/6, 2019 at 20:44 Comment(0)
U
17

Tailwind allows you to prefix the generated classes in the configuration file. See https://tailwindcss.com/docs/configuration

Urania answered 4/3, 2020 at 9:42 Comment(0)
Y
5

I know this is too late to answer but I'm writing this for other people like me who came up with this problem.

In order to add Vuetify to an existing project which is using Tailwind CSS without CSS class conflicting, You just need to activate treeShake in Vuetify options.

For example in a Nuxt project, add the below snippet in nuxt.config.js:

export default {

// Other Configs

vuetify: {
    treeShake: true
  },
}
Yacano answered 28/4, 2021 at 2:56 Comment(3)
can you explain what does 'treeShake' do?Sabaean
It removes unused CSS classes and styles so there will be no conflict between tailwind styles for classes like .flex and vuetify styles.Yacano
This is wrong. Event when using treeSahake: true, all basic styles will be importedMcbee
A
1

According to the Vuetify docs: "Install webpack-plugin-vuetify or vite-plugin-vuetify then enable it in your bundler configuration. Make sure the vuetify plugin comes after the vue plugin or it won’t work correctly."

Amazonas answered 9/2 at 16:40 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Holley

© 2022 - 2024 — McMap. All rights reserved.