Switch to ES6 module syntax with Rollup to utilize tree shaking
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.
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:
-
nestdbcurrent (with a few local changes):- Unminified: 303,233 bytes
- Minified: 105,002 bytes
-
nestdbcurrent (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:
-
[email protected]:- Unminified: 299,421 bytes
- Minified: 100,859 bytes