Skip to content

Commit e027829

Browse files
committed
Reduce babel junk in built files
Configure babel preset-env to match the documentation's browser support list.
1 parent 1aa84d5 commit e027829

File tree

5 files changed

+106
-96
lines changed

5 files changed

+106
-96
lines changed

.github/CONTRIBUTING.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,13 @@ Please open an issue with a proposal for a new feature or refactoring before sta
9999
3. If you've changed APIs, update the documentation.
100100
4. Ensure the tests pass (`npm run test`).
101101

102-
You should see a pre-commit hook run before each commit. If it does not, you may need to reset you Git hookspath:
103-
104-
```
105-
git config --unset core.hookspath
106-
```
102+
You should see a pre-commit hook run before each commit.
107103

108104
You can now submit a pull request, referencing any issues it addresses.
109105

110106
Please try to keep your pull request focused in scope and avoid including unrelated commits.
111107

112-
After you have submitted your pull request, we'll try to get back to you as soon as possible. We may suggest some changes or improvements.
108+
After you have submitted your pull request, it's recommended that **you** perform the first code review. We'll try to get back to you as soon as possible and may suggest changes.
113109

114110
Thank you for contributing!
115111

@@ -118,7 +114,7 @@ Thank you for contributing!
118114
To commit, publish, and push a final version:
119115

120116
```
121-
npm run release -- <version>
117+
npm run release -- <version> --opt=<opt-code>
122118
```
123119

124120
Release candidates or versions that you'd like to publish to npm, but do not want to produce a commit and push it to GitHub:

configs/babel.config.js

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
module.exports = function (api) {
2-
if (api) {
3-
api.cache(true);
4-
}
5-
6-
let modules = false;
7-
8-
if (process.env.BABEL_ENV === 'commonjs' || process.env.NODE_ENV === 'test') {
9-
modules = 'commonjs';
10-
}
1+
const createConfig = ({ modules }) => {
2+
const plugins = [
3+
'@babel/plugin-transform-flow-strip-types',
4+
['@babel/plugin-proposal-class-properties', { loose: true }],
5+
['@babel/plugin-proposal-object-rest-spread', { useBuiltIns: true }],
6+
'@babel/plugin-proposal-nullish-coalescing-operator',
7+
[
8+
'@babel/plugin-transform-runtime',
9+
{
10+
version: '7.18.6'
11+
}
12+
]
13+
].concat(modules ? ['babel-plugin-add-module-exports'] : []);
1114

1215
return {
16+
assumptions: {
17+
iterableIsArray: true
18+
},
19+
comments: true,
1320
presets: [
1421
[
1522
'@babel/preset-env',
@@ -19,36 +26,31 @@ module.exports = function (api) {
1926
exclude: ['transform-typeof-symbol'],
2027
targets: {
2128
browsers: [
22-
'chrome 38',
23-
'android 4',
24-
'firefox 40',
25-
'ios_saf 7',
26-
'safari 7',
27-
'ie 10',
28-
'ie_mob 11',
29-
'edge 12',
30-
'opera 16',
31-
'op_mini 12',
32-
'and_uc 9',
33-
'and_chr 38'
29+
'chrome 49',
30+
// https://www.mozilla.org/en-US/firefox/all/#product-desktop-esr
31+
'firefox 91',
32+
'ios_saf 10',
33+
'safari 10',
34+
// https://docs.microsoft.com/en-us/DeployEdge/microsoft-edge-support-lifecycle
35+
'edge 94',
36+
'opera 36'
3437
]
3538
}
3639
}
3740
],
3841
'@babel/preset-react',
3942
'@babel/preset-flow'
4043
],
41-
plugins: [
42-
'@babel/plugin-transform-flow-strip-types',
43-
['@babel/plugin-proposal-class-properties', { loose: true }],
44-
['@babel/plugin-proposal-object-rest-spread', { useBuiltIns: true }],
45-
'@babel/plugin-proposal-nullish-coalescing-operator',
46-
[
47-
'@babel/plugin-transform-runtime',
48-
{
49-
version: '7.18.6'
50-
}
51-
]
52-
].concat(modules ? ['babel-plugin-add-module-exports'] : [])
44+
plugins: plugins
5345
};
5446
};
47+
48+
module.exports = function (api) {
49+
if (api) {
50+
api.cache(true);
51+
}
52+
53+
return process.env.BABEL_ENV === 'commonjs' || process.env.NODE_ENV === 'test'
54+
? createConfig({ modules: 'commonjs' })
55+
: createConfig({ modules: false });
56+
};

packages/react-native-web/src/exports/Text/index.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,22 @@ import StyleSheet from '../StyleSheet';
2323
import TextAncestorContext from './TextAncestorContext';
2424
import { useLocaleContext, getLocaleDirection } from '../../modules/useLocale';
2525

26-
const forwardPropsList = {
27-
...forwardedProps.defaultProps,
28-
...forwardedProps.accessibilityProps,
29-
...forwardedProps.clickProps,
30-
...forwardedProps.focusProps,
31-
...forwardedProps.keyboardProps,
32-
...forwardedProps.mouseProps,
33-
...forwardedProps.touchProps,
34-
...forwardedProps.styleProps,
35-
href: true,
36-
lang: true,
37-
pointerEvents: true
38-
};
26+
const forwardPropsList = Object.assign(
27+
{},
28+
forwardedProps.defaultProps,
29+
forwardedProps.accessibilityProps,
30+
forwardedProps.clickProps,
31+
forwardedProps.focusProps,
32+
forwardedProps.keyboardProps,
33+
forwardedProps.mouseProps,
34+
forwardedProps.touchProps,
35+
forwardedProps.styleProps,
36+
{
37+
href: true,
38+
lang: true,
39+
pointerEvents: true
40+
}
41+
);
3942

4043
const pickProps = (props) => pick(props, forwardPropsList);
4144

packages/react-native-web/src/exports/TextInput/index.js

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,33 +47,36 @@ const setSelection = (node, selection) => {
4747
}
4848
};
4949

