Published 12/3/2019 · 2 min read
Adding Tailwind To a VueJS Project
Here is my set up for installing Tailwind CSS into a VueJs project.
Install your VueJS project using the CLI as normal.
Create a postcss.config.js file in the root of your project and add the following code:
const tailwindcss = require("tailwindcss");
const autoprefixer = require("autoprefixer");
module.exports = {
plugins: [
tailwindcss("./tailwind.config.js"),
autoprefixer({
add: true,
grid: true,
}),
],
};
Create a tailwind.config.js file in the root of your project and add the following code (optional you don’t have to add this):
module.exports = {
plugins: [
function ({ addUtilities }) {
const newUtilities = {
".trans": {
transition: "all .25s",
},
".trans-bg": {
transition: "property background",
},
".trans-slow": {
transition: "duration .5s",
},
".trans-slower": {
transition: "duration .5s",
},
".trans-fast": {
transition: "duration .15s",
},
".trans-faster": {
transition: "duration .075s",
},
};
addUtilities(newUtilities);
},
],
theme: {
fontFamily: {
sans: ["Open Sans", "sans-serif"],
},
},
};
Create a main.css file in the src directory of your project, I usually add it to /src/assets/css/main.css then add the following:
@tailwind base;
@tailwind components;
@tailwind utilities;
In your main.js file add the following at the top of the file: import "@/assets/css/main.css";
Run the serve command from the Vue CLI and test that you have tailwind injected into your page.
Related Articles
- Form Handling: Moving from Vue to Svelte
A practical guide to translating Vue form patterns to Svelte, covering two-way binding, validation, async submission, and what actually works better in each framework.
- Building a Modal: Vue vs Svelte
A side-by-side comparison of building a modal component in Vue 3 and Svelte 5, exploring the differences in reactivity, props, and component patterns.
- Using Getters & Setters Vuex
A short article on using the getter and setter pattern to update data held in a Vuex store.