Vue + Tailwind + PurgeCSS — The right way

tl;dr

Universal PurgeCSS caveats

Include all files that consume CSS in the content array

Never string-concatinate classnames

Universal Vue.js + TailwindCSS caveats

Class conflicts

External code that consumes classes

TailwindCSS caveats

Special characters in classnames

Vue.js caveats

Single-file components contain <style> blocks

Autogenerated classnames

Final configuration

require('@fullhuman/postcss-purgecss')({
content: [ './public/**/*.html', './src/**/*.vue' ],
defaultExtractor: (content) => {
const contentWithoutStyleBlocks = content.replace(/<style[^]+?<\/style>/gi, '')
return contentWithoutStyleBlocks.match(/[A-Za-z0-9-_/:]*[A-Za-z0-9-_/]+/g) || []
},
whitelistPatterns: [ /-(leave|enter|appear)(|-(to|from|active))$/, /^(?!cursor-move).+-move$/, /^router-link(|-exact)-active$/ ],
})

Unlisted

--

--

Language learning and coding.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
kyis

kyis

Language learning and coding.