Skip to content

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

@denisx

Description

@denisx

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions