Skip to content

Commit

Permalink
Add and document purgeCssEnabled option (#20)
Browse files Browse the repository at this point in the history
* Add and document purgeCssEnabled option

* Enable PurgeCSS by default

* Simplify default purgeCssEnabled, update docs

* Update readme.md

Co-Authored-By: Luc <[email protected]>

* Update readme.md

Co-Authored-By: Luc <[email protected]>
  • Loading branch information
AlexVipond and lucleray committed Jun 25, 2019
1 parent efeea31 commit 38d876e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const glob = require('glob-all')
const PurgecssPlugin = require('purgecss-webpack-plugin')

module.exports = ({
purgeCssEnabled = () => true,
purgeCss = {},
purgeCssPaths = ['pages/**/*', 'components/**/*'],
webpack,
Expand All @@ -12,7 +13,12 @@ module.exports = ({
...nextConfig,

// overwrite webpack config
webpack: (webpackConfig, options) => {

This comment has been minimized.

Copy link
@msheakoski

msheakoski Jun 25, 2019

This change causes a "ReferenceError: options is not defined" error on line 36

webpack: (webpackConfig, { dev, isServer }) => {
// Don't add plugin unless PurgeCSS is enabled
if (!purgeCssEnabled({ dev, isServer })) {
return webpackConfig
}

webpackConfig.plugins.push(
new PurgecssPlugin({
paths: () =>
Expand Down
18 changes: 18 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@ module.exports = withCss(withPurgeCss())

## Options

### `purgeCssEnabled`

By default, `next-purgecss` will always remove unused CSS, regardless of build environment. You can change that by defining a function for the `purgeCssEnabled` option. The `purgeCssEnabled` function receives two arguments:

| Argument | Type | Description |
| --- | --- | --- |
| `dev` | `Boolean` | `true` in development mode (running `next`) or `false` in production mode (running `next start`) |
| `isServer` | `Boolean` | `true` during server side compilation or `false` during client side compilation |

```js
// next.config.js
module.exports = withCss(
withPurgeCss({
purgeCssEnabled: ({ dev, isServer }) => (!isDev && !isServer) // Only enable PurgeCSS for client-side production builds
})
)
```

### `purgeCssPaths`

By default, this plugin will scan `components` and `pages`
Expand Down

0 comments on commit 38d876e

Please sign in to comment.