facebookarchive/prepack

Design an Ecosystem Compatible way for Writing Prepack Specific Branches

Open

#584 创建于 2017年5月5日

在 GitHub 查看
 (4 评论) (0 反应) (0 负责人)JavaScript (14,268 star) (520 fork)batch import
design neededenhancementhelp wanted

描述

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

贡献者指南