fbjs icon indicating copy to clipboard operation
fbjs copied to clipboard

[fbjs-scripts] Babel dependency quite large for packages not using jest preprocessor

Open zpao opened this issue 8 years ago • 3 comments

The jest preprocessor we ship requires Babel, which means we put it into dependencies, however it also means that anybody (eg React Native) that installs fbjs-scripts for just a single script that isn't the preprocessor is paying a 20MB penalty. This is true for the other pieces too (eg the gulp scripts require gulp-util) but it's most felt in the jest stuff.

A couple things:

  1. We should be using babel-core instead of babel, which would save a few MB
  2. We're going to drop Babel 5 soon and switch over to Babel 6. That might be smaller as well

A couple ideas

  1. We could maybe make babel a peerDep. The problem with this is you get a warning about missing peerdeps (npm 3) or they just get installed and no wins (npm 2).
  2. We remove it from deps entirely and just try/catch the require so it's only an issue if it's used and then we can error out with a helpful message.
  3. We remove it from deps and instead make a transform injectible. That pretty much entirely defeats the purpose of having the preprocessor though so I'm not really a fan of this.
  4. We remove the preprocessor and make it just a sample file - projects that are using it must copy it into their project manually (or maybe with a simple "bootstrap" script)

zpao avatar Jan 18 '16 18:01 zpao

This is where React Native uses fbjs-scripts: https://github.com/facebook/react-native/search?utf8=%E2%9C%93&q=fbjs-scripts

@martinbigio, @davidaurelio is there a way we can drop the dependency on fbjs-scripts?

mkonicek avatar Jan 18 '16 19:01 mkonicek

You could copy those 2 things (for jest prepackager and packager transformer) in to RN but that defeats the purpose of a shared library like this that benefits multiple people. And you'd stop getting updates if they came along. Obviously not my call but I'm inclined to disagree with that approach and see if we can get the dependencies worked out instead.

zpao avatar Jan 18 '16 19:01 zpao

A simple solution is to upgrade to Babel 6 and rely on the fact that RN depends on Babel anyway and let npm 3 dedupe the dependencies.

Another idea is to publish many packages instead of one fbjs-scripts package. That way as a dependent you'd pay for only what you use. I would think the overhead of publishing many packages is too high but Babel has managed to automate publishing dozens of plugins.

ide avatar Jan 19 '16 07:01 ide