When building an NPM package, how do you create a build that is able to support cherry picking individual exports to save on Webpack, Rollup or Browserify bundle size?
Preferred syntax would be:
import { myModuleOne, myModuleTwo } from 'my-npm-package';
Or
import myModuleOne from 'my-npm-package/myModuleOne';
import myModuleTwo from 'my-npm-package/myModuleTwo';
Just use ES6 exports:
And in
package.json
set themodule
property to the path of your bundle:Rollup and webpack 2 have tree-shaking, so the generated bundle will include only the modules you need.