-
-
Save philipboomy/4b684507ff349da5dd316821711e95c8 to your computer and use it in GitHub Desktop.
Webpack config for Statamic, Tailwind CSS, and PurgeCSS
This file contains 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