Skip to content

Instantly share code, notes, and snippets.

@alexbowers
Created March 13, 2019 13:42
Show Gist options
  • Save alexbowers/0a2312363a145b747a5138f1e318775b to your computer and use it in GitHub Desktop.
Save alexbowers/0a2312363a145b747a5138f1e318775b to your computer and use it in GitHub Desktop.
Example Tailwind Vue SFC
<template>
<div>
<p class="bg-blue">Hello World 2</p>
</div>
</template>
<script>
export default {};
</script>
<template>
<div>
<p class="bg-red">Hello World</p>
<p class="custom-class">One</p>
<child-component>
</div>
</template>
<style tailwind lang="less" scoped>
@tailwind preflight;
@tailwind components;
@tailwind utilities;
.custom-class {
color: @apply .text-white;
h1 {
font-size: 24px;
}
}
</style>
<script>
import Child from 'Child';
export default {
components: {
'child-component': Child,
},
};
</script>
@adamwathan
Copy link

This will work but if you add those @tailwind directives in a bunch of components you are gonna end up with a 50gb CSS file, haha... You'll definitely want to use purgecss, but that might be risky on a legacy project. It will also be extremely slow if you have to purge 10 components that all duplicate the same styles.

As far as the PostCSS config, just something like this will be fine:

// postcss.config.js
module.exports = {
  plugins: [
    require('tailwindcss')(),
    require('autoprefixer')
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment