32
loading...
This website collects cookies to deliver better user experience
cd my-vue-project
npm install -D tailwindcss@npm:@tailwindcss/postcss7-compat @tailwindcss/postcss7-compat postcss@^7 autoprefixer@^9
package.json
file in your project you should see this added to your dependencies@tailwindcss/postcss7-compat": "^2.2.4"
npx tailwindcss init -p
tailwind.config.js
and postcss.config.js
. tailwind.config.js
contains paths to components and pages of our application and it is in this file we also add customizations//tailwind.config.js
module.exports = {
purge: [],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
}
purge
property :// tailwind.config.js
module.exports = {
purge: [
'./src/**/*.html',
'./src/**/*.vue',
'./src/**/*.jsx',
],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
}
purge
property just as the name denotes purges unused css styles which was generated by tailwind on installation, this does not in any way affect the styles by third party CSS used in your project. Check here to read up more about this.src
folder we are going to create a subfolder called styles
and inside the styles
folder we create a file tailwind.css
, note that this file can be named however you deem fit, I use tailwind.css
here as it is more descriptive and you should also give it a descriptive name. Type this in your terminal :mkdir src/styles && touch src/styles/tailwind.css
tailwind.css
add this :/* ./src/styles/tailwind.css */
@tailwind base;
@tailwind components;
@tailwind utilities;
@tailwind
to import tailwind's styles. Now we have to import tailwind.css
into the main.js
file.import { createApp } from 'vue';
import App from './App.vue';
import './styles/tailwind.css'; //Here
createApp(App).mount('#app');
App.vue
file add this :<template>
<div class="justify-center flex items-center bg-blue-500 h-screen">
<div class="text-4xl text-white">
This is Tailwind 🙂
</div>
</div>
</template>
<script>
export default {
name: 'App',
};
</script>