Skip to content

Commit 7bf5bb2

Browse files
authored
Update webpack.mix.js
1 parent 9b4a2f9 commit 7bf5bb2

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/tailwindcss-stubs/webpack.mix.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
let mix = require('laravel-mix');
22
var tailwindcss = require('tailwindcss');
3+
let glob = require("glob-all");
4+
let PurgecssPlugin = require("purgecss-webpack-plugin");
5+
6+
class TailwindExtractor {
7+
static extract(content) {
8+
return content.match(/[A-z0-9-:\/]+/g) || [];
9+
}
10+
}
311

412
/*
513
|--------------------------------------------------------------------------
@@ -31,3 +39,31 @@ mix.js('resources/assets/js/app.js', 'public/js')
3139
// processCssUrls: false,
3240
// postCss: [ tailwindcss('tailwind.js') ],
3341
// });
42+
43+
// Only run PurgeCSS during production builds for faster development builds
44+
// and so you still have the full set of utilities available during
45+
// development.
46+
if (mix.inProduction()) {
47+
mix.webpackConfig({
48+
plugins: [
49+
new PurgecssPlugin({
50+
51+
// Specify the locations of any files you want to scan for class names.
52+
paths: glob.sync([
53+
path.join(__dirname, "resources/views/**/*.blade.php"),
54+
path.join(__dirname, "resources/assets/js/**/*.vue")
55+
]),
56+
extractors: [
57+
{
58+
extractor: TailwindExtractor,
59+
60+
// Specify the file extensions to include when scanning for
61+
// class names.
62+
extensions: ["html", "js", "php", "vue"]
63+
}
64+
]
65+
})
66+
]
67+
});
68+
}
69+

0 commit comments

Comments
 (0)