Skip to content

Commit

Permalink
Enable error code transform per package
Browse files Browse the repository at this point in the history
Currently we're not consistent about which packages should have their
errors minified in production and which ones should.

This adds a field to the bundle configuration to control whether to
apply the transform. We should decide what the criteria is going
forward. I think it's probably a good idea to minify any package that
gets sent over the network. So yes to modules that run in the browser,
and no to modules that run on the server and during development only.
  • Loading branch information
acdlite committed Sep 30, 2021
1 parent a6a6466 commit 3ed2d03
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 10 deletions.
17 changes: 7 additions & 10 deletions scripts/rollup/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ function getBabelConfig(
bundleType,
packageName,
externals,
isDevelopment
isDevelopment,
bundle
) {
const canAccessReactObject =
packageName === 'react' || externals.indexOf('react') !== -1;
Expand Down Expand Up @@ -179,12 +180,6 @@ function getBabelConfig(
case FB_WWW_DEV:
case FB_WWW_PROD:
case FB_WWW_PROFILING:
return Object.assign({}, options, {
plugins: options.plugins.concat([
// Minify invariant messages
require('../error-codes/transform-error-messages'),
]),
});
case RN_OSS_DEV:
case RN_OSS_PROD:
case RN_OSS_PROFILING:
Expand All @@ -195,8 +190,9 @@ function getBabelConfig(
plugins: options.plugins.concat([
[
require('../error-codes/transform-error-messages'),
// Preserve full error messages in React Native build
{noMinify: true},
// Controls whether to replace error messages with error codes
// in production. By default, error messages are replaced.
{noMinify: bundle.minifyWithProdErrorCodes === false},
],
]),
});
Expand Down Expand Up @@ -390,7 +386,8 @@ function getPlugins(
bundleType,
packageName,
externals,
!isProduction
!isProduction,
bundle
)
),
// Remove 'use strict' from individual source files.
Expand Down
Loading

0 comments on commit 3ed2d03

Please sign in to comment.