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

Plugins and named exports: can make less bundle size at client #27

Open
denisx opened this issue Dec 4, 2024 · 0 comments
Open

Plugins and named exports: can make less bundle size at client #27

denisx opened this issue Dec 4, 2024 · 0 comments

Comments

@denisx
Copy link

denisx commented Dec 4, 2024

About

Now package has almoust a 6kb size. We can add small changes and make named imports and plugin style.
It can reduce bundle size at client side for 2-3kb (Profit!)

Changes:

config func (at and):

  ...
  // Inject plugins to Decimal prototype
  Object.entries(plugins).forEach(([name, plugin]) => {
    this.prototype[name] = plugin
  })
  
  return this;
}

write all public func as named exports:

export default Decimal;

export {
  absoluteValue, absoluteValue as abs,
  dividedBy, dividedBy as div,
  ...
}

user code:

import Decimal, { abs, log, toNumber, ... }  from 'decimal.js-light/plugins';

Decimal.config({
  plugins: {
    abs, log, toNumber
  }
})

Standard (all) funcs: 5.8 kB
Plugin version: from 2.37 kB (main import with mini-funcs)

mini-funcs (one-lines or without external funcs) can be includes by default (wiill be base version from ~2.5 kB)

lets discuss

@denisx denisx changed the title Plugins Plugins and named exports: can make less bundle size at client Dec 4, 2024
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

No branches or pull requests

1 participant