mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-01 10:07:35 +00:00
Reduce babel junk in built files
Configure babel preset-env to match the documentation's browser support list.
This commit is contained in:
+36
-34
@@ -1,15 +1,22 @@
|
||||
module.exports = function (api) {
|
||||
if (api) {
|
||||
api.cache(true);
|
||||
}
|
||||
|
||||
let modules = false;
|
||||
|
||||
if (process.env.BABEL_ENV === 'commonjs' || process.env.NODE_ENV === 'test') {
|
||||
modules = 'commonjs';
|
||||
}
|
||||
const createConfig = ({ modules }) => {
|
||||
const 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'] : []);
|
||||
|
||||
return {
|
||||
assumptions: {
|
||||
iterableIsArray: true
|
||||
},
|
||||
comments: true,
|
||||
presets: [
|
||||
[
|
||||
'@babel/preset-env',
|
||||
@@ -19,18 +26,14 @@ module.exports = function (api) {
|
||||
exclude: ['transform-typeof-symbol'],
|
||||
targets: {
|
||||
browsers: [
|
||||
'chrome 38',
|
||||
'android 4',
|
||||
'firefox 40',
|
||||
'ios_saf 7',
|
||||
'safari 7',
|
||||
'ie 10',
|
||||
'ie_mob 11',
|
||||
'edge 12',
|
||||
'opera 16',
|
||||
'op_mini 12',
|
||||
'and_uc 9',
|
||||
'and_chr 38'
|
||||
'chrome 49',
|
||||
// https://www.mozilla.org/en-US/firefox/all/#product-desktop-esr
|
||||
'firefox 91',
|
||||
'ios_saf 10',
|
||||
'safari 10',
|
||||
// https://docs.microsoft.com/en-us/DeployEdge/microsoft-edge-support-lifecycle
|
||||
'edge 94',
|
||||
'opera 36'
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -38,17 +41,16 @@ module.exports = function (api) {
|
||||
'@babel/preset-react',
|
||||
'@babel/preset-flow'
|
||||
],
|
||||
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'] : [])
|
||||
plugins: plugins
|
||||
};
|
||||
};
|
||||
|
||||
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 });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user