Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation & sample usage for svgo.browser.js #1671

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dr-js
Copy link

@dr-js dr-js commented Apr 28, 2022

Reworded based on #1050 (comment)

@Glandos
Copy link

Glandos commented Sep 14, 2022

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 :)

@dr-js
Copy link
Author

dr-js commented Sep 15, 2022

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

@Glandos
Copy link

Glandos commented Sep 15, 2022

That's what I did for now:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants