FredKSchott / pika-pack-builders

🏗 A collection of official & community @pika/pack build plugins
MIT License
162 stars 31 forks source link

[plugin-bundle-node] Bundling of peer/optional dependencies? #37

Open avocadowastaken opened 5 years ago

avocadowastaken commented 5 years ago

While trying to bundle cli app with @pika/plugin-bundle-node I found few problems:

  1. It bundles all externals, even if they are in dependencies or peerDependencies, so these dependencies will be bundled and installed. Solution: Notify user if there are dependencies or peerDependencies in package.json and add them to externals.

  2. Same thing as 1., but with optional dependencies (not optionalDependencies), which not listed in package.json, but can be used with module. (e.g. pg, mysql packages that not listed in package.json of orm packages) Solution: Add option to pass externals. (Also can be as solution for 1.)

  3. I was using ink and react to build cli interface, and both of these libs requires to list namedExports in rollup-plugin-commonjs. Solution: Add option to pass namedExports for each module.

  4. As I said in 3., I was using react which has NODE_ENV checks inside, that's why bundle becomes really big. Solution 1: Always pass process.env.NODE_ENV=production with rollup-plugin-replace. Solution 2: Add option to pass env variables and replace them with rollup-plugin-replace.

  5. Does not work without @pika/plugin-build-node. Solution: Use dist-node/index.bundle.js only if dist-node/index.js wasn't created. Otherwise output to dist-node/index.js and do not skip bundle without --publish flag. (We also will need incremental builds for this, related to https://github.com/pikapkg/pack/issues/29)

From minor problems I found that there are no way to pass minNodeVersion and rollup-plugin-node-resolve warns about deprecated module option. I'll create PRs for them, but really want to discuss listed issues.


Update:


Update 2:

FredKSchott commented 5 years ago

Hey @umidbekkarimov, thanks for taking such a deep look into this, it's really appreciated.

I just went through your PRs, but don't have time now to respond to these remaining, larger issues in full now. Let me think through them a bit tomorrow and then respond then.

avocadowastaken commented 5 years ago

Hello @FredKSchott! No problems at all, it took me about a week to came up with this proposals. And I'm using local config, so no blockers from you.