mirror of
https://github.com/status-im/react-native.git
synced 2025-01-10 01:25:39 +00:00
9d09efdd53
Summary:Make packager transform files before extracting their dependencies. This allows us to extract dependencies added by transforms (and to avoid including them manually). It also allows for better optimization and to get rid of the “whole program optimization” step: This diff utilizes the new worker introduced in D2976677 / d94a567 – that means that minified builds inline the following variables: - `__DEV__` → `false` - `process.env.NODE_ENV` → `'production'` - `Platform.OS` / `React.Platform.OS` → `'android'` / `'ios'` and eliminates branches of conditionals with constant conditions. Dependency extraction happens only after that step, which means that production bundles don’t include any modules that are not used. Fixes #4185 Reviewed By: martinbigio Differential Revision: D2977169 fb-gh-sync-id: e6ce8dd29d1b49aec49b309201141f5b2709da1d shipit-source-id: e6ce8dd29d1b49aec49b309201141f5b2709da1d
55 lines
1.5 KiB
JavaScript
55 lines
1.5 KiB
JavaScript
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
'use strict';
|
|
|
|
const Promise = require('promise');
|
|
const sign = require('../sign');
|
|
const writeFile = require('./writeFile');
|
|
|
|
function buildBundle(packagerClient, requestOptions) {
|
|
return packagerClient.buildBundle(requestOptions);
|
|
}
|
|
|
|
function createCodeWithMap(bundle, dev) {
|
|
return {
|
|
code: bundle.getSource({dev}),
|
|
map: JSON.stringify(bundle.getSourceMap({dev})),
|
|
};
|
|
}
|
|
|
|
function saveBundleAndMap(bundle, options, log) {
|
|
const {
|
|
'bundle-output': bundleOutput,
|
|
'bundle-encoding': encoding,
|
|
dev,
|
|
'sourcemap-output': sourcemapOutput,
|
|
} = options;
|
|
|
|
log('start');
|
|
const codeWithMap = createCodeWithMap(bundle, dev);
|
|
log('finish');
|
|
|
|
log('Writing bundle output to:', bundleOutput);
|
|
const writeBundle = writeFile(bundleOutput, sign(codeWithMap.code), encoding);
|
|
writeBundle.then(() => log('Done writing bundle output'));
|
|
|
|
if (sourcemapOutput) {
|
|
log('Writing sourcemap output to:', sourcemapOutput);
|
|
const writeMap = writeFile(sourcemapOutput, codeWithMap.map, null);
|
|
writeMap.then(() => log('Done writing sourcemap output'));
|
|
return Promise.all([writeBundle, writeMap]);
|
|
} else {
|
|
return writeBundle;
|
|
}
|
|
}
|
|
|
|
exports.build = buildBundle;
|
|
exports.save = saveBundleAndMap;
|
|
exports.formatName = 'bundle';
|