-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breaking: Run purgecss and minify as a part of defaultPlugins()
Take a bundle: bool flag and purge + minify is true. Defaults to false.
- Loading branch information
Showing
4 changed files
with
184 additions
and
44 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,43 @@ | ||
const path = require('path'); | ||
const purgecss = require('@fullhuman/postcss-purgecss'); | ||
const csso = require('postcss-csso'); | ||
|
||
const LOOKBOOK_TAILWIND_CONF = path.resolve( | ||
path.join(__dirname, '..', 'tailwind.config.js') | ||
); | ||
|
||
// Looking through all React files for selectors | ||
// that are unused in the CSS, and removes the selectors from the final CSS | ||
const purgeCssOpts = { | ||
content: [ | ||
// Source tree, with the app view code | ||
'./src/**/*.{tsx,ts}', | ||
// Often imported components from our (built) lib in node_modules | ||
'./node_modules/@lookback/component/build/**/*.js', | ||
], | ||
safelist: [/flex-\d/, /flex-grow/, /flex-shrink/, /LoadingDots/], | ||
extractors: [ | ||
{ | ||
extractor(content) { | ||
// Matches Tailwind class names | ||
return content.match(/[A-Za-z0-9-_:/]+/g) || []; | ||
}, | ||
|
||
extensions: ['tsx', 'ts'], | ||
}, | ||
], | ||
}; | ||
|
||
exports.defaultPlugins = ({ | ||
pathToTailwindConf = LOOKBOOK_TAILWIND_CONF, | ||
/** If true, we'll minify and purge unused CSS classes. */ | ||
bundle = false, | ||
} = {}) => [ | ||
require('postcss-import'), | ||
require('tailwindcss')(pathToTailwindConf), | ||
require('postcss-nested'), | ||
require('postcss-color-function'), | ||
require('postcss-hexrgba'), | ||
require('autoprefixer'), | ||
...(bundle ? [purgecss(purgeCssOpts), csso] : []), | ||
]; |
Oops, something went wrong.