decimal.js-light icon indicating copy to clipboard operation
decimal.js-light copied to clipboard

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

Open denisx opened this issue 1 year ago • 0 comments

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 avatar Dec 04 '24 20:12 denisx