Shopify / slate

Slate is a toolkit for developing Shopify themes. It's designed to assist your workflow and speed up the process of developing, testing, and deploying themes.
https://shopify.github.io/slate
MIT License
1.28k stars 365 forks source link

Adding PurgeCss to build process #1034

Open fowlercraig opened 5 years ago

fowlercraig commented 5 years ago

Is there any guidance on how to include a plugin like PurgeCss to the build process of Slate? I've tried a couple things, but am somewhat lost.

fcisio commented 5 years ago

You can find more info on the Slate Configuration page

Here's my working solution:

const PostcssCssnano = require("cssnano")()
const PostcssAutoprefixer = require("autoprefixer")({ browsers: 'last 2 versions' })
const PostcssPurgeCss = require('@fullhuman/postcss-purgecss')

module.exports = {
    'webpack.postcss.plugins': (config) => {
        const plugins = [
            AnyDevPlugin,
            AnyOtherDevPlugin
        ];
        if (process.env.NODE_ENV === 'production') {
            plugins.push(
                PostcssPurgeCss({
                    content: ['./src/**/*.liquid'],
                    whitelistPatterns: [/^(is-|has-|will-|js-)/],
                    keyframes: true,
                    fontFace: true
                }),
                PostcssAutoprefixer,
                PostcssCssnano
            )
        }
        return plugins;
    }
};

I hope it helps! 👍

fowlercraig commented 5 years ago

Perfect, thank you. I've been scouring the docs, but somehow missed this page!