nestdb icon indicating copy to clipboard operation
nestdb copied to clipboard

Switch to ES6 module syntax with Rollup to utilize tree shaking

Open JamesMGreene opened this issue 8 years ago • 1 comments

ES6 module syntax offers some awesome benefits when it comes to building a streamlined browser version of your module by leveraging tools like Rollup that can perform advanced reduction of dependencies by a methodology called tree shaking.

This should greatly reduce the size of the current browser version as it should strip out a lot of unused dependency methods from the bundled version.

It is important to note that not all tree-shaking implementation are created equal. Currently, Webpack 2's implementation leaves more dead code intact (before uglification) than Rollup's does.

Rollup can also be utilized as a plugin for browserify with the rollupify plugin. Combine that with the babelify plugin to make ES5-compatible output modules. See Rollup's publishing tips for guidance on how to capitalize on both ES6 and ES5 formats.

JamesMGreene avatar Aug 10 '17 14:08 JamesMGreene

Once this is in place, we should also be able to eliminate the "browser-version/browser-specific/lib/customUtils.js" file since we can tree-shake out the use of the crypto module to just its randomBytes function.

Trying to do so now results in the following nasty file size increases:

  • nestdb current (with a few local changes):
    • Unminified: 303,233 bytes
    • Minified: 105,002 bytes
  • nestdb current (with a few local changes), minus the browser-specific "customUtils.js":
    • Unminified: 893,020 bytes (294.5% of the original size)
    • Minified: 417,158 bytes (397.3% of the original size)

So its existence is currently DEFINITELY warranted! :confused:

FYI on NeDB (pre-fork) stats:

JamesMGreene avatar Aug 11 '17 16:08 JamesMGreene