Design an Ecosystem Compatible way for Writing Prepack Specific Branches
#584 opened on May 5, 2017
Description
It is useful to be able to write library code that takes a different path if you know that you're running a Prepack environment and can rely on that code getting pre-evaluated.
let fn = function() { ... };
if (__PREPACK__) {
fn = function() { ... };
}
Right now it is not palatable for libraries (such as React) to publish such code to NPM. Because you can't rely on this being properly stripped out by other build tool chains.
A common pattern is to strip out patterns like:
if (process.env.NODE_ENV !== 'production') { ... }
It might be possible to have a Prepack specific one like:
if (process.env.NODE_ENV === 'prepack-production') { ... }
However, Prepack would then have to special case things like process.env.NODE_ENV !== 'production' to also fail! This is weird.
Another strategy might be something like:
if (false && __PREPACK__) {
}
Other constant folders/minifiers would automatically strip out this branch but we could detect it as a special case and make that branch pass.
Another problem to consider is if minifiers run before Prepack in the build steps, then none of this works.
This is a rabbit hole that needs a solution.
See similar discussion about introducing a "profile" build of React. https://github.com/facebook/react/issues/6627