JamesMGreene / nestdb

NestDB: An embedded persistent or in-memory database for Node.js, originally forked from NeDB
MIT License
58 stars 7 forks source link

Switch to ES6 module syntax with Rollup to utilize tree shaking #5

Open JamesMGreene opened 7 years ago

JamesMGreene commented 7 years ago

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 commented 7 years ago

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:

So its existence is currently DEFINITELY warranted! :confused:

FYI on NeDB (pre-fork) stats: