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

Inline SVGs as data URIs instead encoding it with base64 #1941

Closed
strarsis opened this issue Dec 22, 2022 · 4 comments
Closed

Inline SVGs as data URIs instead encoding it with base64 #1941

strarsis opened this issue Dec 22, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@strarsis
Copy link

strarsis commented Dec 22, 2022

With the 6.6.6 release of bud assets, including SVGs can be now inlined by using the ìnline parameter.

Inlining SVGs as base64 strings is functionally fine, however SVGs can be inlined as data URIs with a much smaller overhead than using plain base64 or URL encoding.

The webpack documentation uses some generator config for using the mini-svg-data-uri for SVG files.

bud SVG inline rule:
https://github.com/roots/bud/blob/v6.6.6/sources/@roots/bud-build/src/handlers/rules/svg.inline.ts#L8

@retlehs retlehs added the enhancement New feature or request label Dec 22, 2022
@kellymears
Copy link
Member

kellymears commented Dec 24, 2022

yeah, i want to add this. but general ?inline support seemed like a great place to start and has zero overhead.

likely a separate rules for ?data-uri (that was my latest thinking on it, at least)

for reference: this is the rule for inline svg if anybody else wants to take a crack at adding mini-svg-data-uri support in sources/@roots/bud-build/src/handlers/rules/svg.data-uri.ts:

https://github.com/roots/bud/blob/main/sources/%40roots/bud-build/src/handlers/rules/svg.inline.ts

@kellymears
Copy link
Member

I changed my mind about .svg?data-uri and ended up just modifying the .svg?inline rule to use the svg-mini-data-uri transformer.

kodiakhq bot pushed a commit that referenced this issue Dec 26, 2022
- adds support for `svg-mini-data-uri`
- adds unit test
- update docs

example use:

```ts
body {
  background: url(@src/svg/demo.svg?inline);
}
```

refers:

- #1941 

## Type of change

**PATCH: backwards compatible change**



This PR includes breaking changes to the following core packages:

- none

This PR includes breaking changes to the follow extensions:

- none

## Dependencies

### Adds

- mini-svg-data-uri

### Removes

- none
@kellymears
Copy link
Member

OK this is merged in #1948

@strarsis
Copy link
Author

@kellymears: Awesome, thank you!

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

No branches or pull requests

3 participants