vite-plugin-image-optimizer
vite-plugin-image-optimizer copied to clipboard
Added new config option convertAllTo …
for converting all image files to another format - can close issue #20
What is the purpose of this pull request?
- [ ] Bug fix
- [X] New Feature
- [ ] Documentation
- [ ] Other
Description
Added new config option convertAllTo for converting all image files to another format - can close issue #20
Checks
- [x] PR adheres to the code style of this project
- [x] Related issues linked using
fixes #number
- [x] Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
- [x] Lint and build have passed locally by running
pnpm lint && pnpm build
- [x] Code changes have been verified in local
- [x] Documentation added/updated if necessary
Additional Context
Hey @netolicak, thanks for the PR! Sorry I couldn't get back earlier. Could you please check the above lint issues? Also, I tried running your changes on my local, and they seem to be failing at:
bundler[filePath + "." + format].source = content;
^
TypeError: Cannot set properties of undefined (setting 'source')
Since we are generating a new file and not altering an existing one, we should write a new file using fs at the same path as the existing file, I believe.
Also, here are a few suggestions for your PR:
-
It can accept an array or a single string (i.e., convertAllTo: 'webp' or convertAllTo: ['webp', 'png']).
-
If the extension of the file being converted is the same as the one present in convertAllTo, then there is no point in converting the file. We have to handle this scenario.
-
Add TypeScript type completions for convertAllTo so that users are aware of which types to convert to in their IDE.
-
If users pass an unknown file type that does not exist in options[extName], then we should probably throw an error.
-
Add an output log indicating that file conversion to the formats specified in convertAllTo has been completed successfully in the logStats method.
This is an important feature. Is there something else in the vite plugin ecosystem that can make up for this feature in the meantime? @FatehAK
A quick search gave me this @Lastofthefirst https://www.npmjs.com/package/vite-imagetools
hi @FatehAK , is this request is going to be merged? thanks.