Add simple Node build (#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.
Sebastian Markbåge committed
May 28, 2020 at 15:56 UTC
76f157e3dd18d0501b4ed083e54b444ce11d232f
7 files changed
+89
-17
packages/react-transport-dom-webpack/npm/plugin.js
+1
-5
@@ -1,7 +1,3 @@
1
'use strict';
2
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
+5
@@ -45,6 +45,7 @@ process.on('unhandledRejection', err => {
45
});
46
47
const {
48
+ NODE_ES2015,
49
UMD_DEV,
50
UMD_PROD,
51
UMD_PROFILING,
@@ -244,6 +245,7 @@ function getFormat(bundleType) {
245
case UMD_PROD:
246
case UMD_PROFILING:
247
return `umd`;
248
+ case NODE_ES2015:
249
case NODE_DEV:
250
case NODE_PROD:
251
case NODE_PROFILING:
@@ -262,6 +264,7 @@ function getFormat(bundleType) {
264
265
function isProductionBundleType(bundleType) {
266
switch (bundleType) {
267
+ case NODE_ES2015:
268
case UMD_DEV:
269
case NODE_DEV:
270
case FB_WWW_DEV:
@@ -286,6 +289,7 @@ function isProductionBundleType(bundleType) {
289
290
function isProfilingBundleType(bundleType) {
291
switch (bundleType) {
292
+ case NODE_ES2015:
293
case FB_WWW_DEV:
294
case FB_WWW_PROD:
295
case NODE_DEV:
@@ -725,6 +729,7 @@ async function buildEverything() {
729
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
730
for (const bundle of Bundles.bundles) {
731
bundles.push(
732
+ [bundle, NODE_ES2015],
733
[bundle, UMD_DEV],
734
[bundle, UMD_PROD],
735
[bundle, UMD_PROFILING],
scripts/rollup/bundles.js
+5
-12
@@ -8,6 +8,7 @@ const __EXPERIMENTAL__ =
8
: true;
9
10
const bundleTypes = {
11
+ NODE_ES2015: 'NODE_ES2015',
12
UMD_DEV: 'UMD_DEV',
13
UMD_PROD: 'UMD_PROD',
14
UMD_PROFILING: 'UMD_PROFILING',
@@ -26,6 +27,7 @@ const bundleTypes = {
27
};
28
29
const {
30
+ NODE_ES2015,
31
UMD_DEV,
32
UMD_PROD,
33
UMD_PROFILING,
@@ -280,22 +282,11 @@ const bundles = [
282
283
/******* React Transport DOM Webpack Plugin *******/
284
{
283
- bundleTypes: [NODE_DEV, NODE_PROD],
285
+ bundleTypes: [NODE_ES2015],
286
moduleType: RENDERER_UTILS,
287
entry: 'react-transport-dom-webpack/plugin',
288
global: 'ReactFlightWebpackPlugin',
289
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
- }),
290
},
291
292
/******* React Transport DOM Server Relay *******/
@@ -803,6 +794,8 @@ function getFilename(bundle, bundleType) {
794
// we do this to replace / to -, for react-dom/server
795
name = name.replace('/index.', '.').replace('/', '-');
796
switch (bundleType) {
797
+ case NODE_ES2015:
798
+ return `${name}.js`;
799
case UMD_DEV:
800
return `${name}.development.js`;
801
case UMD_PROD:
scripts/rollup/packaging.js
+3
@@ -16,6 +16,7 @@ const {
16
} = require('./utils');
17
18
const {
19
+ NODE_ES2015,
20
UMD_DEV,
21
UMD_PROD,
22
UMD_PROFILING,
@@ -42,6 +43,8 @@ function getPackageName(name) {
43
44
function getBundleOutputPath(bundleType, filename, packageName) {
45
switch (bundleType) {
46
+ case NODE_ES2015:
47
+ return `build/node_modules/${packageName}/cjs/${filename}`;
48
case NODE_DEV:
49
case NODE_PROD:
50
case NODE_PROFILING:
scripts/rollup/validate/eslintrc.cjs2015.js
new
+57
@@ -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
+4
@@ -8,6 +8,7 @@ const {bundles, getFilename, bundleTypes} = require('../bundles');
8
const Packaging = require('../packaging');
9
10
const {
11
+ NODE_ES2015,
12
UMD_DEV,
13
UMD_PROD,
14
UMD_PROFILING,
@@ -31,6 +32,8 @@ function getFormat(bundleType) {
32
case UMD_PROD:
33
case UMD_PROFILING:
34
return 'umd';
35
+ case NODE_ES2015:
36
+ return 'cjs2015';
37
case NODE_DEV:
38
case NODE_PROD:
39
case NODE_PROFILING:
@@ -60,6 +63,7 @@ function getESLintInstance(format) {
63
64
const esLints = {
65
cjs: getESLintInstance('cjs'),
66
+ cjs2015: getESLintInstance('cjs2015'),
67
rn: getESLintInstance('rn'),
68
fb: getESLintInstance('fb'),
69
umd: getESLintInstance('umd'),
scripts/rollup/wrappers.js
+14
@@ -4,6 +4,7 @@ const {bundleTypes, moduleTypes} = require('./bundles');
4
const reactVersion = require('../../package.json').version;
5
6
const {
7
+ NODE_ES2015,
8
UMD_DEV,
9
UMD_PROD,
10
UMD_PROFILING,
@@ -29,6 +30,19 @@ const license = ` * Copyright (c) Facebook, Inc. and its affiliates.
30
* LICENSE file in the root directory of this source tree.`;
31
32
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
+
46
/***************** UMD_DEV *****************/
47
[UMD_DEV](source, globalName, filename, moduleType) {
48
return `/** @license React v${reactVersion}