Created
November 30, 2018 17:36
-
-
Save ryanscherler/f16b98cf645f1e4daab7ba3131b98c8e to your computer and use it in GitHub Desktop.
Add PurgeCSS in production for Gatsby
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
// Add PurgeCSS in production | |
// See: https://github.com/gatsbyjs/gatsby/issues/5778#issuecomment-402481270 | |
const PurgeCssPlugin = require(`purgecss-webpack-plugin`) | |
const path = require(`path`) | |
const glob = require(`glob`) | |
const PATHS = { | |
src: path.join(__dirname, `src`) | |
} | |
// Nonessential options removed for brevity | |
const purgeCssConfig = { | |
paths: glob.sync(`${PATHS.src}/**/*.js`, { nodir: true }), | |
} | |
exports.onCreateWebpackConfig = ({ actions, stage }) => { | |
if (stage.includes(`develop`)) return | |
// Add PurgeCSS in production | |
if (stage.includes(`build`)) { | |
actions.setWebpackConfig({ | |
plugins: [new PurgeCssPlugin(purgeCssConfig)] | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment