babel-preset-expo 0.0.1-canary-20231205-250b31f → 0.0.1-canary-20240222-c729a13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -13
- package/build/index.js +8 -10
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# babel-preset-expo
|
|
2
2
|
|
|
3
|
-
This preset extends the default React Native preset (
|
|
3
|
+
This preset extends the default React Native preset (`@react-native/babel-preset`) and adds support for decorators, tree-shaking web packages, and loading font icons with optional native dependencies if they're installed.
|
|
4
4
|
|
|
5
|
-
You can use this preset in any React Native project as a drop-in replacement for
|
|
5
|
+
You can use this preset in any React Native project as a drop-in replacement for `@react-native/babel-preset`. If your project isn't using native font loading or web support then this preset will only add support for decorators with `@babel/plugin-proposal-decorators` - this is mostly used for supporting legacy community libraries.
|
|
6
6
|
|
|
7
7
|
If you start your **web** project with `@expo/webpack-config` or `npx expo start` and your project doesn't contain a `babel.config.js` or a `.babelrc` then it will default to using `babel-preset-expo` for loading.
|
|
8
8
|
|
|
@@ -92,14 +92,10 @@ This can improve the initial load time of your app because evaluating dependenci
|
|
|
92
92
|
|
|
93
93
|
The value of `lazyImports` has a few possible effects:
|
|
94
94
|
|
|
95
|
-
- `null` - [
|
|
96
|
-
|
|
95
|
+
- `null` - [@react-native/babel-preset](https://github.com/facebook/react-native/tree/main/packages/react-native-babel-preset) will handle it. (Learn more about it here: https://github.com/facebook/metro/commit/23e3503dde5f914f3e642ef214f508d0a699851d)
|
|
97
96
|
- `false` - No lazy initialization of any imported module.
|
|
98
|
-
|
|
99
97
|
- `true` - Lazy-init all imported modules except local imports (e.g., `./foo`), certain Expo packages that have side effects, and the two cases mentioned [here](https://babeljs.io/docs/en/babel-plugin-transform-modules-commonjs#lazy).
|
|
100
|
-
|
|
101
98
|
- `Array<string>` - [babel-plugin-transform-modules-commonjs](https://babeljs.io/docs/en/babel-plugin-transform-modules-commonjs#lazy) will handle it.
|
|
102
|
-
|
|
103
99
|
- `(string) => boolean` - [babel-plugin-transform-modules-commonjs](https://babeljs.io/docs/en/babel-plugin-transform-modules-commonjs#lazy) will handle it.
|
|
104
100
|
|
|
105
101
|
If you choose to do this, you can also access the list of Expo packages that have side effects by using `const lazyImportsBlacklist = require('babel-preset-expo/lazy-imports-blacklist');` which returns a `Set`.
|
|
@@ -117,11 +113,20 @@ The value of `lazyImports` has a few possible effects:
|
|
|
117
113
|
|
|
118
114
|
### `disableImportExportTransform`
|
|
119
115
|
|
|
120
|
-
|
|
116
|
+
Pass `true` to disable the transform that converts import/export to `module.exports`. Avoid setting this property directly. If you're using Metro, set `experimentalImportSupport: true` instead to ensure the entire pipeline is configured correctly.
|
|
121
117
|
|
|
122
|
-
|
|
118
|
+
```js
|
|
119
|
+
// metro.config.js
|
|
120
|
+
|
|
121
|
+
config.transformer.getTransformOptions = async () => ({
|
|
122
|
+
transform: {
|
|
123
|
+
// Setting this to `true` will automatically toggle `disableImportExportTransform` in `babel-preset-expo`.
|
|
124
|
+
experimentalImportSupport: true,
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
```
|
|
123
128
|
|
|
124
|
-
|
|
129
|
+
If `undefined` (default), this will be set automatically via `caller.supportsStaticESM` which is set by the bundler.
|
|
125
130
|
|
|
126
131
|
```js
|
|
127
132
|
[
|
|
@@ -134,15 +139,15 @@ Enabling this option will allow your project to run with older JavaScript syntax
|
|
|
134
139
|
|
|
135
140
|
### `unstable_transformProfile`
|
|
136
141
|
|
|
137
|
-
Changes the engine preset in
|
|
142
|
+
Changes the engine preset in `@react-native/babel-preset` based on the JavaScript engine that is being targeted. In Expo SDK 50 and greater, this is automatically set based on the [`jsEngine`](https://docs.expo.dev/versions/latest/config/app/#jsengine) option in your `app.json`.
|
|
138
143
|
|
|
139
144
|
### `enableBabelRuntime`
|
|
140
145
|
|
|
141
|
-
Passed to
|
|
146
|
+
Passed to `@react-native/babel-preset`.
|
|
142
147
|
|
|
143
148
|
### `disableFlowStripTypesTransform`
|
|
144
149
|
|
|
145
|
-
Passed to
|
|
150
|
+
Passed to `@react-native/babel-preset`.
|
|
146
151
|
|
|
147
152
|
## Platform-specific options
|
|
148
153
|
|
package/build/index.js
CHANGED
|
@@ -20,6 +20,7 @@ function babelPresetExpo(api, options = {}) {
|
|
|
20
20
|
const isDev = api.caller(common_1.getIsDev);
|
|
21
21
|
const isFastRefreshEnabled = api.caller(common_1.getIsFastRefreshEnabled);
|
|
22
22
|
const baseUrl = api.caller(common_1.getBaseUrl);
|
|
23
|
+
const supportsStaticESM = api.caller((caller) => caller?.supportsStaticESM);
|
|
23
24
|
// Unlike `isDev`, this will be `true` when the bundler is explicitly set to `production`,
|
|
24
25
|
// i.e. `false` when testing, development, or used with a bundler that doesn't specify the correct inputs.
|
|
25
26
|
const isProduction = api.caller(common_1.getIsProd);
|
|
@@ -34,10 +35,10 @@ function babelPresetExpo(api, options = {}) {
|
|
|
34
35
|
if (platform === 'web') {
|
|
35
36
|
// Only disable import/export transform when Webpack is used because
|
|
36
37
|
// Metro does not support tree-shaking.
|
|
37
|
-
platformOptions.disableImportExportTransform = isWebpack;
|
|
38
|
+
platformOptions.disableImportExportTransform = supportsStaticESM ?? isWebpack;
|
|
38
39
|
}
|
|
39
40
|
else {
|
|
40
|
-
platformOptions.disableImportExportTransform = false;
|
|
41
|
+
platformOptions.disableImportExportTransform = supportsStaticESM ?? false;
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
if (platformOptions.unstable_transformProfile == null) {
|
|
@@ -51,10 +52,7 @@ function babelPresetExpo(api, options = {}) {
|
|
|
51
52
|
// `@react-native/babel-preset` configures this plugin with `{ loose: true }`, which breaks all
|
|
52
53
|
// getters and setters in spread objects. We need to add this plugin ourself without that option.
|
|
53
54
|
// @see https://github.com/expo/expo/pull/11960#issuecomment-887796455
|
|
54
|
-
extraPlugins.push([
|
|
55
|
-
require.resolve('@babel/plugin-proposal-object-rest-spread'),
|
|
56
|
-
{ loose: false },
|
|
57
|
-
]);
|
|
55
|
+
extraPlugins.push([require('@babel/plugin-transform-object-rest-spread'), { loose: false }]);
|
|
58
56
|
}
|
|
59
57
|
else {
|
|
60
58
|
// This is added back on hermes to ensure the react-jsx-dev plugin (`@babel/preset-react`) works as expected when
|
|
@@ -99,7 +97,7 @@ function babelPresetExpo(api, options = {}) {
|
|
|
99
97
|
extraPlugins.push(inline_env_vars_1.expoInlineEnvVars);
|
|
100
98
|
}
|
|
101
99
|
if (platform === 'web') {
|
|
102
|
-
extraPlugins.push(require
|
|
100
|
+
extraPlugins.push(require('babel-plugin-react-native-web'));
|
|
103
101
|
// Webpack uses the DefinePlugin to provide the manifest to `expo-constants`.
|
|
104
102
|
if (bundler !== 'webpack') {
|
|
105
103
|
extraPlugins.push(expo_inline_manifest_plugin_1.expoInlineManifestPlugin);
|
|
@@ -183,12 +181,12 @@ function babelPresetExpo(api, options = {}) {
|
|
|
183
181
|
plugins: [
|
|
184
182
|
...extraPlugins,
|
|
185
183
|
// TODO: Remove
|
|
186
|
-
[require
|
|
187
|
-
require
|
|
184
|
+
[require('@babel/plugin-proposal-decorators'), { legacy: true }],
|
|
185
|
+
require('@babel/plugin-transform-export-namespace-from'),
|
|
188
186
|
// Automatically add `react-native-reanimated/plugin` when the package is installed.
|
|
189
187
|
// TODO: Move to be a customTransformOption.
|
|
190
188
|
(0, common_1.hasModule)('react-native-reanimated') &&
|
|
191
|
-
platformOptions.reanimated !== false && [require
|
|
189
|
+
platformOptions.reanimated !== false && [require('react-native-reanimated/plugin')],
|
|
192
190
|
].filter(Boolean),
|
|
193
191
|
};
|
|
194
192
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-preset-expo",
|
|
3
|
-
"version": "0.0.1-canary-
|
|
3
|
+
"version": "0.0.1-canary-20240222-c729a13",
|
|
4
4
|
"description": "The Babel preset for Expo projects",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"files": [
|
|
@@ -42,19 +42,19 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@babel/plugin-proposal-decorators": "^7.12.9",
|
|
45
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.12.13",
|
|
46
45
|
"@babel/plugin-transform-export-namespace-from": "^7.22.11",
|
|
46
|
+
"@babel/plugin-transform-object-rest-spread": "^7.12.13",
|
|
47
|
+
"@babel/plugin-transform-parameters": "^7.22.15",
|
|
47
48
|
"@babel/preset-env": "^7.20.0",
|
|
48
49
|
"@babel/preset-react": "^7.22.15",
|
|
49
|
-
"@babel/plugin-transform-parameters": "^7.22.15",
|
|
50
50
|
"@react-native/babel-preset": "^0.73.18",
|
|
51
|
-
"babel-plugin-react-native-web": "~0.
|
|
51
|
+
"babel-plugin-react-native-web": "~0.19.10",
|
|
52
52
|
"react-refresh": "0.14.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@babel/core": "^7.20.0",
|
|
56
|
-
"expo-module-scripts": "0.0.1-canary-
|
|
56
|
+
"expo-module-scripts": "0.0.1-canary-20240222-c729a13",
|
|
57
57
|
"jest": "^29.2.1"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "c729a13f936926743c13c021f569a22921455e49"
|
|
60
60
|
}
|