Created
July 30, 2021 11:45
-
-
Save sibelius/339b8e0294d832cefc964286d8ae96b2 to your computer and use it in GitHub Desktop.
webpack tailwind production config
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 webpackCommonConfig = require("./webpack.config"); | |
const { merge } = require('webpack-merge'); | |
const TerserPlugin = require('terser-webpack-plugin'); | |
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); | |
const { trimEnd } = require('lodash'); | |
module.exports = merge(webpackCommonConfig, { | |
mode: 'production', | |
devtool: 'source-map', | |
optimization: { | |
minimizer: [new TerserPlugin({ | |
parallel: 4, | |
})], | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.css$/, | |
use: [ | |
MiniCssExtractPlugin.loader, | |
{ | |
loader: 'css-loader', | |
options: { | |
importLoaders: 1 | |
} | |
}, | |
{ | |
loader: "postcss-loader", | |
options: { | |
postcssOptions: { | |
plugins: [ | |
require("tailwindcss")("./tailwind.config.js"), | |
require("@fullhuman/postcss-purgecss")({ | |
content: ["**/*.html", "**/*.tsx", "**/*.svelte"], | |
css: ["**/*.css"], | |
defaultExtractor: (content) => { | |
// Capture as liberally as possible, including things like `h-(screen-1.5)` | |
const broadMatches = | |
content.match(/[^<>"'`\s]*[^<>"'`\s:]/g) || []; | |
const broadMatchesWithoutTrailingSlash = broadMatches.map( | |
(match) => trimEnd(match, "\\") | |
); | |
// Capture classes within other delimiters like .block(class="w-1/2") in Pug | |
const innerMatches = | |
content.match( | |
/[^<>"'`\s.(){}[\]#=%]*[^<>"'`\s.(){}[\]#=%:]/g | |
) || []; | |
return broadMatches | |
.concat(broadMatchesWithoutTrailingSlash) | |
.concat(innerMatches); | |
}, | |
}), | |
require("autoprefixer"), | |
require("cssnano"), | |
], | |
}, | |
}, | |
}, | |
], | |
}, | |
], | |
}, | |
plugins: [ | |
new MiniCssExtractPlugin(), | |
], | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment