more progress on forwarding modules and FB config

This commit is contained in:
Dominic Gannaway
2017-03-09 15:11:06 +00:00
parent 690a72b870
commit ff0c87129f
8 changed files with 139 additions and 5 deletions
+29 -5
View File
@@ -51,12 +51,14 @@ function getBanner(bundleType, hastName) {
return '';
}
function updaateBabelConfig(babelOpts, bundleType) {
function updateBabelConfig(babelOpts, bundleType) {
let newOpts;
switch (bundleType) {
case bundleTypes.PROD:
case bundleTypes.DEV:
case bundleTypes.NODE:
const newOpts = Object.assign({}, babelOpts);
newOpts = Object.assign({}, babelOpts);
// we add the objectAssign transform for these bundles
newOpts.plugins = newOpts.plugins.slice();
@@ -65,7 +67,11 @@ function updaateBabelConfig(babelOpts, bundleType) {
);
return newOpts;
case bundleTypes.FB:
return babelOpts;
newOpts = Object.assign({}, babelOpts);
// for FB, we don't want the devExpressionWithCodes plugin to run
newOpts.plugins = [];
return newOpts;
}
}
@@ -125,6 +131,24 @@ function uglifyConfig() {
};
}
function getCommonJsConfig(bundleType) {
switch (bundleType) {
case bundleTypes.PROD:
case bundleTypes.DEV:
return {};
case bundleTypes.NODE:
case bundleTypes.FB:
// we ignore the require() for some inline modules
// wrapped in __DEV__
return {
ignore: [
'ReactPerf',
'ReactTestUtils',
],
};
}
}
function getPlugins(entry, babelOpts, paths, filename, bundleType) {
const plugins = [
replace(
@@ -133,9 +157,9 @@ function getPlugins(entry, babelOpts, paths, filename, bundleType) {
replaceFbjsModuleAliases(bundleType)
)
),
babel(updaateBabelConfig(babelOpts, bundleType)),
babel(updateBabelConfig(babelOpts, bundleType)),
alias(getAliases(paths, bundleType)),
commonjs(),
commonjs(getCommonJsConfig(bundleType)),
];
if (bundleType === bundleTypes.PROD) {
plugins.push(
+19
View File
@@ -0,0 +1,19 @@
/**
* Copyright 2013-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.
*
* @providesModule ReactPerf
* @flow
*/
'use strict';
const {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
} = require('ReactDOM');
module.exports = __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactPerf;
@@ -0,0 +1,19 @@
/**
* Copyright 2013-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.
*
* @providesModule ReactTestUtils
* @flow
*/
'use strict';
const {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
} = require('ReactDOM');
module.exports = __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactTestUtils;
@@ -0,0 +1,19 @@
/**
* Copyright 2013-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.
*
* @providesModule flattenChildren
* @flow
*/
'use strict';
const {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
} = require('React');
module.exports = __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.flattenChildren;
+39
View File
@@ -0,0 +1,39 @@
/**
* Copyright 2013-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.
*
* @providesModule onlyChild
*/
'use strict';
var { isValidElement } = require('React');
var invariant = require('invariant');
/**
* Returns the first child in a collection of children and verifies that there
* is only one child in the collection.
*
* See https://facebook.github.io/react/docs/react-api.html#react.children.only
*
* The current implementation of this function assumes that a single child gets
* passed without a wrapper, but the purpose of this helper function is to
* abstract away the particular structure of children.
*
* @param {?object} children Child collection structure.
* @return {ReactElement} The first and only `ReactElement` contained in the
* structure.
*/
function onlyChild(children) {
invariant(
isValidElement(children),
'React.Children.only expected to receive a single React element child.'
);
return children;
}
module.exports = onlyChild;
+1
View File
@@ -113,6 +113,7 @@ function replaceFbjsModuleAliases(bundleType) {
'fbjs/lib/ExecutionEnvironment': 'ExecutionEnvironment',
'fbjs/lib/createNodesFromMarkup': 'createNodesFromMarkup',
'fbjs/lib/performanceNow': 'performanceNow',
"'react'": "'React'",
};
}
}
+12
View File
@@ -22,4 +22,16 @@ ReactDOMFiber.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = {
SyntheticEvent: require('SyntheticEvent'),
};
if (__DEV__) {
Object.assign(
ReactDOMFiber.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
{
// ReactPerf and ReactTestUtils currently only work with the DOM renderer
// so we expose them from here, but only in DEV mode.
ReactPerf: require('react-dom/lib/ReactPerf'),
ReactTestUtils: require('react-dom/lib/ReactTestUtils'),
}
);
}
module.exports = ReactDOMFiber;
+1
View File
@@ -19,6 +19,7 @@ var ReactFBEntry = Object.assign({
ReactCurrentOwner: require('react/lib/ReactCurrentOwner'),
getComponentName: require('getComponentName'),
ReactInstanceMap: require('react-dom/lib/ReactInstanceMap'),
flattenChildren: require('flattenChildren'),
},
}, React);