babel-preset-expo
The Babel preset for Expo projects
Last updated 10 months ago by wschurman .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install babel-preset-expo 
SYNC missed versions from official npm registry.

babel-preset-expo

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.

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.

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.

If you have problems with the code in this repository, please file issues & bug reports at https://github.com/expo/expo. Thanks!

Expo Bundler Spec Compliance

A bundler must follow these requirements if they are to be considered spec compliant for use with a universal React (Expo) project.

Babel Loader

The babel loading mechanism must include the following properties on its caller.

platform

A platform property denoting the target platform. If the platform is not defined, it will default to using web when the bundler is webpack -- this is temporary and will throw an error in the future.

Value Description
ios Runs on iOS devices
android Runs on Android devices
web Runs in web browsers

bundler

A bundler property denoting the name of the bundler that is being used to create the JavaScript bundle. If the bundler is not defined, it will default to checking if a babel-loader is used, if so then webpack will be used, otherwise it will default to metro.

Value Description
metro Bundling with Metro
webpack Bundling with Webpack

Options

react-compiler

Settings to pass to babel-plugin-react-compiler. Set as false to disable the plugin. As of SDK 51, you must also enable experiments.reactCompiler: true in the app.json.

[
  'babel-preset-expo',
  {
    'react-compiler': {
      sources: (filename) => {
        // Match file names to include in the React Compiler.
        return filename.includes('src/path/to/dir');
      },
    },
  },
];

minifyTypeofWindow

Set minifyTypeofWindow: false to preserve the typeof window check in your code, e.g. if (typeof window === 'undefined') -> if (true) in servers. This is useful when you're using libraries that mock the window object on native or in the server.

[
  'babel-preset-expo',
  {
    // If your native app doesn't polyfill `window` then setting this to `false` can reduce bundle size.
    native: {
      minifyTypeofWindow: true,
    },
  },
];

Defaults to false for server environments and web, true for native platforms to support legacy browser polyfills.

reanimated

boolean, defaults to true. Set reanimated: false to disable adding the react-native-reanimated/plugin when react-native-reanimated is installed.

jsxRuntime

classic | automatic, defaults to automatic

  • automatic automatically convert JSX to JS without the need to import React from 'react' in every file. Be sure to follow the rest of the setup guide after enabling this, otherwise ESLint and other tools will throw warnings.
  • classic does not automatically import anything, React must imported into every file that uses JSX syntax.
[
  'babel-preset-expo',
  {
    jsxRuntime: 'classic',
  },
];

This property is passed down to @babel/plugin-transform-react-jsx. This flag does nothing when useTransformReactJSXExperimental is set to true because @babel/plugin-transform-react-jsx is omitted.

jsxImportSource

string, defaults to react

This option allows specifying a custom import source for importing functions.

[
  'babel-preset-expo',
  {
    jsxRuntime: 'automatic',
    jsxImportSource: 'react',
  },
];

This property is passed down to @babel/plugin-transform-react-jsx. This options does nothing when jsxRuntime is not set to automatic.

lazyImports

Changes Babel's compiled import statements to be lazily evaluated when their imported bindings are used for the first time.

Note: this option has an effect only when the disableImportExportTransform option is set to false. On Android and iOS, disableImportExportTransform defaults to false, and on web it defaults to true to allow for tree shaking.

This can improve the initial load time of your app because evaluating dependencies up front is sometimes entirely un-necessary, particularly when the dependencies have no side effects.

The value of lazyImports has a few possible effects:

default: null

[
    'babel-preset-expo',
    {
        lazyImports: true
    }
],

disableImportExportTransform

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.

// metro.config.js

config.transformer.getTransformOptions = async () => ({
  transform: {
    // Setting this to `true` will automatically toggle `disableImportExportTransform` in `babel-preset-expo`.
    experimentalImportSupport: true,
  },
});

If undefined (default), this will be set automatically via caller.supportsStaticESM which is set by the bundler.

[
    'babel-preset-expo',
    {
        disableImportExportTransform: true
    }
],

unstable_transformProfile

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 option in your app.json.

enableBabelRuntime

Passed to @react-native/babel-preset.

disableFlowStripTypesTransform

Passed to @react-native/babel-preset.

Platform-specific options

All options can be passed in the platform-specific objects native and web to provide different settings on different platforms. For example, if you'd like to only apply disableImportExportTransform on web, use the following:

[
  'babel-preset-expo',
  {
    // Default value:
    disableImportExportTransform: false,

    web: {
      // Web-specific value:
      disableImportExportTransform: true,
    },
  },
];

Platform-specific options have higher priority over top-level options.

Current Tags

  • 11.1.0-canary-20240927-ab8a962                                ...           canary (3 months ago)
  • 11.0.14                                ...           latest (4 months ago)
  • 11.0.14                                ...           next (4 months ago)
  • 10.0.1                                ...           sdk-50 (a year ago)
  • 11.0.6                                ...           sdk-51 (7 months ago)

