Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 76f157e

Browse files
authored
Add simple Node build (facebook#19022)
The webpack plugin doesn't really need a separate prod and dev build. It also needs to be ES2015 otherwise we can't extend native classes.
1 parent 60afa3c commit 76f157e

File tree

7 files changed

+89
-17
lines changed

7 files changed

+89
-17
lines changed
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
'use strict';
22

3-
if (process.env.NODE_ENV === 'production') {
4-
module.exports = require('./cjs/react-transport-dom-webpack-plugin.production.min.js');
5-
} else {
6-
module.exports = require('./cjs/react-transport-dom-webpack-plugin.development.js');
7-
}
3+
module.exports = require('./cjs/react-transport-dom-webpack-plugin.js');

scripts/rollup/build.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ process.on('unhandledRejection', err => {
4545
});
4646

4747
const {
48+
NODE_ES2015,
4849
UMD_DEV,
4950
UMD_PROD,
5051
UMD_PROFILING,
@@ -244,6 +245,7 @@ function getFormat(bundleType) {
244245
case UMD_PROD:
245246
case UMD_PROFILING:
246247
return `umd`;
248+
case NODE_ES2015:
247249
case NODE_DEV:
248250
case NODE_PROD:
249251
case NODE_PROFILING:
@@ -262,6 +264,7 @@ function getFormat(bundleType) {
262264

263265
function isProductionBundleType(bundleType) {
264266
switch (bundleType) {
267+
case NODE_ES2015:
265268
case UMD_DEV:
266269
case NODE_DEV:
267270
case FB_WWW_DEV:
@@ -286,6 +289,7 @@ function isProductionBundleType(bundleType) {
286289

287290
function isProfilingBundleType(bundleType) {
288291
switch (bundleType) {
292+
case NODE_ES2015:
289293
case FB_WWW_DEV:
290294
case FB_WWW_PROD:
291295
case NODE_DEV:
@@ -725,6 +729,7 @@ async function buildEverything() {
725729
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
726730
for (const bundle of Bundles.bundles) {
727731
bundles.push(
732+
[bundle, NODE_ES2015],
728733
[bundle, UMD_DEV],
729734
[bundle, UMD_PROD],
730735
[bundle, UMD_PROFILING],

scripts/rollup/bundles.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const __EXPERIMENTAL__ =
88
: true;
99

1010
const bundleTypes = {
11+
NODE_ES2015: 'NODE_ES2015',
1112
UMD_DEV: 'UMD_DEV',
1213
UMD_PROD: 'UMD_PROD',
1314
UMD_PROFILING: 'UMD_PROFILING',
@@ -26,6 +27,7 @@ const bundleTypes = {
2627
};
2728

2829
const {
30+
NODE_ES2015,
2931
UMD_DEV,
3032
UMD_PROD,
3133
UMD_PROFILING,
@@ -280,22 +282,11 @@ const bundles = [
280282

281283
/******* React Transport DOM Webpack Plugin *******/
282284
{
283-
bundleTypes: [NODE_DEV, NODE_PROD],
285+
bundleTypes: [NODE_ES2015],
284286
moduleType: RENDERER_UTILS,
285287
entry: 'react-transport-dom-webpack/plugin',
286288
global: 'ReactFlightWebpackPlugin',
287289
externals: [],
288-
babel: opts =>
289-
Object.assign({}, opts, {
290-
// Include JSX
291-
presets: opts.presets.concat([
292-
require.resolve('@babel/preset-react'),
293-
require.resolve('@babel/preset-flow'),
294-
]),
295-
plugins: opts.plugins.concat([
296-
[require.resolve('@babel/plugin-transform-classes'), {loose: true}],
297-
]),
298-
}),
299290
},
300291

301292
/******* React Transport DOM Server Relay *******/
@@ -803,6 +794,8 @@ function getFilename(bundle, bundleType) {
803794
// we do this to replace / to -, for react-dom/server
804795
name = name.replace('/index.', '.').replace('/', '-');
805796
switch (bundleType) {
797+
case NODE_ES2015:
798+
return `${name}.js`;
806799
case UMD_DEV:
807800
return `${name}.development.js`;
808801
case UMD_PROD:

scripts/rollup/packaging.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const {
1616
} = require('./utils');
1717

1818
const {
19+
NODE_ES2015,
1920
UMD_DEV,
2021
UMD_PROD,
2122
UMD_PROFILING,
@@ -42,6 +43,8 @@ function getPackageName(name) {
4243

4344
function getBundleOutputPath(bundleType, filename, packageName) {
4445
switch (bundleType) {
46+
case NODE_ES2015:
47+
return `build/node_modules/${packageName}/cjs/${filename}`;
4548
case NODE_DEV:
4649
case NODE_PROD:
4750
case NODE_PROFILING:
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
'use strict';
2+
3+
module.exports = {
4+
env: {
5+
commonjs: true,
6+
browser: true,
7+
},
8+
globals: {
9+
// ES 6
10+
Map: true,
11+
Set: true,
12+
Proxy: true,
13+
Symbol: true,
14+
WeakMap: true,
15+
WeakSet: true,
16+
Uint16Array: true,
17+
Reflect: true,
18+
// Vendor specific
19+
MSApp: true,
20+
__REACT_DEVTOOLS_GLOBAL_HOOK__: true,
21+
// CommonJS / Node
22+
process: true,
23+
setImmediate: true,
24+
Buffer: true,
25+
// Trusted Types
26+
trustedTypes: true,
27+
28+
// Scheduler profiling
29+
SharedArrayBuffer: true,
30+
Int32Array: true,
31+
ArrayBuffer: true,
32+
33+
// Flight
34+
Uint8Array: true,
35+
Promise: true,
36+
37+
// Flight Webpack
38+
__webpack_chunk_load__: true,
39+
__webpack_require__: true,
40+
41+
// jest
42+
expect: true,
43+
},
44+
parserOptions: {
45+
ecmaVersion: 2015,
46+
sourceType: 'script',
47+
},
48+
rules: {
49+
'no-undef': 'error',
50+
'no-shadow-restricted-names': 'error',
51+
},
52+
53+
// These plugins aren't used, but eslint complains if an eslint-ignore comment
54+
// references unused plugins. An alternate approach could be to strip
55+
// eslint-ignore comments as part of the build.
56+
plugins: ['jest', 'no-for-of-loops', 'react', 'react-internal'],
57+
};

scripts/rollup/validate/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const {bundles, getFilename, bundleTypes} = require('../bundles');
88
const Packaging = require('../packaging');
99

1010
const {
11+
NODE_ES2015,
1112
UMD_DEV,
1213
UMD_PROD,
1314
UMD_PROFILING,
@@ -31,6 +32,8 @@ function getFormat(bundleType) {
3132
case UMD_PROD:
3233
case UMD_PROFILING:
3334
return 'umd';
35+
case NODE_ES2015:
36+
return 'cjs2015';
3437
case NODE_DEV:
3538
case NODE_PROD:
3639
case NODE_PROFILING:
@@ -60,6 +63,7 @@ function getESLintInstance(format) {
6063

6164
const esLints = {
6265
cjs: getESLintInstance('cjs'),
66+
cjs2015: getESLintInstance('cjs2015'),
6367
rn: getESLintInstance('rn'),
6468
fb: getESLintInstance('fb'),
6569
umd: getESLintInstance('umd'),

scripts/rollup/wrappers.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const {bundleTypes, moduleTypes} = require('./bundles');
44
const reactVersion = require('../../package.json').version;
55

66
const {
7+
NODE_ES2015,
78
UMD_DEV,
89
UMD_PROD,
910
UMD_PROFILING,
@@ -29,6 +30,19 @@ const license = ` * Copyright (c) Facebook, Inc. and its affiliates.
2930
* LICENSE file in the root directory of this source tree.`;
3031

3132
const wrappers = {
33+
/***************** NODE_ES2015 *****************/
34+
[NODE_ES2015](source, globalName, filename, moduleType) {
35+
return `/** @license React v${reactVersion}
36+
* ${filename}
37+
*
38+
${license}
39+
*/
40+
41+
'use strict';
42+
43+
${source}`;
44+
},
45+
3246
/***************** UMD_DEV *****************/
3347
[UMD_DEV](source, globalName, filename, moduleType) {
3448
return `/** @license React v${reactVersion}

0 commit comments

Comments
 (0)