Skip to content

Instantly share code, notes, and snippets.

@gmcz
Last active July 4, 2019 16:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gmcz/5a0a76aeb9005435426f0f260f56721b to your computer and use it in GitHub Desktop.
Save gmcz/5a0a76aeb9005435426f0f260f56721b to your computer and use it in GitHub Desktop.
Webpack config for Statamic, Tailwind CSS, and PurgeCSS
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'
],
}),
],
});
}
@gmcz
Copy link
Author

gmcz commented May 1, 2018

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.

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