105 Versions

  • 11.1.0-canary-20240927-ab8a962                                ...           3 months ago
  • 11.1.0-canary-20240912-1059f85                                ...           3 months ago
  • 11.1.0-canary-20240904-69100c1                                ...           4 months ago
  • 11.1.0-canary-20240814-ce0f7d5                                ...           4 months ago
  • 11.0.14                                ...           4 months ago
  • 11.0.13                                ...           5 months ago
  • 11.1.0-canary-20240719-83ee47b                                ...           5 months ago
  • 11.0.12                                ...           6 months ago
  • 11.1.0-canary-20240628-1ba8152                                ...           6 months ago
  • 11.0.11                                ...           6 months ago
  • 11.1.0-canary-20240627-1402f4b                                ...           6 months ago
  • 11.1.0-canary-20240625-2333e70                                ...           6 months ago
  • 11.0.10                                ...           6 months ago
  • 11.0.9                                ...           6 months ago
  • 11.0.8                                ...           7 months ago
  • 11.0.7                                ...           7 months ago
  • 11.0.6                                ...           7 months ago
  • 11.0.5                                ...           8 months ago
  • 11.0.4                                ...           8 months ago
  • 11.0.3                                ...           8 months ago
  • 11.0.2                                ...           8 months ago
  • 11.0.1                                ...           8 months ago
  • 11.0.0                                ...           8 months ago
  • 0.0.1-canary-20240418-8d74597                                ...           8 months ago
  • 0.0.1-canary-20240415-cca04d8                                ...           8 months ago
  • 0.0.1-canary-20240415-0868fc4                                ...           8 months ago
  • 10.0.2                                ...           8 months ago
  • 0.0.1-canary-20240411-55a0085                                ...           8 months ago
  • 0.0.1-canary-20240411-33a7dc1                                ...           8 months ago
  • 0.0.1-canary-20240406-a4950c7                                ...           9 months ago
  • 0.0.1-canary-20240405-cdfd9c1                                ...           9 months ago
  • 0.0.1-canary-20240404-e2b8743                                ...           9 months ago
  • 0.0.1-canary-20240328-24ecc5e                                ...           9 months ago
  • 0.0.1-canary-20240327-a7302d9                                ...           9 months ago
  • 0.0.1-canary-20240320-8a10e09                                ...           9 months ago
  • 0.0.1-canary-20240318-dd8f245                                ...           9 months ago
  • 0.0.1-canary-20240318-af634b1                                ...           9 months ago
  • 0.0.1-canary-20240318-53194f5                                ...           9 months ago
  • 0.0.1-canary-20240315-ce71005                                ...           9 months ago
  • 0.0.1-canary-20240308-6715875                                ...           10 months ago
  • 0.0.1-canary-20240305-e60019e                                ...           10 months ago
  • 0.0.1-canary-20240228-7cee619                                ...           10 months ago
  • 0.0.1-canary-20240222-c729a13                                ...           10 months ago
  • 0.0.1-canary-20240109-93608d8                                ...           a year ago
  • 10.0.1                                ...           a year ago
  • 10.0.0                                ...           a year ago
  • 0.0.1-canary-20231205-250b31f                                ...           a year ago
  • 0.0.1-canary-20231130-c8a9bf9                                ...           a year ago
  • 0.0.1-canary-20231130-ede75a7-1                                ...           a year ago
  • 0.0.1-canary-20231130-ede75a7                                ...           a year ago
  • 0.0.1-canary-20231129-c0ec023                                ...           a year ago
  • 0.0.1-canary-20231125-d600e44                                ...           a year ago
  • 0.0.0-canary-20231123-1b19f96                                ...           a year ago
  • 0.0.0-canary-20231122-1af9191                                ...           a year ago
  • 9.9.0                                ...           a year ago
  • 9.8.0                                ...           a year ago
  • 9.7.0                                ...           a year ago
  • 9.6.2                                ...           a year ago
  • 9.5.2                                ...           a year ago
  • 9.6.1                                ...           a year ago
  • 9.6.0                                ...           a year ago
  • 9.5.1                                ...           a year ago
  • 9.5.0                                ...           2 years ago
  • 9.4.1                                ...           2 years ago
  • 9.4.0                                ...           2 years ago
  • 9.3.2                                ...           2 years ago
  • 9.3.1                                ...           2 years ago
  • 9.3.0                                ...           2 years ago
  • 9.2.2                                ...           2 years ago
  • 9.2.1                                ...           2 years ago
  • 9.2.0                                ...           2 years ago
  • 9.1.0                                ...           3 years ago
  • 9.0.2                                ...           3 years ago
  • 9.0.1                                ...           3 years ago
  • 9.0.0                                ...           3 years ago
  • 8.5.1                                ...           3 years ago
  • 8.5.0                                ...           3 years ago
  • 8.4.1                                ...           3 years ago
  • 8.4.0                                ...           4 years ago
  • 8.3.0                                ...           4 years ago
  • 8.2.3                                ...           5 years ago
  • 8.2.2                                ...           5 years ago
  • 8.2.1                                ...           5 years ago
  • 8.1.1 [deprecated]           ...           5 years ago
  • 8.2.0 [deprecated]           ...           5 years ago
  • 8.1.0                                ...           5 years ago
  • 8.0.0                                ...           5 years ago
  • 7.1.0                                ...           5 years ago
  • 7.0.0                                ...           5 years ago
  • 7.0.0-rc.1                                ...           5 years ago
  • 7.0.0-rc.0                                ...           5 years ago
  • 6.0.0                                ...           5 years ago
  • 5.2.0                                ...           6 years ago
  • 5.1.1                                ...           6 years ago
  • 5.1.0                                ...           6 years ago
  • 5.0.0                                ...           6 years ago
  • 5.0.0-rc.1                                ...           6 years ago
  • 5.0.0-rc.0                                ...           6 years ago
  • 4.0.0                                ...           7 years ago
  • 3.0.0                                ...           7 years ago
  • 3.0.0-alpha.0                                ...           7 years ago
  • 2.0.0                                ...           8 years ago
  • 2.0.0-rc.0                                ...           8 years ago
  • 1.0.1                                ...           8 years ago
  • 1.0.0                                ...           8 years ago

© 2010 - cnpmjs.org x YWFE | Home | YWFE