-
-
Notifications
You must be signed in to change notification settings - Fork 237
Expand file tree
/
Copy pathbabel.config.js
More file actions
36 lines (33 loc) · 1.13 KB
/
babel.config.js
File metadata and controls
36 lines (33 loc) · 1.13 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
/**
* The library's babel config has a single job: ensure
* `babel-plugin-react-compiler` runs on every code path that produces
* shipped JavaScript.
*
* - When `react-native-builder-bob` invokes us (bob targets set
* `configFile: true` so they pick up this file), we extend bob's own
* preset — it already takes care of `@babel/preset-env`, JSX, TS, and
* import-extension rewriting. Adding our own RN preset would mis-target
* the published bundle for Hermes only.
* - For any other caller (jest is ts-jest only and ignores this file, but
* IDE tooling and `metro` in the example app may load it), fall back to
* the standard React Native preset.
*
* The compiler plugin is listed BEFORE other plugins so it operates on
* pristine source.
*/
module.exports = (api) => {
const isBob = api.caller((caller) =>
caller != null ? caller.name === 'react-native-builder-bob' : false
)
const plugins = ['babel-plugin-react-compiler']
if (isBob) {
return {
presets: [require.resolve('react-native-builder-bob/babel-preset')],
plugins,
}
}
return {
presets: ['module:@react-native/babel-preset'],
plugins,
}
}