50-
const forwardPropsList = {
51-
...forwardedProps.defaultProps,
52-
...forwardedProps.accessibilityProps,
53-
...forwardedProps.clickProps,
54-
...forwardedProps.focusProps,
55-
...forwardedProps.keyboardProps,
56-
...forwardedProps.mouseProps,
57-
...forwardedProps.touchProps,
58-
...forwardedProps.styleProps,
59-
autoCapitalize: true,
60-
autoComplete: true,
61-
autoCorrect: true,
62-
autoFocus: true,
63-
defaultValue: true,
64-
disabled: true,
65-
lang: true,
66-
maxLength: true,
67-
onChange: true,
68-
onScroll: true,
69-
placeholder: true,
70-
pointerEvents: true,
71-
readOnly: true,
72-
rows: true,
73-
spellCheck: true,
74-
value: true,
75-
type: true
76-
};
50+
const forwardPropsList = Object.assign(
51+
{},
52+
forwardedProps.defaultProps,
53+
forwardedProps.accessibilityProps,
54+
forwardedProps.clickProps,
55+
forwardedProps.focusProps,
56+
forwardedProps.keyboardProps,
57+
forwardedProps.mouseProps,
58+
forwardedProps.touchProps,
59+
forwardedProps.styleProps,
60+
{
61+
autoCapitalize: true,
62+
autoComplete: true,
63+
autoCorrect: true,
64+
autoFocus: true,
65+
defaultValue: true,
66+
disabled: true,
67+
lang: true,
68+
maxLength: true,
69+
onChange: true,
70+
onScroll: true,
71+
placeholder: true,
72+
pointerEvents: true,
73+
readOnly: true,
74+
rows: true,
75+
spellCheck: true,
76+
value: true,
77+
type: true
78+
}
79+
);
7780

7881
const pickProps = (props) => pick(props, forwardPropsList);
7982

packages/react-native-web/src/exports/View/index.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,27 @@ import StyleSheet from '../StyleSheet';
2323
import TextAncestorContext from '../Text/TextAncestorContext';
2424
import { useLocaleContext, getLocaleDirection } from '../../modules/useLocale';
2525

26-
const forwardPropsList = {
27-
...forwardedProps.defaultProps,
28-
...forwardedProps.accessibilityProps,
29-
...forwardedProps.clickProps,
30-
...forwardedProps.focusProps,
31-
...forwardedProps.keyboardProps,
32-
...forwardedProps.mouseProps,
33-
...forwardedProps.touchProps,
34-
...forwardedProps.styleProps,
35-
href: true,
36-
lang: true,
37-
onScroll: true,
38-
onWheel: true,
39-
pointerEvents: true
40-
};
26+
const forwardPropsList = Object.assign(
27+
{},
28+
forwardedProps.defaultProps,
29+
forwardedProps.accessibilityProps,
30+
forwardedProps.clickProps,
31+
forwardedProps.defaultProps,
32+
forwardedProps.accessibilityProps,
33+
forwardedProps.clickProps,
34+
forwardedProps.focusProps,
35+
forwardedProps.keyboardProps,
36+
forwardedProps.mouseProps,
37+
forwardedProps.touchProps,
38+
forwardedProps.styleProps,
39+
{
40+
href: true,
41+
lang: true,
42+
onScroll: true,
43+
onWheel: true,
44+
pointerEvents: true
45+
}
46+
);
4147

4248
const pickProps = (props) => pick(props, forwardPropsList);
4349

0 commit comments

Comments
 (0)