Repository navigation
Expand file tree
/
Copy pathbabel.config.js
More file actions
49 lines (46 loc) · 1.85 KB
/
Copy pathbabel.config.js
File metadata and controls
49 lines (46 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const path = require('path');
// Keeps React Native's own fetch as the global fetch (src/setupEnv.ts says why).
// In release bundles babel-preset-expo inlines EXPO_PUBLIC_* variables from the
// environment Babel runs in, so the app setting it at runtime is too late
// there: the flag must be set here as well. Without it, a release build installs
// expo/fetch, which threw on a FormData body (the SSO login's) in release
// builds.
process.env.EXPO_PUBLIC_USE_RN_FETCH = '1';
const srcDir = path.join(__dirname, 'src') + path.sep;
const widgetsDir = path.join(srcDir, 'widgets') + path.sep;
// babel-preset-expo inlines process.env.EXPO_OS and adds the Worklets,
// expo-widgets and @expo/ui plugins on its own. It only adds the React Compiler
// when app.json turns on `experiments.reactCompiler`, which we leave off, so the
// compiler is added here.
module.exports = {
presets: ['babel-preset-expo'],
plugins: [
// Must run first, on the original source. Only app code is compiled, not
// node_modules.
[
'babel-plugin-react-compiler',
{
target: '19',
// Widget layouts are sent as source text, not run as components.
sources: filename =>
filename.startsWith(srcDir) && !filename.startsWith(widgetsDir),
},
],
[
'module-resolver',
{
root: ['./src'],
// The local Expo modules sit next to src/, not in it; tests import the
// helpers, mocks and fixtures in jest/ as test-utils/…
alias: { modules: './modules', 'test-utils': './jest' },
extensions: ['.ts', '.tsx'],
},
],
// Inlines the allowed .env keys into src/helpers/env.ts.
'./babel/inline-env',
// Turns helpers/platform's isApple() and friends into checks Metro
// folds, so another platform's code leaves a release bundle.
'./babel/inline-platform',
'preval',
],
};