Skip to content

Commit

Permalink
fix: sizes as array should overwrites defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux committed Jan 19, 2021
1 parent caaff86 commit 339b7dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@ async function imageModule (moduleOptions: ModuleOptions) {
accept: [],
sharp: {}
},
sizes: [320, 420, 768, 1024, 1200, 1600],
internalUrl: '',
providers: {},
accept: [],
intersectOptions: {}
}

const options: ModuleOptions = defu(moduleOptions, nuxt.options.image, defaults)
// Sanitize sizes
if (!Array.isArray(options.sizes)) {
options.sizes = [320, 420, 768, 1024, 1200, 1600]
} else {
// Sort sizes from lowest to highest
options.sizes.sort((s1, s2) => s1 - s2)
}

options.provider = process.env.NUXT_IMAGE_PROVIDER || options.provider || 'static'

Expand Down
2 changes: 1 addition & 1 deletion src/types/module.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface ModuleOptions extends ImageProviders {
accept: string[]
sharp: { [key: string]: any }
}
sizes: number[],
sizes?: number[],
internalUrl?: string
accept: any
intersectOptions: object
Expand Down

0 comments on commit 339b7dd

Please sign in to comment.