Webpack: How to persist exports that aren’t used inside the bundle itself in bundled JS file?
I want to use webpack to bundle a NodeJS application that exports functions to be used by other projects. However, when i export functions in src/index.js
that are not used anywhere else inside the bundle, they are omitted from the actual bundle in dist/index.bundle.js
.
From webpack’s documentation I learned that this behaviour is expected, following the Tree Shaking principle to omit “dead code”.
I understand that webpack main purpose is to bundle browser scripts that benefit greatly from reducing the size of the bundle. I’d still appreciate to be able to use webpack for bundling my node applications, because of it’s great ecosystem of plugins and documentation.