Skip to content

Commit

Permalink
fix: allow user to override critters options (#15)
Browse files Browse the repository at this point in the history
* feat: support passing in critters options
* fix: use `defaults`
  • Loading branch information
danielroe committed Jul 3, 2021
1 parent 36e1bcd commit 99e57fd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
16 changes: 16 additions & 0 deletions README.md
Expand Up @@ -40,6 +40,22 @@ Nuxt has a number of ways to optimize your CSS in production:
2. 📦 You can enable [`purgecss`](https://github.com/Developmint/nuxt-purgecss) to remove unused CSS rules from your bundle.
3. ✅ with `@nuxtjs/critters` you can now extract CSS files and load them separately, just inlining the CSS necessary to render the page.

## Options

You can override the `@nuxtjs/critters` defaults like this:
```js
// nuxt.config.js
export default {
critters: {
// Options passed directly to critters: https://github.com/GoogleChromeLabs/critters#critters-2
config: {
// Default: 'media'
preload: 'swap'
}
}
}
```

## Development

1. Clone this repository
Expand Down
10 changes: 7 additions & 3 deletions src/index.ts
Expand Up @@ -4,8 +4,12 @@ import Critters from 'critters'

export default defineNuxtModule({
name: 'critters',
options: {
preload: 'media'
configKey: 'critters',
defaults: {
// Options passed directly to `critters`
config: {
preload: 'media' as 'media' | 'body' | 'swap' | 'js' | 'js-lazy'
}
},
setup (options, nuxt) {
// Only enable for production
Expand All @@ -16,7 +20,7 @@ export default defineNuxtModule({
const critters = new Critters({
path: resolve(nuxt.options.buildDir, 'dist/client'),
publicPath: nuxt.options.build.publicPath,
preload: options.preload,
...options.config,
})

// Enable css extraction
Expand Down

0 comments on commit 99e57fd

Please sign in to comment.