svgo icon indicating copy to clipboard operation
svgo copied to clipboard

Add documentation & sample usage for `svgo.browser.js`

Open dr-js opened this issue 3 years ago • 3 comments

Reworded based on https://github.com/svg/svgo/issues/1050#issuecomment-1111706921

dr-js avatar Apr 28 '22 04:04 dr-js

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 avatar Sep 14 '22 13:09 Glandos

@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).

dr-js avatar Sep 15 '22 01:09 dr-js

That's what I did for now:

declare module 'svgo/dist/svgo.browser.js' {
    import svgo from 'svgo'
    export const optimize: typeof svgo.optimize
}

Glandos avatar Sep 15 '22 08:09 Glandos