-
-
Save mikeerickson/b72a681a6f335a70645145188f5d987c to your computer and use it in GitHub Desktop.
Webpack: Tailwind CSS + PurgeCSS Example
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 ExtractTextPlugin = require("extract-text-webpack-plugin"); | |
const path = require("path"); | |
const glob = require("glob-all"); | |
const PurgecssPlugin = require("purgecss-webpack-plugin"); | |
/** | |
* Custom PurgeCSS Extractor | |
* https://github.com/FullHuman/purgecss | |
* https://github.com/FullHuman/purgecss-webpack-plugin | |
*/ | |
class TailwindExtractor { | |
static extract(content) { | |
return content.match(/[A-z0-9-:\/]+/g); | |
} | |
} | |
module.exports = { | |
entry: "./index.js", | |
output: { | |
path: path.resolve(__dirname, "dist"), | |
filename: "styles.css" | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.css$/, | |
use: ExtractTextPlugin.extract({ | |
fallback: "style-loader", | |
use: [{ loader: "css-loader", options: { importLoaders: 1 } }, "postcss-loader"] | |
}) | |
} | |
] | |
}, | |
plugins: [ | |
new ExtractTextPlugin("styles.css"), | |
new PurgecssPlugin({ | |
paths: glob.sync([ | |
path.join(__dirname, "resources/views/**/*.blade.php"), | |
path.join(__dirname, "resources/assets/js/**/*.vue") | |
]), | |
extractors: [ | |
{ | |
extractor: TailwindExtractor, | |
extensions: ["html", "js", "php", "vue"] | |
} | |
] | |
}) | |
] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment