Skip to content

Commit a6cfb64

Browse files
committed
Add profile feature
1 parent 756e66f commit a6cfb64

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/lib/vite.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,27 @@ function run(cfg) {
2424
}
2525

2626
function main({
27+
profiles = {},
28+
// deprecated - to remove in next major
2729
runDefaultDirectives = new URLSearchParams('w=480;1024;1920&format=avif;webp;jpg'),
2830
defaultDirectives = new URLSearchParams(),
2931
exclude = '{build,dist,node_modules}/**/*',
3032
extendOutputFormats = (i) => i, //noop
3133
...rest
3234
} = {}) {
35+
const dict = {
36+
run: runDefaultDirectives,
37+
...profiles
38+
}
3339
return imagetools({
34-
defaultDirectives: (url) =>
35-
url.searchParams.get('as')?.split(':')[0] === 'run'
36-
? runDefaultDirectives
37-
: defaultDirectives,
38-
extendOutputFormats: (builtins) => ({ ...extendOutputFormats(builtins), run }),
40+
defaultDirectives: (url) => {
41+
const key = url.searchParams.get('as')?.split(':')[0]
42+
return Object.keys(dict).includes(key) ? dict[key] : defaultDirectives
43+
},
44+
extendOutputFormats: (builtins) => ({
45+
...extendOutputFormats(builtins),
46+
...Object.keys(dict).reduce((a, c) => ({ ...a, [c]: run }), {})
47+
}),
3948
exclude,
4049
...rest
4150
})

0 commit comments

Comments
 (0)