mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Work in progress: start adding ReactNative bundle
This commit is contained in:
+23
-5
@@ -34,7 +34,7 @@ function getAliases(paths, bundleType) {
|
||||
}
|
||||
|
||||
function getBanner(bundleType, hastName) {
|
||||
if (bundleType === bundleTypes.FB) {
|
||||
if (bundleType === bundleTypes.FB || bundleType === bundleTypes.RN) {
|
||||
return (
|
||||
// intentionally not indented correctly, as whitespace is literal
|
||||
`/**
|
||||
@@ -59,6 +59,7 @@ function updateBabelConfig(babelOpts, bundleType) {
|
||||
case bundleTypes.PROD:
|
||||
case bundleTypes.DEV:
|
||||
case bundleTypes.NODE:
|
||||
case bundleTypes.RN:
|
||||
newOpts = Object.assign({}, babelOpts);
|
||||
|
||||
// we add the objectAssign transform for these bundles
|
||||
@@ -106,6 +107,7 @@ function getFormat(bundleType) {
|
||||
return `umd`;
|
||||
case bundleTypes.NODE:
|
||||
case bundleTypes.FB:
|
||||
case bundleTypes.RN:
|
||||
return `cjs`;
|
||||
}
|
||||
}
|
||||
@@ -119,6 +121,7 @@ function getFilename(name, hasteName, bundleType) {
|
||||
case bundleTypes.NODE:
|
||||
return `${name}.cjs.js`;
|
||||
case bundleTypes.FB:
|
||||
case bundleTypes.RN:
|
||||
return `${hasteName}.js`;
|
||||
}
|
||||
}
|
||||
@@ -146,6 +149,7 @@ function getCommonJsConfig(bundleType) {
|
||||
return {};
|
||||
case bundleTypes.NODE: // TODO: why does it share settings with FB?
|
||||
case bundleTypes.FB:
|
||||
case bundleTypes.RN: // TODO: I haven't checked if this is right
|
||||
// Modules we don't want to inline in the bundle.
|
||||
// Force them to stay as require()s in the output.
|
||||
return {
|
||||
@@ -207,15 +211,27 @@ function getPlugins(entry, babelOpts, paths, filename, bundleType) {
|
||||
|
||||
const inputBundleType = argv.type;
|
||||
|
||||
function createBundle({babelOpts, entry, fbEntry, config, paths, name, hasteName}, bundleType) {
|
||||
function createBundle({babelOpts, entry, fbEntry, rnEntry, config, paths, name, hasteName}, bundleType) {
|
||||
if (inputBundleType && inputBundleType !== bundleType) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
switch (bundleType) {
|
||||
case bundleTypes.FB:
|
||||
entry = fbEntry;
|
||||
break;
|
||||
case bundleTypes.RN:
|
||||
entry = rnEntry;
|
||||
break;
|
||||
}
|
||||
if (!entry) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
const filename = getFilename(name, hasteName, bundleType);
|
||||
const format = getFormat(bundleType);
|
||||
|
||||
return rollup({
|
||||
entry: bundleType === bundleTypes.FB ? fbEntry : entry,
|
||||
entry: entry,
|
||||
plugins: getPlugins(entry, babelOpts, paths, filename, bundleType),
|
||||
onwarn: handleRollupWarnings,
|
||||
}).then(({write}) => write(
|
||||
@@ -234,7 +250,9 @@ bundles.forEach(bundle => {
|
||||
);
|
||||
} else {
|
||||
createBundle(bundle, bundleTypes.NODE).then(() =>
|
||||
createBundle(bundle, bundleTypes.FB)
|
||||
createBundle(bundle, bundleTypes.FB).then(() =>
|
||||
createBundle(bundle, bundleTypes.RN)
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
+19
-21
@@ -7,6 +7,7 @@ const bundleTypes = {
|
||||
PROD: 'PROD',
|
||||
NODE: 'NODE',
|
||||
FB: 'FB',
|
||||
RN: 'RN',
|
||||
};
|
||||
|
||||
const babelOptsReact = {
|
||||
@@ -183,28 +184,25 @@ const bundles = [
|
||||
},
|
||||
|
||||
/******* React Native *******/
|
||||
// {
|
||||
// babelOpts: babelOptsReact,
|
||||
// config: {
|
||||
// destDir: 'build/rollup/',
|
||||
// moduleName: 'ReactNative',
|
||||
// sourceMap: false,
|
||||
// },
|
||||
// entry: 'src/umd/ReactDOMUMDEntry.js',
|
||||
// name: 'react-native-renderer',
|
||||
// paths: [
|
||||
// 'src/umd/ReactDOMUMDEntry.js',
|
||||
// 'src/umd/ReactDOMServerUMDEntry.js',
|
||||
{
|
||||
babelOpts: babelOptsReact,
|
||||
config: {
|
||||
destDir: 'build/rollup/',
|
||||
moduleName: 'ReactNative',
|
||||
sourceMap: false,
|
||||
},
|
||||
rnEntry: 'src/renderers/native/ReactNative.js',
|
||||
hasteName: 'ReactNative',
|
||||
name: 'react-native-renderer',
|
||||
paths: [
|
||||
'src/renderers/native/**/*.js',
|
||||
'src/renderers/shared/**/*.js',
|
||||
|
||||
// 'src/renderers/dom/**/*.js',
|
||||
// 'src/renderers/shared/**/*.js',
|
||||
// 'src/test/**/*.js', // ReactTestUtils is currently very coupled to DOM.
|
||||
|
||||
// 'src/ReactVersion.js',
|
||||
// 'src/shared/**/*.js',
|
||||
// ],
|
||||
// umd: false,
|
||||
// },
|
||||
'src/ReactVersion.js',
|
||||
'src/shared/**/*.js',
|
||||
],
|
||||
umd: false,
|
||||
},
|
||||
];
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* 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 NativeMethodsMixin
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const {
|
||||
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
|
||||
} = require('ReactNative');
|
||||
|
||||
module.exports = __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.NativeMethodsMixin;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* 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 ReactDebugTool
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const {
|
||||
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
|
||||
} = require('ReactNative');
|
||||
|
||||
module.exports = __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactDebugTool;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* 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 ReactErrorUtils
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const {
|
||||
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
|
||||
} = require('ReactNative');
|
||||
|
||||
module.exports = __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactErrorUtils;
|
||||
|
||||
@@ -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 ReactNativePropRegistry
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const {
|
||||
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
|
||||
} = require('ReactNative');
|
||||
|
||||
module.exports = __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactNativePropRegistry;
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* 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 TouchHistoryMath
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const {
|
||||
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
|
||||
} = require('ReactNative');
|
||||
|
||||
module.exports = __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.TouchHistoryMath;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* 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 createReactNativeComponentClass
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const {
|
||||
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
|
||||
} = require('ReactNative');
|
||||
|
||||
module.exports = __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.createReactNativeComponentClass;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* 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 findNodeHandle
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const {
|
||||
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
|
||||
} = require('ReactNative');
|
||||
|
||||
module.exports = __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.findNodeHandle;
|
||||
|
||||
@@ -36,6 +36,7 @@ function getExternalModules(bundleType) {
|
||||
};
|
||||
case bundleTypes.NODE:
|
||||
case bundleTypes.FB:
|
||||
case bundleTypes.RN:
|
||||
return {};
|
||||
}
|
||||
}
|
||||
@@ -58,6 +59,7 @@ function getInternalModules(bundleType) {
|
||||
};
|
||||
case bundleTypes.NODE:
|
||||
case bundleTypes.FB:
|
||||
case bundleTypes.RN: // TODO: I haven't checked if this is right
|
||||
return {
|
||||
// we tell Rollup where these files are located internally, otherwise
|
||||
// it doesn't pick them up and assumes they're external
|
||||
@@ -76,6 +78,7 @@ function replaceInternalModules(bundleType) {
|
||||
case bundleTypes.PROD:
|
||||
case bundleTypes.NODE:
|
||||
case bundleTypes.FB:
|
||||
case bundleTypes.RN:
|
||||
// we inline these modules in the bundles rather than leave them as external
|
||||
return {
|
||||
'react-dom/lib/ReactPerf': resolve('./src/renderers/shared/ReactPerf.js'),
|
||||
@@ -112,6 +115,7 @@ function getFbjsModuleAliases(bundleType) {
|
||||
};
|
||||
case bundleTypes.NODE:
|
||||
case bundleTypes.FB:
|
||||
case bundleTypes.RN:
|
||||
// for FB we don't want to bundle the above modules, instead keep them
|
||||
// as external require() calls in the bundle
|
||||
return {};
|
||||
@@ -123,6 +127,7 @@ function replaceFbjsModuleAliases(bundleType) {
|
||||
case bundleTypes.DEV:
|
||||
case bundleTypes.PROD:
|
||||
case bundleTypes.NODE:
|
||||
case bundleTypes.RN:
|
||||
return {};
|
||||
case bundleTypes.FB:
|
||||
// the diff for Haste to support fbjs/lib/* hasn't landed, so this
|
||||
|
||||
@@ -7,9 +7,16 @@
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule ReactNative
|
||||
* @flow
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var ReactNativeStack = require('ReactNativeStack');
|
||||
|
||||
// TODO (bvaughn) Enable Fiber experiement via ReactNativeFeatureFlags
|
||||
module.exports = require('ReactNativeStack');
|
||||
var ReactNative = ReactNativeStack;
|
||||
|
||||
ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = {
|
||||
ReactNativePropRegistry: require('ReactNativePropRegistry'),
|
||||
};
|
||||
|
||||
module.exports = ReactNative;
|
||||
|
||||
Reference in New Issue
Block a user