mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
3f73dcee37
* Rename "name"->"filepath" field on Webpack module references This field name will get confused with the imported name or the module id. * Switch back to transformSource instead of getSource getSource would be more efficient in the cases where we don't need to read the original file but we'll need to most of the time. Even then, we can't return a JS file if we're trying to support non-JS loader because it'll end up being transformed. Similarly, we'll need to parse the file and we can't parse it before it's transformed. So we need to chain with other loaders that know how. * Add acorn dependency This should be the version used by Webpack since we have a dependency on Webpack anyway. * Parse exported names of ESM modules We need to statically resolve the names that a client component will export so that we can export a module reference for each of the names. For export * from, this gets tricky because we need to also load the source of the next file to parse that. We don't know exactly how the client is built so we guess it's somewhat default. * Handle imported names one level deep in CommonJS using a Proxy We use a proxy to see what property the server access and that will tell us which property we'll want to import on the client. * Add export name to module reference and Webpack map To support named exports each name needs to be encoded as a separate reference. It's possible with module splitting that different exports end up in different chunks. It's also possible that the export is renamed as part of minification. So the map also includes a map from the original to the bundled name. * Special case plain CJS requires and conditional imports using __esModule This models if the server tries to import .default or a plain require. We should replicate the same thing on the client when we load that module reference. * Dedupe acorn-related deps Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
844 lines
20 KiB
JavaScript
844 lines
20 KiB
JavaScript
'use strict';
|
|
|
|
const RELEASE_CHANNEL = process.env.RELEASE_CHANNEL;
|
|
|
|
const __EXPERIMENTAL__ =
|
|
typeof RELEASE_CHANNEL === 'string'
|
|
? RELEASE_CHANNEL === 'experimental'
|
|
: true;
|
|
|
|
const bundleTypes = {
|
|
NODE_ES2015: 'NODE_ES2015',
|
|
NODE_ESM: 'NODE_ESM',
|
|
UMD_DEV: 'UMD_DEV',
|
|
UMD_PROD: 'UMD_PROD',
|
|
UMD_PROFILING: 'UMD_PROFILING',
|
|
NODE_DEV: 'NODE_DEV',
|
|
NODE_PROD: 'NODE_PROD',
|
|
NODE_PROFILING: 'NODE_PROFILING',
|
|
FB_WWW_DEV: 'FB_WWW_DEV',
|
|
FB_WWW_PROD: 'FB_WWW_PROD',
|
|
FB_WWW_PROFILING: 'FB_WWW_PROFILING',
|
|
RN_OSS_DEV: 'RN_OSS_DEV',
|
|
RN_OSS_PROD: 'RN_OSS_PROD',
|
|
RN_OSS_PROFILING: 'RN_OSS_PROFILING',
|
|
RN_FB_DEV: 'RN_FB_DEV',
|
|
RN_FB_PROD: 'RN_FB_PROD',
|
|
RN_FB_PROFILING: 'RN_FB_PROFILING',
|
|
};
|
|
|
|
const {
|
|
NODE_ES2015,
|
|
NODE_ESM,
|
|
UMD_DEV,
|
|
UMD_PROD,
|
|
UMD_PROFILING,
|
|
NODE_DEV,
|
|
NODE_PROD,
|
|
NODE_PROFILING,
|
|
FB_WWW_DEV,
|
|
FB_WWW_PROD,
|
|
FB_WWW_PROFILING,
|
|
RN_OSS_DEV,
|
|
RN_OSS_PROD,
|
|
RN_OSS_PROFILING,
|
|
RN_FB_DEV,
|
|
RN_FB_PROD,
|
|
RN_FB_PROFILING,
|
|
} = bundleTypes;
|
|
|
|
const moduleTypes = {
|
|
// React
|
|
ISOMORPHIC: 'ISOMORPHIC',
|
|
// Individual renderers. They bundle the reconciler. (e.g. ReactDOM)
|
|
RENDERER: 'RENDERER',
|
|
// Helper packages that access specific renderer's internals. (e.g. TestUtils)
|
|
RENDERER_UTILS: 'RENDERER_UTILS',
|
|
// Standalone reconciler for third-party renderers.
|
|
RECONCILER: 'RECONCILER',
|
|
// Non-Fiber implementations like SSR and Shallow renderers.
|
|
NON_FIBER_RENDERER: 'NON_FIBER_RENDERER',
|
|
};
|
|
|
|
const {
|
|
ISOMORPHIC,
|
|
RENDERER,
|
|
RENDERER_UTILS,
|
|
RECONCILER,
|
|
NON_FIBER_RENDERER,
|
|
} = moduleTypes;
|
|
|
|
const bundles = [
|
|
/******* Isomorphic *******/
|
|
{
|
|
bundleTypes: [
|
|
UMD_DEV,
|
|
UMD_PROD,
|
|
UMD_PROFILING,
|
|
NODE_DEV,
|
|
NODE_PROD,
|
|
FB_WWW_DEV,
|
|
FB_WWW_PROD,
|
|
FB_WWW_PROFILING,
|
|
RN_FB_DEV,
|
|
RN_FB_PROD,
|
|
RN_FB_PROFILING,
|
|
],
|
|
moduleType: ISOMORPHIC,
|
|
entry: 'react',
|
|
global: 'React',
|
|
externals: [],
|
|
},
|
|
|
|
/******* Isomorphic Server Only *******/
|
|
{
|
|
bundleTypes: [NODE_DEV, NODE_PROD],
|
|
moduleType: ISOMORPHIC,
|
|
entry: 'react/unstable-index.server',
|
|
global: 'React',
|
|
externals: [],
|
|
},
|
|
|
|
/******* React JSX Runtime *******/
|
|
{
|
|
bundleTypes: [
|
|
NODE_DEV,
|
|
NODE_PROD,
|
|
NODE_PROFILING,
|
|
// TODO: use on WWW.
|
|
RN_FB_DEV,
|
|
RN_FB_PROD,
|
|
RN_FB_PROFILING,
|
|
],
|
|
moduleType: ISOMORPHIC,
|
|
entry: 'react/jsx-runtime',
|
|
global: 'JSXRuntime',
|
|
externals: ['react'],
|
|
},
|
|
|
|
/******* React JSX DEV Runtime *******/
|
|
{
|
|
bundleTypes: [
|
|
NODE_DEV,
|
|
NODE_PROD,
|
|
NODE_PROFILING,
|
|
FB_WWW_DEV,
|
|
FB_WWW_PROD,
|
|
FB_WWW_PROFILING,
|
|
RN_FB_DEV,
|
|
RN_FB_PROD,
|
|
RN_FB_PROFILING,
|
|
],
|
|
moduleType: ISOMORPHIC,
|
|
entry: 'react/jsx-dev-runtime',
|
|
global: 'JSXDEVRuntime',
|
|
externals: ['react'],
|
|
},
|
|
|
|
/******* React Cache (experimental, new) *******/
|
|
{
|
|
bundleTypes: __EXPERIMENTAL__ ? [NODE_DEV, NODE_PROD, NODE_PROFILING] : [],
|
|
moduleType: ISOMORPHIC,
|
|
entry: 'react/unstable-cache',
|
|
global: 'ReactCache',
|
|
externals: ['react'],
|
|
},
|
|
|
|
/******* React Fetch Browser (experimental, new) *******/
|
|
{
|
|
bundleTypes: [NODE_DEV, NODE_PROD],
|
|
moduleType: ISOMORPHIC,
|
|
entry: 'react-fetch/index.browser',
|
|
global: 'ReactFetch',
|
|
externals: ['react'],
|
|
},
|
|
|
|
/******* React Fetch Node (experimental, new) *******/
|
|
{
|
|
bundleTypes: [NODE_DEV, NODE_PROD],
|
|
moduleType: ISOMORPHIC,
|
|
entry: 'react-fetch/index.node',
|
|
global: 'ReactFetch',
|
|
externals: ['react', 'http', 'https'],
|
|
},
|
|
|
|
/******* React DOM *******/
|
|
{
|
|
bundleTypes: [
|
|
UMD_DEV,
|
|
UMD_PROD,
|
|
UMD_PROFILING,
|
|
NODE_DEV,
|
|
NODE_PROD,
|
|
NODE_PROFILING,
|
|
FB_WWW_DEV,
|
|
FB_WWW_PROD,
|
|
FB_WWW_PROFILING,
|
|
],
|
|
moduleType: RENDERER,
|
|
entry: 'react-dom',
|
|
global: 'ReactDOM',
|
|
externals: ['react'],
|
|
},
|
|
|
|
/******* React DOM - www - Uses forked reconciler *******/
|
|
{
|
|
moduleType: RENDERER,
|
|
bundleTypes: [FB_WWW_DEV, FB_WWW_PROD, FB_WWW_PROFILING],
|
|
entry: 'react-dom',
|
|
global: 'ReactDOMForked',
|
|
enableNewReconciler: true,
|
|
externals: ['react'],
|
|
},
|
|
|
|
/******* Test Utils *******/
|
|
{
|
|
moduleType: RENDERER_UTILS,
|
|
bundleTypes: [FB_WWW_DEV, NODE_DEV, NODE_PROD, UMD_DEV, UMD_PROD],
|
|
entry: 'react-dom/test-utils',
|
|
global: 'ReactTestUtils',
|
|
externals: ['react', 'react-dom'],
|
|
},
|
|
|
|
/******* React DOM - www - Testing *******/
|
|
{
|
|
moduleType: RENDERER,
|
|
bundleTypes: [FB_WWW_DEV, FB_WWW_PROD],
|
|
entry: 'react-dom/testing',
|
|
global: 'ReactDOMTesting',
|
|
externals: ['react'],
|
|
},
|
|
|
|
/******* React DOM Server *******/
|
|
{
|
|
bundleTypes: [
|
|
UMD_DEV,
|
|
UMD_PROD,
|
|
NODE_DEV,
|
|
NODE_PROD,
|
|
FB_WWW_DEV,
|
|
FB_WWW_PROD,
|
|
],
|
|
moduleType: NON_FIBER_RENDERER,
|
|
entry: 'react-dom/server.browser',
|
|
global: 'ReactDOMServer',
|
|
externals: ['react'],
|
|
babel: opts =>
|
|
Object.assign({}, opts, {
|
|
plugins: opts.plugins.concat([
|
|
[require.resolve('@babel/plugin-transform-classes'), {loose: true}],
|
|
]),
|
|
}),
|
|
},
|
|
{
|
|
bundleTypes: [NODE_DEV, NODE_PROD],
|
|
moduleType: NON_FIBER_RENDERER,
|
|
entry: 'react-dom/server.node',
|
|
externals: ['react', 'stream'],
|
|
babel: opts =>
|
|
Object.assign({}, opts, {
|
|
plugins: opts.plugins.concat([
|
|
[require.resolve('@babel/plugin-transform-classes'), {loose: true}],
|
|
]),
|
|
}),
|
|
},
|
|
|
|
/******* React DOM Fizz Server *******/
|
|
{
|
|
bundleTypes: __EXPERIMENTAL__
|
|
? [NODE_DEV, NODE_PROD, UMD_DEV, UMD_PROD]
|
|
: [],
|
|
moduleType: RENDERER,
|
|
entry: 'react-dom/unstable-fizz.browser',
|
|
global: 'ReactDOMFizzServer',
|
|
externals: ['react', 'react-dom/server'],
|
|
},
|
|
{
|
|
bundleTypes: __EXPERIMENTAL__ ? [NODE_DEV, NODE_PROD] : [],
|
|
moduleType: RENDERER,
|
|
entry: 'react-dom/unstable-fizz.node',
|
|
global: 'ReactDOMFizzServer',
|
|
externals: ['react', 'react-dom/server'],
|
|
},
|
|
|
|
/******* React Transport DOM Server Webpack *******/
|
|
{
|
|
bundleTypes: [NODE_DEV, NODE_PROD, UMD_DEV, UMD_PROD],
|
|
moduleType: RENDERER,
|
|
entry: 'react-transport-dom-webpack/server.browser',
|
|
global: 'ReactTransportDOMServer',
|
|
externals: ['react', 'react-dom/server'],
|
|
},
|
|
{
|
|
bundleTypes: [NODE_DEV, NODE_PROD],
|
|
moduleType: RENDERER,
|
|
entry: 'react-transport-dom-webpack/server.node',
|
|
global: 'ReactTransportDOMServer',
|
|
externals: ['react', 'react-dom/server'],
|
|
},
|
|
|
|
/******* React Transport DOM Client Webpack *******/
|
|
{
|
|
bundleTypes: [NODE_DEV, NODE_PROD, UMD_DEV, UMD_PROD],
|
|
moduleType: RENDERER,
|
|
entry: 'react-transport-dom-webpack',
|
|
global: 'ReactTransportDOMClient',
|
|
externals: ['react'],
|
|
},
|
|
|
|
/******* React Transport DOM Webpack Plugin *******/
|
|
{
|
|
bundleTypes: [NODE_ES2015],
|
|
moduleType: RENDERER_UTILS,
|
|
entry: 'react-transport-dom-webpack/plugin',
|
|
global: 'ReactFlightWebpackPlugin',
|
|
externals: [],
|
|
},
|
|
|
|
/******* React Transport DOM Webpack Node.js Loader *******/
|
|
{
|
|
bundleTypes: [NODE_ESM],
|
|
moduleType: RENDERER_UTILS,
|
|
entry: 'react-transport-dom-webpack/node-loader',
|
|
global: 'ReactFlightWebpackNodeLoader',
|
|
externals: ['acorn'],
|
|
},
|
|
|
|
/******* React Transport DOM Webpack Node.js CommonJS Loader *******/
|
|
{
|
|
bundleTypes: [NODE_ES2015],
|
|
moduleType: RENDERER_UTILS,
|
|
entry: 'react-transport-dom-webpack/node-register',
|
|
global: 'ReactFlightWebpackNodeRegister',
|
|
externals: ['url', 'module'],
|
|
},
|
|
|
|
/******* React Transport DOM Server Relay *******/
|
|
{
|
|
bundleTypes: [FB_WWW_DEV, FB_WWW_PROD],
|
|
moduleType: RENDERER,
|
|
entry: 'react-transport-dom-relay/server',
|
|
global: 'ReactFlightDOMRelayServer',
|
|
externals: [
|
|
'react',
|
|
'react-dom/server',
|
|
'ReactFlightDOMRelayServerIntegration',
|
|
'JSResourceReference',
|
|
],
|
|
},
|
|
|
|
/******* React Transport DOM Client Relay *******/
|
|
{
|
|
bundleTypes: [FB_WWW_DEV, FB_WWW_PROD],
|
|
moduleType: RENDERER,
|
|
entry: 'react-transport-dom-relay',
|
|
global: 'ReactFlightDOMRelayClient',
|
|
externals: [
|
|
'react',
|
|
'ReactFlightDOMRelayClientIntegration',
|
|
'JSResourceReference',
|
|
],
|
|
},
|
|
|
|
/******* React Transport Native Server Relay *******/
|
|
{
|
|
bundleTypes: [RN_FB_DEV, RN_FB_PROD],
|
|
moduleType: RENDERER,
|
|
entry: 'react-transport-native-relay/server',
|
|
global: 'ReactFlightNativeRelayServer',
|
|
externals: [
|
|
'react',
|
|
'ReactFlightNativeRelayServerIntegration',
|
|
'JSResourceReferenceImpl',
|
|
],
|
|
},
|
|
|
|
/******* React Transport Native Client Relay *******/
|
|
{
|
|
bundleTypes: [RN_FB_DEV, RN_FB_PROD],
|
|
moduleType: RENDERER,
|
|
entry: 'react-transport-native-relay',
|
|
global: 'ReactFlightNativeRelayClient',
|
|
externals: [
|
|
'react',
|
|
'ReactFlightNativeRelayClientIntegration',
|
|
'JSResourceReferenceImpl',
|
|
],
|
|
},
|
|
|
|
/******* React ART *******/
|
|
{
|
|
bundleTypes: [
|
|
UMD_DEV,
|
|
UMD_PROD,
|
|
NODE_DEV,
|
|
NODE_PROD,
|
|
FB_WWW_DEV,
|
|
FB_WWW_PROD,
|
|
],
|
|
moduleType: RENDERER,
|
|
entry: 'react-art',
|
|
global: 'ReactART',
|
|
externals: ['react'],
|
|
babel: opts =>
|
|
Object.assign({}, opts, {
|
|
// Include JSX
|
|
presets: opts.presets.concat([
|
|
require.resolve('@babel/preset-react'),
|
|
require.resolve('@babel/preset-flow'),
|
|
]),
|
|
plugins: opts.plugins.concat([
|
|
[require.resolve('@babel/plugin-transform-classes'), {loose: true}],
|
|
]),
|
|
}),
|
|
},
|
|
|
|
/******* React Native *******/
|
|
{
|
|
bundleTypes: __EXPERIMENTAL__
|
|
? []
|
|
: [RN_FB_DEV, RN_FB_PROD, RN_FB_PROFILING],
|
|
moduleType: RENDERER,
|
|
entry: 'react-native-renderer',
|
|
global: 'ReactNativeRenderer',
|
|
externals: ['react-native'],
|
|
babel: opts =>
|
|
Object.assign({}, opts, {
|
|
plugins: opts.plugins.concat([
|
|
[require.resolve('@babel/plugin-transform-classes'), {loose: true}],
|
|
]),
|
|
}),
|
|
},
|
|
{
|
|
bundleTypes: [RN_OSS_DEV, RN_OSS_PROD, RN_OSS_PROFILING],
|
|
moduleType: RENDERER,
|
|
entry: 'react-native-renderer',
|
|
global: 'ReactNativeRenderer',
|
|
externals: ['react-native'],
|
|
babel: opts =>
|
|
Object.assign({}, opts, {
|
|
plugins: opts.plugins.concat([
|
|
[require.resolve('@babel/plugin-transform-classes'), {loose: true}],
|
|
]),
|
|
}),
|
|
},
|
|
|
|
/******* React Native Fabric *******/
|
|
{
|
|
bundleTypes: __EXPERIMENTAL__
|
|
? []
|
|
: [RN_FB_DEV, RN_FB_PROD, RN_FB_PROFILING],
|
|
moduleType: RENDERER,
|
|
entry: 'react-native-renderer/fabric',
|
|
global: 'ReactFabric',
|
|
externals: ['react-native'],
|
|
babel: opts =>
|
|
Object.assign({}, opts, {
|
|
plugins: opts.plugins.concat([
|
|
[require.resolve('@babel/plugin-transform-classes'), {loose: true}],
|
|
]),
|
|
}),
|
|
},
|
|
{
|
|
bundleTypes: [RN_OSS_DEV, RN_OSS_PROD, RN_OSS_PROFILING],
|
|
moduleType: RENDERER,
|
|
entry: 'react-native-renderer/fabric',
|
|
global: 'ReactFabric',
|
|
externals: ['react-native'],
|
|
babel: opts =>
|
|
Object.assign({}, opts, {
|
|
plugins: opts.plugins.concat([
|
|
[require.resolve('@babel/plugin-transform-classes'), {loose: true}],
|
|
]),
|
|
}),
|
|
},
|
|
|
|
/******* React Test Renderer *******/
|
|
{
|
|
bundleTypes: [
|
|
FB_WWW_DEV,
|
|
NODE_DEV,
|
|
NODE_PROD,
|
|
UMD_DEV,
|
|
UMD_PROD,
|
|
RN_FB_DEV,
|
|
RN_FB_PROD,
|
|
RN_FB_PROFILING,
|
|
],
|
|
moduleType: RENDERER,
|
|
entry: 'react-test-renderer',
|
|
global: 'ReactTestRenderer',
|
|
externals: ['react', 'scheduler', 'scheduler/unstable_mock'],
|
|
babel: opts =>
|
|
Object.assign({}, opts, {
|
|
plugins: opts.plugins.concat([
|
|
[require.resolve('@babel/plugin-transform-classes'), {loose: true}],
|
|
]),
|
|
}),
|
|
},
|
|
|
|
/******* React Noop Renderer (used for tests) *******/
|
|
{
|
|
bundleTypes: [NODE_DEV, NODE_PROD],
|
|
moduleType: RENDERER,
|
|
entry: 'react-noop-renderer',
|
|
global: 'ReactNoopRenderer',
|
|
externals: ['react', 'scheduler', 'scheduler/unstable_mock', 'expect'],
|
|
},
|
|
|
|
/******* React Noop Persistent Renderer (used for tests) *******/
|
|
{
|
|
bundleTypes: [NODE_DEV, NODE_PROD],
|
|
moduleType: RENDERER,
|
|
entry: 'react-noop-renderer/persistent',
|
|
global: 'ReactNoopRendererPersistent',
|
|
externals: ['react', 'scheduler', 'expect'],
|
|
},
|
|
|
|
/******* React Noop Server Renderer (used for tests) *******/
|
|
{
|
|
bundleTypes: [NODE_DEV, NODE_PROD],
|
|
moduleType: RENDERER,
|
|
entry: 'react-noop-renderer/server',
|
|
global: 'ReactNoopRendererServer',
|
|
externals: ['react', 'scheduler', 'expect'],
|
|
},
|
|
|
|
/******* React Noop Flight Server (used for tests) *******/
|
|
{
|
|
bundleTypes: [NODE_DEV, NODE_PROD],
|
|
moduleType: RENDERER,
|
|
entry: 'react-noop-renderer/flight-server',
|
|
global: 'ReactNoopFlightServer',
|
|
externals: [
|
|
'react',
|
|
'scheduler',
|
|
'expect',
|
|
'react-noop-renderer/flight-modules',
|
|
],
|
|
},
|
|
|
|
/******* React Noop Flight Client (used for tests) *******/
|
|
{
|
|
bundleTypes: [NODE_DEV, NODE_PROD],
|
|
moduleType: RENDERER,
|
|
entry: 'react-noop-renderer/flight-client',
|
|
global: 'ReactNoopFlightClient',
|
|
externals: [
|
|
'react',
|
|
'scheduler',
|
|
'expect',
|
|
'react-noop-renderer/flight-modules',
|
|
],
|
|
},
|
|
|
|
/******* React Reconciler *******/
|
|
{
|
|
bundleTypes: [NODE_DEV, NODE_PROD, NODE_PROFILING],
|
|
moduleType: RECONCILER,
|
|
entry: 'react-reconciler',
|
|
global: 'ReactReconciler',
|
|
externals: ['react'],
|
|
},
|
|
|
|
/******* React Server *******/
|
|
{
|
|
bundleTypes: [NODE_DEV, NODE_PROD],
|
|
moduleType: RECONCILER,
|
|
entry: 'react-server',
|
|
global: 'ReactServer',
|
|
externals: ['react'],
|
|
},
|
|
|
|
/******* React Flight Server *******/
|
|
{
|
|
bundleTypes: [NODE_DEV, NODE_PROD],
|
|
moduleType: RECONCILER,
|
|
entry: 'react-server/flight',
|
|
global: 'ReactFlightServer',
|
|
externals: ['react'],
|
|
},
|
|
|
|
/******* React Flight Client *******/
|
|
{
|
|
bundleTypes: [NODE_DEV, NODE_PROD],
|
|
moduleType: RECONCILER,
|
|
entry: 'react-client/flight',
|
|
global: 'ReactFlightClient',
|
|
externals: ['react'],
|
|
},
|
|
|
|
/******* Reflection *******/
|
|
{
|
|
moduleType: RENDERER_UTILS,
|
|
bundleTypes: [NODE_DEV, NODE_PROD],
|
|
entry: 'react-reconciler/reflection',
|
|
global: 'ReactFiberTreeReflection',
|
|
externals: [],
|
|
},
|
|
|
|
/******* React Is *******/
|
|
{
|
|
bundleTypes: [
|
|
NODE_DEV,
|
|
NODE_PROD,
|
|
FB_WWW_DEV,
|
|
FB_WWW_PROD,
|
|
UMD_DEV,
|
|
UMD_PROD,
|
|
],
|
|
moduleType: ISOMORPHIC,
|
|
entry: 'react-is',
|
|
global: 'ReactIs',
|
|
externals: [],
|
|
},
|
|
|
|
/******* React Debug Tools *******/
|
|
{
|
|
bundleTypes: [NODE_DEV, NODE_PROD],
|
|
moduleType: ISOMORPHIC,
|
|
entry: 'react-debug-tools',
|
|
global: 'ReactDebugTools',
|
|
externals: [],
|
|
},
|
|
|
|
/******* React Cache (experimental, old) *******/
|
|
{
|
|
// This is only used by our own tests.
|
|
// We can delete it later.
|
|
bundleTypes: [NODE_DEV, NODE_PROD],
|
|
moduleType: ISOMORPHIC,
|
|
entry: 'react-cache',
|
|
global: 'ReactCacheOld',
|
|
externals: ['react', 'scheduler'],
|
|
},
|
|
|
|
/******* createComponentWithSubscriptions *******/
|
|
{
|
|
bundleTypes: [NODE_DEV, NODE_PROD],
|
|
moduleType: ISOMORPHIC,
|
|
entry: 'create-subscription',
|
|
global: 'createSubscription',
|
|
externals: ['react'],
|
|
babel: opts =>
|
|
Object.assign({}, opts, {
|
|
plugins: opts.plugins.concat([
|
|
[require.resolve('@babel/plugin-transform-classes'), {loose: true}],
|
|
]),
|
|
}),
|
|
},
|
|
|
|
/******* Hook for managing subscriptions safely *******/
|
|
{
|
|
bundleTypes: [NODE_DEV, NODE_PROD],
|
|
moduleType: ISOMORPHIC,
|
|
entry: 'use-subscription',
|
|
global: 'useSubscription',
|
|
externals: ['react'],
|
|
},
|
|
|
|
/******* React Scheduler (experimental) *******/
|
|
{
|
|
bundleTypes: [
|
|
NODE_DEV,
|
|
NODE_PROD,
|
|
FB_WWW_DEV,
|
|
FB_WWW_PROD,
|
|
FB_WWW_PROFILING,
|
|
RN_FB_DEV,
|
|
RN_FB_PROD,
|
|
RN_FB_PROFILING,
|
|
],
|
|
moduleType: ISOMORPHIC,
|
|
entry: 'scheduler',
|
|
global: 'Scheduler',
|
|
externals: [],
|
|
},
|
|
|
|
/******* React Scheduler Mock (experimental) *******/
|
|
{
|
|
bundleTypes: [
|
|
UMD_DEV,
|
|
UMD_PROD,
|
|
NODE_DEV,
|
|
NODE_PROD,
|
|
FB_WWW_DEV,
|
|
FB_WWW_PROD,
|
|
RN_FB_DEV,
|
|
RN_FB_PROD,
|
|
],
|
|
moduleType: ISOMORPHIC,
|
|
entry: 'scheduler/unstable_mock',
|
|
global: 'SchedulerMock',
|
|
externals: [],
|
|
},
|
|
|
|
/******* React Scheduler Post Task (experimental) *******/
|
|
{
|
|
bundleTypes: [
|
|
NODE_DEV,
|
|
NODE_PROD,
|
|
FB_WWW_DEV,
|
|
FB_WWW_PROD,
|
|
FB_WWW_PROFILING,
|
|
],
|
|
moduleType: ISOMORPHIC,
|
|
entry: 'scheduler/unstable_post_task',
|
|
global: 'SchedulerPostTask',
|
|
externals: [],
|
|
},
|
|
|
|
/******* React Scheduler Post Task Only (experimental) *******/
|
|
{
|
|
bundleTypes: [
|
|
NODE_DEV,
|
|
NODE_PROD,
|
|
FB_WWW_DEV,
|
|
FB_WWW_PROD,
|
|
FB_WWW_PROFILING,
|
|
],
|
|
moduleType: ISOMORPHIC,
|
|
entry: 'scheduler/unstable_post_task_only',
|
|
global: 'SchedulerPostTaskOnly',
|
|
externals: [],
|
|
},
|
|
|
|
/******* React Scheduler No DOM (experimental) *******/
|
|
{
|
|
bundleTypes: [
|
|
NODE_DEV,
|
|
NODE_PROD,
|
|
FB_WWW_DEV,
|
|
FB_WWW_PROD,
|
|
FB_WWW_PROFILING,
|
|
RN_FB_DEV,
|
|
RN_FB_PROD,
|
|
RN_FB_PROFILING,
|
|
],
|
|
moduleType: ISOMORPHIC,
|
|
entry: 'scheduler/unstable_no_dom',
|
|
global: 'SchedulerNoDOM',
|
|
externals: [],
|
|
},
|
|
|
|
/******* Jest React (experimental) *******/
|
|
{
|
|
bundleTypes: [NODE_DEV, NODE_PROD],
|
|
moduleType: ISOMORPHIC,
|
|
entry: 'jest-react',
|
|
global: 'JestReact',
|
|
externals: [],
|
|
},
|
|
|
|
/******* ESLint Plugin for Hooks *******/
|
|
{
|
|
// TODO: it's awkward to create a bundle for this but if we don't, the package
|
|
// won't get copied. We also can't create just DEV bundle because it contains a
|
|
// NODE_ENV check inside. We should probably tweak our build process to allow
|
|
// "raw" packages that don't get bundled.
|
|
bundleTypes: [NODE_DEV, NODE_PROD],
|
|
moduleType: ISOMORPHIC,
|
|
entry: 'eslint-plugin-react-hooks',
|
|
global: 'ESLintPluginReactHooks',
|
|
externals: [],
|
|
},
|
|
|
|
/******* React Fresh *******/
|
|
{
|
|
bundleTypes: [NODE_DEV, NODE_PROD],
|
|
moduleType: ISOMORPHIC,
|
|
entry: 'react-refresh/babel',
|
|
global: 'ReactFreshBabelPlugin',
|
|
externals: [],
|
|
},
|
|
{
|
|
bundleTypes: [NODE_DEV, NODE_PROD, FB_WWW_DEV],
|
|
moduleType: ISOMORPHIC,
|
|
entry: 'react-refresh/runtime',
|
|
global: 'ReactFreshRuntime',
|
|
externals: [],
|
|
},
|
|
|
|
{
|
|
bundleTypes: [
|
|
FB_WWW_DEV,
|
|
FB_WWW_PROD,
|
|
FB_WWW_PROFILING,
|
|
NODE_DEV,
|
|
NODE_PROD,
|
|
NODE_PROFILING,
|
|
RN_FB_DEV,
|
|
RN_FB_PROD,
|
|
RN_FB_PROFILING,
|
|
],
|
|
moduleType: ISOMORPHIC,
|
|
entry: 'scheduler/tracing',
|
|
global: 'SchedulerTracing',
|
|
externals: [],
|
|
},
|
|
];
|
|
|
|
// Based on deep-freeze by substack (public domain)
|
|
function deepFreeze(o) {
|
|
Object.freeze(o);
|
|
Object.getOwnPropertyNames(o).forEach(function(prop) {
|
|
if (
|
|
o[prop] !== null &&
|
|
(typeof o[prop] === 'object' || typeof o[prop] === 'function') &&
|
|
!Object.isFrozen(o[prop])
|
|
) {
|
|
deepFreeze(o[prop]);
|
|
}
|
|
});
|
|
return o;
|
|
}
|
|
|
|
// Don't accidentally mutate config as part of the build
|
|
deepFreeze(bundles);
|
|
deepFreeze(bundleTypes);
|
|
deepFreeze(moduleTypes);
|
|
|
|
function getFilename(bundle, bundleType) {
|
|
let name = bundle.entry;
|
|
const globalName = bundle.global;
|
|
// we do this to replace / to -, for react-dom/server
|
|
name = name.replace('/index.', '.').replace('/', '-');
|
|
switch (bundleType) {
|
|
case NODE_ES2015:
|
|
return `${name}.js`;
|
|
case NODE_ESM:
|
|
return `${name}.js`;
|
|
case UMD_DEV:
|
|
return `${name}.development.js`;
|
|
case UMD_PROD:
|
|
return `${name}.production.min.js`;
|
|
case UMD_PROFILING:
|
|
return `${name}.profiling.min.js`;
|
|
case NODE_DEV:
|
|
return `${name}.development.js`;
|
|
case NODE_PROD:
|
|
return `${name}.production.min.js`;
|
|
case NODE_PROFILING:
|
|
return `${name}.profiling.min.js`;
|
|
case FB_WWW_DEV:
|
|
case RN_OSS_DEV:
|
|
case RN_FB_DEV:
|
|
return `${globalName}-dev.js`;
|
|
case FB_WWW_PROD:
|
|
case RN_OSS_PROD:
|
|
case RN_FB_PROD:
|
|
return `${globalName}-prod.js`;
|
|
case FB_WWW_PROFILING:
|
|
case RN_FB_PROFILING:
|
|
case RN_OSS_PROFILING:
|
|
return `${globalName}-profiling.js`;
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
bundleTypes,
|
|
moduleTypes,
|
|
bundles,
|
|
getFilename,
|
|
};
|