Reduce babel junk in built files

Configure babel preset-env to match the documentation's browser support
list.
This commit is contained in:
Nicolas Gallagher
2022-07-05 11:26:31 -07:00
parent 1aa84d5447
commit e027829cdb
5 changed files with 106 additions and 96 deletions
+3 -7
View File
@@ -99,17 +99,13 @@ Please open an issue with a proposal for a new feature or refactoring before sta
3. If you've changed APIs, update the documentation. 3. If you've changed APIs, update the documentation.
4. Ensure the tests pass (`npm run test`). 4. Ensure the tests pass (`npm run test`).
You should see a pre-commit hook run before each commit. If it does not, you may need to reset you Git hookspath: You should see a pre-commit hook run before each commit.
```
git config --unset core.hookspath
```
You can now submit a pull request, referencing any issues it addresses. You can now submit a pull request, referencing any issues it addresses.
Please try to keep your pull request focused in scope and avoid including unrelated commits. Please try to keep your pull request focused in scope and avoid including unrelated commits.
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. 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.
Thank you for contributing! Thank you for contributing!
@@ -118,7 +114,7 @@ Thank you for contributing!
To commit, publish, and push a final version: To commit, publish, and push a final version:
``` ```
npm run release -- <version> npm run release -- <version> --opt=<opt-code>
``` ```
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: 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:
+36 -34
View File
@@ -1,15 +1,22 @@
module.exports = function (api) { const createConfig = ({ modules }) => {
if (api) { const plugins = [
api.cache(true); '@babel/plugin-transform-flow-strip-types',
} ['@babel/plugin-proposal-class-properties', { loose: true }],
['@babel/plugin-proposal-object-rest-spread', { useBuiltIns: true }],
let modules = false; '@babel/plugin-proposal-nullish-coalescing-operator',
[
if (process.env.BABEL_ENV === 'commonjs' || process.env.NODE_ENV === 'test') { '@babel/plugin-transform-runtime',
modules = 'commonjs'; {
} version: '7.18.6'
}
]
].concat(modules ? ['babel-plugin-add-module-exports'] : []);
return { return {
assumptions: {
iterableIsArray: true
},
comments: true,
presets: [ presets: [
[ [
'@babel/preset-env', '@babel/preset-env',
@@ -19,18 +26,14 @@ module.exports = function (api) {
exclude: ['transform-typeof-symbol'], exclude: ['transform-typeof-symbol'],
targets: { targets: {
browsers: [ browsers: [
'chrome 38', 'chrome 49',
'android 4', // https://www.mozilla.org/en-US/firefox/all/#product-desktop-esr
'firefox 40', 'firefox 91',
'ios_saf 7', 'ios_saf 10',
'safari 7', 'safari 10',
'ie 10', // https://docs.microsoft.com/en-us/DeployEdge/microsoft-edge-support-lifecycle
'ie_mob 11', 'edge 94',
'edge 12', 'opera 36'
'opera 16',
'op_mini 12',
'and_uc 9',
'and_chr 38'
] ]
} }
} }
@@ -38,17 +41,16 @@ module.exports = function (api) {
'@babel/preset-react', '@babel/preset-react',
'@babel/preset-flow' '@babel/preset-flow'
], ],
plugins: [ plugins: plugins
'@babel/plugin-transform-flow-strip-types',
['@babel/plugin-proposal-class-properties', { loose: true }],
['@babel/plugin-proposal-object-rest-spread', { useBuiltIns: true }],
'@babel/plugin-proposal-nullish-coalescing-operator',
[
'@babel/plugin-transform-runtime',
{
version: '7.18.6'
}
]
].concat(modules ? ['babel-plugin-add-module-exports'] : [])
}; };
}; };
module.exports = function (api) {
if (api) {
api.cache(true);
}
return process.env.BABEL_ENV === 'commonjs' || process.env.NODE_ENV === 'test'
? createConfig({ modules: 'commonjs' })
: createConfig({ modules: false });
};
+16 -13
View File
@@ -23,19 +23,22 @@ import StyleSheet from '../StyleSheet';
import TextAncestorContext from './TextAncestorContext'; import TextAncestorContext from './TextAncestorContext';
import { useLocaleContext, getLocaleDirection } from '../../modules/useLocale'; import { useLocaleContext, getLocaleDirection } from '../../modules/useLocale';
const forwardPropsList = { const forwardPropsList = Object.assign(
...forwardedProps.defaultProps, {},
...forwardedProps.accessibilityProps, forwardedProps.defaultProps,
...forwardedProps.clickProps, forwardedProps.accessibilityProps,
...forwardedProps.focusProps, forwardedProps.clickProps,
...forwardedProps.keyboardProps, forwardedProps.focusProps,
...forwardedProps.mouseProps, forwardedProps.keyboardProps,
...forwardedProps.touchProps, forwardedProps.mouseProps,
...forwardedProps.styleProps, forwardedProps.touchProps,
href: true, forwardedProps.styleProps,
lang: true, {
pointerEvents: true href: true,
}; lang: true,
pointerEvents: true
}
);
const pickProps = (props) => pick(props, forwardPropsList); const pickProps = (props) => pick(props, forwardPropsList);
+30 -27
View File
@@ -47,33 +47,36 @@ const setSelection = (node, selection) => {
} }
}; };
const forwardPropsList = { const forwardPropsList = Object.assign(
...forwardedProps.defaultProps, {},
...forwardedProps.accessibilityProps, forwardedProps.defaultProps,
...forwardedProps.clickProps, forwardedProps.accessibilityProps,
...forwardedProps.focusProps, forwardedProps.clickProps,
...forwardedProps.keyboardProps, forwardedProps.focusProps,
...forwardedProps.mouseProps, forwardedProps.keyboardProps,
...forwardedProps.touchProps, forwardedProps.mouseProps,
...forwardedProps.styleProps, forwardedProps.touchProps,
autoCapitalize: true, forwardedProps.styleProps,
autoComplete: true, {
autoCorrect: true, autoCapitalize: true,
autoFocus: true, autoComplete: true,
defaultValue: true, autoCorrect: true,
disabled: true, autoFocus: true,
lang: true, defaultValue: true,
maxLength: true, disabled: true,
onChange: true, lang: true,
onScroll: true, maxLength: true,
placeholder: true, onChange: true,
pointerEvents: true, onScroll: true,
readOnly: true, placeholder: true,
rows: true, pointerEvents: true,
spellCheck: true, readOnly: true,
value: true, rows: true,
type: true spellCheck: true,
}; value: true,
type: true
}
);
const pickProps = (props) => pick(props, forwardPropsList); const pickProps = (props) => pick(props, forwardPropsList);
+21 -15
View File
@@ -23,21 +23,27 @@ import StyleSheet from '../StyleSheet';
import TextAncestorContext from '../Text/TextAncestorContext'; import TextAncestorContext from '../Text/TextAncestorContext';
import { useLocaleContext, getLocaleDirection } from '../../modules/useLocale'; import { useLocaleContext, getLocaleDirection } from '../../modules/useLocale';
const forwardPropsList = { const forwardPropsList = Object.assign(
...forwardedProps.defaultProps, {},
...forwardedProps.accessibilityProps, forwardedProps.defaultProps,
...forwardedProps.clickProps, forwardedProps.accessibilityProps,
...forwardedProps.focusProps, forwardedProps.clickProps,
...forwardedProps.keyboardProps, forwardedProps.defaultProps,
...forwardedProps.mouseProps, forwardedProps.accessibilityProps,
...forwardedProps.touchProps, forwardedProps.clickProps,
...forwardedProps.styleProps, forwardedProps.focusProps,
href: true, forwardedProps.keyboardProps,
lang: true, forwardedProps.mouseProps,
onScroll: true, forwardedProps.touchProps,
onWheel: true, forwardedProps.styleProps,
pointerEvents: true {
}; href: true,
lang: true,
onScroll: true,
onWheel: true,
pointerEvents: true
}
);
const pickProps = (props) => pick(props, forwardPropsList); const pickProps = (props) => pick(props, forwardPropsList);