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

feat!: rewrite lib to support esm #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

feat!: rewrite lib to support esm #32

wants to merge 2 commits into from

Conversation

onmax
Copy link
Member

@onmax onmax commented Oct 30, 2024

Why not just use the legacy version?

We had problems running the lib in worker. That was it. But then, as I started to look at it, I discovered that we are there is room for improvement.

Bundling

While gulp is great and allows you to build the library, vite is the standard these days. With the old implementation, the library loaded all the features of svg into a single DOM element (using dom-parser) and from there, depending on the hash, it selected the features for the fiven hash. Then it ensabmages all the selected elements together with a predefined background and colors and runs an optimization process on each render.

With the new approach, we run svgo with some defined plugins in dev and write the optimized svg to the folder. Then at runtime we just ensamble the selected optimized features and return the SVG. After the selected features have been retrieved, we just ensamlbe the SVG and return it. We don't use dom-parser and we don't need to optimize the SVG at runtime.

Docs

I am planning to make a small README with a basic usage of the library, but I also prepared a page for the developer center:

Playground

I have created a Vue 3 application that can be used for local testing, but also as a playground. We need to enable deployment to GitHub pages from GitHub actions and the link should work.

Performance Comparison

Metric Legacy Implementation Current Implementation
First Time Load ~20ms ~10ms
Already Loaded ~6ms ~1ms
Average Size Reduction - 25% smaller

Breaking changes

See Migration Guide here

Discontinued functions

Please check the functions that have NOT been migrated: https://deploy-preview-78--developer-center.netlify.app/build/ui/identicons#discontiuned-functions

TODO

  • Update README in this branch.
  • Rename master branch to v1
  • Add deprecation notice in the v1 branch warning users. Also add a notice banner in the readme of main branch linking to v1
  • Publish the package
  • Remove this PR
  • Update the code from the @onmax/nimiq-identicons
  • Check features are ok

solves #2, #12, #17

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.

1 participant