Last active
July 4, 2019 16:14
-
-
Save gmcz/5a0a76aeb9005435426f0f260f56721b to your computer and use it in GitHub Desktop.
Webpack config for Statamic, Tailwind CSS, and PurgeCSS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {mix} = require('laravel-mix'); | |
const tailwindcss = require('tailwindcss'); | |
const glob = require('glob-all'); | |
const PurgecssPlugin = require('purgecss-webpack-plugin'); | |
mix | |
.js('js/src/theme-name.js', 'js/theme-name.js') | |
.sass('sass/theme-name.scss', 'css') | |
.options({ | |
processCssUrls: false, | |
postCss: [tailwindcss('tailwind.js')], | |
}) | |
.browserSync({ | |
proxy: 'https://site-name.localhost', | |
files: [ | |
'templates/*.html', | |
'layouts/*.html', | |
'partials/*.html', | |
'js/src/theme-name.js', | |
], | |
}); | |
class TailwindExtractor { | |
static extract(content) { | |
return content.match(/[A-z0-9-:\/]+/g) || []; | |
} | |
} | |
if (mix.inProduction()) { | |
mix.webpackConfig({ | |
plugins: [ | |
new PurgecssPlugin({ | |
paths: glob.sync([ | |
path.join(__dirname, 'templates/*.html'), | |
path.join(__dirname, 'partials/*.html'), | |
path.join(__dirname, 'layouts/*.html'), | |
// path.join(__dirname, 'js/.js'), | |
]), | |
extractors: [ | |
{ | |
extractor: TailwindExtractor, | |
extensions: ['html', 'js', 'php', 'vue'], | |
}, | |
], | |
whitelist: [ | |
'h2', | |
'h3', | |
'p', | |
'blockquote', | |
'cta-primary', | |
'cta-secondary' | |
], | |
}), | |
], | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See Line 46 to 52 for an example of whitelisting classes that are dynamically inserted by Statamic. Or, in this case where I've directly styled some elements.