Skip to content

Commit 66c996c

Browse files
committed
Smaller production builds
Builds on the exclusion of PropTypes from production builds: - Remove 'lodash' and use smaller modules for equivalent functions. - Remove use of some unnecessary Facebook utilities. - Remove 'TouchableBounce'; it isn't part of React Native anymore. - Remove stray import of 'react-dom/server'. - Exclude 'StyleSheetValidation' from production. Measuring the UMD build (gzip)… Before: ~100KB After: ~60KB
1 parent d65c92e commit 66c996c

File tree

21 files changed

+74
-440
lines changed

21 files changed

+74
-440
lines changed

examples/demos/Game2048/Game2048.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var {
2323
AppRegistry,
2424
StyleSheet,
2525
Text,
26-
TouchableBounce,
26+
TouchableOpacity,
2727
View,
2828
} = ReactNative;
2929

@@ -139,9 +139,9 @@ class GameEndOverlay extends React.Component {
139139
return (
140140
<View style={styles.overlay}>
141141
<Text style={styles.overlayMessage}>{message}</Text>
142-
<TouchableBounce onPress={this.props.onRestart} style={styles.tryAgain}>
142+
<TouchableOpacity onPress={this.props.onRestart} style={styles.tryAgain}>
143143
<Text style={styles.tryAgainText}>Try Again?</Text>
144-
</TouchableBounce>
144+
</TouchableOpacity>
145145
</View>
146146
);
147147
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
},
2020
"dependencies": {
2121
"animated": "^0.1.3",
22+
"array-find-index": "^1.0.2",
2223
"babel-plugin-transform-react-remove-prop-types": "^0.2.11",
2324
"babel-runtime": "^6.11.6",
25+
"debounce": "^1.0.0",
26+
"deep-assign": "^2.0.0",
2427
"fbjs": "^0.8.4",
2528
"inline-style-prefixer": "^2.0.1",
26-
"lodash": "^4.15.0",
2729
"react-dom": "~15.3.2",
2830
"react-textarea-autosize": "^4.0.4",
2931
"react-timer-mixin": "^0.13.3",

src/apis/AppRegistry/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import { Component } from 'react';
1010
import invariant from 'fbjs/lib/invariant';
1111
import { unmountComponentAtNode } from 'react/lib/ReactMount';
12-
import renderApplication, { prerenderApplication } from './renderApplication';
12+
import renderApplication, { getApplication } from './renderApplication';
1313

1414
const runnables = {};
1515

src/apis/AppRegistry/renderApplication.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import invariant from 'fbjs/lib/invariant';
1010
import { render } from 'react/lib/ReactMount';
11-
import ReactDOMServer from 'react-dom/server';
1211
import ReactNativeApp from './ReactNativeApp';
1312
import StyleSheet from '../../apis/StyleSheet';
1413
import React, { Component } from 'react';

src/apis/AppState/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import ExecutionEnvironment from 'fbjs/lib/ExecutionEnvironment';
2-
import findIndex from 'lodash/findIndex';
2+
import findIndex from 'array-find-index';
33
import invariant from 'fbjs/lib/invariant';
44

55
const EVENT_TYPES = [ 'change' ];

src/apis/AsyncStorage/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2015-present, Facebook, Inc.
44
* All rights reserved.
55
*/
6-
import merge from 'lodash/merge';
6+
import merge from 'deep-assign';
77

88
const mergeLocalStorageItem = (key, value) => {
99
const oldValue = window.localStorage.getItem(key);

src/apis/Dimensions/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @flow
77
*/
88

9-
import debounce from 'lodash/debounce';
9+
import debounce from 'debounce';
1010
import ExecutionEnvironment from 'fbjs/lib/ExecutionEnvironment';
1111
import invariant from 'fbjs/lib/invariant';
1212

src/apis/InteractionManager/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
*/
77

88
import invariant from 'fbjs/lib/invariant';
9-
import keyMirror from 'fbjs/lib/keyMirror';
109

1110
const InteractionManager = {
12-
Events: keyMirror({
13-
interactionStart: true,
14-
interactionComplete: true
15-
}),
11+
Events: {
12+
interactionStart: 'interactionStart',
13+
interactionComplete: 'interactionComplete'
14+
},
1615

1716
/**
1817
* Schedule a function to run after all interactions have completed.

src/apis/NetInfo/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import ExecutionEnvironment from 'fbjs/lib/ExecutionEnvironment';
10-
import findIndex from 'lodash/findIndex';
10+
import findIndex from 'array-find-index';
1111
import invariant from 'fbjs/lib/invariant';
1212

1313
const connection = ExecutionEnvironment.canUseDOM && (

src/apis/StyleSheet/__tests__/index-test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
/* eslint-env jasmine, jest */
22

33
import { getDefaultStyleSheet } from '../css';
4-
import isPlainObject from 'lodash/isPlainObject';
54
import StyleSheet from '..';
65

6+
const isPlainObject = (x) => {
7+
const toString = Object.prototype.toString;
8+
let proto;
9+
/* eslint-disable */
10+
return (
11+
toString.call(x) === '[object Object]' &&
12+
(proto = Object.getPrototypeOf(x), proto === null || proto === Object.getPrototypeOf({}))
13+
);
14+
/* eslint-enable */
15+
};
16+
717
describe('apis/StyleSheet', () => {
818
beforeEach(() => {
919
StyleSheet._reset();

src/apis/StyleSheet/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import ExecutionEnvironment from 'fbjs/lib/ExecutionEnvironment';
44
import flattenStyle from '../../modules/flattenStyle';
55
import React from 'react';
66
import ReactNativePropRegistry from '../../modules/ReactNativePropRegistry';
7-
import StyleSheetValidation from './StyleSheetValidation';
87

98
let styleElement;
109
let shouldInsertStyleSheet = ExecutionEnvironment.canUseDOM;
@@ -52,7 +51,9 @@ module.exports = {
5251

5352
const result = {};
5453
for (const key in styles) {
55-
StyleSheetValidation.validateStyle(key, styles);
54+
if (process.env.NODE_ENV !== 'production') {
55+
require('./StyleSheetValidation').validateStyle(key, styles);
56+
}
5657
result[key] = ReactNativePropRegistry.register(styles[key]);
5758
}
5859
return result;

src/components/ListView/index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import applyNativeMethods from '../../modules/applyNativeMethods';
22
import ListViewDataSource from './ListViewDataSource';
33
import ListViewPropTypes from './ListViewPropTypes';
4-
import pick from 'lodash/pick';
54
import ScrollView from '../ScrollView';
65
import View from '../View';
76
import React, { Component } from 'react';
87

9-
const scrollViewProps = Object.keys(ScrollView.propTypes);
10-
118
class ListView extends Component {
129
static propTypes = ListViewPropTypes;
1310

@@ -90,9 +87,7 @@ class ListView extends Component {
9087
}
9188
}
9289

93-
const props = pick(this.props, scrollViewProps);
94-
95-
return React.cloneElement(this.props.renderScrollComponent(props), {
90+
return React.cloneElement(this.props.renderScrollComponent(this.props), {
9691
ref: this._setScrollViewRef
9792
}, header, children, footer);
9893
}

src/components/ScrollView/ScrollViewBase.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @flow
77
*/
88

9-
import debounce from 'lodash/debounce';
9+
import debounce from 'debounce';
1010
import View from '../View';
1111
import React, { Component, PropTypes } from 'react';
1212

src/components/Touchable/Touchable.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
/* @edit start */
1616
const BoundingDimensions = require('./BoundingDimensions');
17-
const keyMirror = require('fbjs/lib/keyMirror');
1817
const normalizeColor = require('../../modules/normalizeColor');
1918
const Position = require('./Position');
2019
const React = require('react');
@@ -111,16 +110,16 @@ const View = require('../../components/View');
111110
/**
112111
* Touchable states.
113112
*/
114-
var States = keyMirror({
115-
NOT_RESPONDER: null, // Not the responder
116-
RESPONDER_INACTIVE_PRESS_IN: null, // Responder, inactive, in the `PressRect`
117-
RESPONDER_INACTIVE_PRESS_OUT: null, // Responder, inactive, out of `PressRect`
118-
RESPONDER_ACTIVE_PRESS_IN: null, // Responder, active, in the `PressRect`
119-
RESPONDER_ACTIVE_PRESS_OUT: null, // Responder, active, out of `PressRect`
120-
RESPONDER_ACTIVE_LONG_PRESS_IN: null, // Responder, active, in the `PressRect`, after long press threshold
121-
RESPONDER_ACTIVE_LONG_PRESS_OUT: null, // Responder, active, out of `PressRect`, after long press threshold
122-
ERROR: null
123-
});
113+
var States = {
114+
NOT_RESPONDER: 'NOT_RESPONDER', // Not the responder
115+
RESPONDER_INACTIVE_PRESS_IN: 'RESPONDER_INACTIVE_PRESS_IN', // Responder, inactive, in the `PressRect`
116+
RESPONDER_INACTIVE_PRESS_OUT: 'RESPONDER_INACTIVE_PRESS_OUT', // Responder, inactive, out of `PressRect`
117+
RESPONDER_ACTIVE_PRESS_IN: 'RESPONDER_ACTIVE_PRESS_IN', // Responder, active, in the `PressRect`
118+
RESPONDER_ACTIVE_PRESS_OUT: 'RESPONDER_ACTIVE_PRESS_OUT', // Responder, active, out of `PressRect`
119+
RESPONDER_ACTIVE_LONG_PRESS_IN: 'RESPONDER_ACTIVE_LONG_PRESS_IN', // Responder, active, in the `PressRect`, after long press threshold
120+
RESPONDER_ACTIVE_LONG_PRESS_OUT: 'RESPONDER_ACTIVE_LONG_PRESS_OUT', // Responder, active, out of `PressRect`, after long press threshold
121+
ERROR: 'ERROR'
122+
};
124123

125124
/**
126125
* Quick lookup map for states that are considered to be "active"
@@ -147,15 +146,15 @@ var IsLongPressingIn = {
147146
/**
148147
* Inputs to the state machine.
149148
*/
150-
var Signals = keyMirror({
151-
DELAY: null,
152-
RESPONDER_GRANT: null,
153-
RESPONDER_RELEASE: null,
154-
RESPONDER_TERMINATED: null,
155-
ENTER_PRESS_RECT: null,
156-
LEAVE_PRESS_RECT: null,
157-
LONG_PRESS_DETECTED: null,
158-
});
149+
var Signals = {
150+
DELAY: 'DELAY',
151+
RESPONDER_GRANT: 'RESPONDER_GRANT',
152+
RESPONDER_RELEASE: 'RESPONDER_RELEASE',
153+
RESPONDER_TERMINATED: 'RESPONDER_TERMINATED',
154+
ENTER_PRESS_RECT: 'ENTER_PRESS_RECT',
155+
LEAVE_PRESS_RECT: 'LEAVE_PRESS_RECT',
156+
LONG_PRESS_DETECTED: 'LONG_PRESS_DETECTED',
157+
};
159158

160159
/**
161160
* Mapping from States x Signals => States

0 commit comments

Comments
 (0)