Skip to content

Commit 61bd344

Browse files
authored
Add Tailwind's extractor for PurgeCSS
1 parent 2347526 commit 61bd344

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

build/webpack.prod.conf.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ const ManifestPlugin = require('webpack-manifest-plugin')
1515
const PurgecssPlugin = require('purgecss-webpack-plugin')
1616
const glob = require('glob-all')
1717

18+
// Custom PurgeCSS extractor for Tailwind that allows special characters in
19+
// class names.
20+
//
21+
// https://github.com/FullHuman/purgecss#extractor
22+
class TailwindExtractor {
23+
static extract(content) {
24+
return content.match(/[A-z0-9-:\/]+/g) || [];
25+
}
26+
}
27+
1828
const env = require('../config/prod.env')
1929

2030
const webpackConfig = merge(baseWebpackConfig, {
@@ -63,7 +73,16 @@ const webpackConfig = merge(baseWebpackConfig, {
6373
path.join(__dirname, './../templates/**/*.twig'),
6474
path.join(__dirname, './../**/*.vue'),
6575
path.join(__dirname, './../src/**/*.js')
66-
])
76+
]),
77+
extractors: [
78+
{
79+
extractor: TailwindExtractor,
80+
81+
// Specify the file extensions to include when scanning for
82+
// class names.
83+
extensions: ["html", "js", "twig", "vue"]
84+
}
85+
]
6786
}),
6887
// Compress extracted CSS. We are using this plugin so that possible
6988
// duplicated CSS from different components can be deduped.

0 commit comments

Comments
 (0)