svgo
svgo copied to clipboard
Add documentation & sample usage for `svgo.browser.js`
Reworded based on https://github.com/svg/svgo/issues/1050#issuecomment-1111706921
The section regarding webpack/rollup seems unclear to me.
In a project, I added svgo (yarn add svgo), but importing import { optimize } from 'svgo/dist/svgo.browser.js' in a TypeScript file result in a typing error (code works), even with @types/svgo. Sooo, it's not that easy :)
@Glandos I think to use the es module file with webpack or rollup would need one sample,
and to import this file from TypeScript with correct type would be another sample config,
both can be complex depending on how everyone's repo/IDE is configured.
For your use case in TypeScript the types from @types/svgo is for the main svgo code (usage like import .. from 'svgo').
'svgo/dist/svgo.browser.js' is plain bundled JavaScript and without corresponding .d.ts, so some type patch from the user side should be required (maybe borrow types from @types/svgo can work).
That's what I did for now:
declare module 'svgo/dist/svgo.browser.js' {
import svgo from 'svgo'
export const optimize: typeof svgo.optimize
}