Skip to content

Commit

Permalink
Add profile feature
Browse files Browse the repository at this point in the history
  • Loading branch information
zerodevx committed Sep 23, 2023
1 parent 756e66f commit a6cfb64
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/lib/vite.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,27 @@ function run(cfg) {
}

function main({
profiles = {},
// deprecated - to remove in next major
runDefaultDirectives = new URLSearchParams('w=480;1024;1920&format=avif;webp;jpg'),
defaultDirectives = new URLSearchParams(),
exclude = '{build,dist,node_modules}/**/*',
extendOutputFormats = (i) => i, //noop
...rest
} = {}) {
const dict = {
run: runDefaultDirectives,
...profiles
}
return imagetools({
defaultDirectives: (url) =>
url.searchParams.get('as')?.split(':')[0] === 'run'
? runDefaultDirectives
: defaultDirectives,
extendOutputFormats: (builtins) => ({ ...extendOutputFormats(builtins), run }),
defaultDirectives: (url) => {
const key = url.searchParams.get('as')?.split(':')[0]
return Object.keys(dict).includes(key) ? dict[key] : defaultDirectives
},
extendOutputFormats: (builtins) => ({
...extendOutputFormats(builtins),
...Object.keys(dict).reduce((a, c) => ({ ...a, [c]: run }), {})
}),
exclude,
...rest
})
Expand Down

0 comments on commit a6cfb64

Please sign in to comment.