Skip to main content

types-bundle-config

Build npm version

TypeScript type definitions for Metro bundling configuration, bundler plugins, server configuration, and React Native platform targets. This package exists to break circular dependencies between rnx-kit packages that share these types.

Installation

yarn add @rnx-kit/types-bundle-config --dev

or if you're using npm

npm add --save-dev @rnx-kit/types-bundle-config

Usage

import type {
BundleConfig,
BundleParameters,
ServerConfig,
AllPlatforms,
Plugin,
} from "@rnx-kit/types-bundle-config";

Types

Bundle Configuration

BundleConfig

Defines how a package is bundled. Extends BundleParameters with platform-specific overrides.

NameTypeDescription
idstring | undefinedUnique identifier for this bundle configuration.
targetsAllPlatforms[] | undefinedThe platform(s) for which this package may be bundled.
platformsPartial<Record<AllPlatforms, BundleParameters>>Platform-specific overrides for bundling parameters.

BundleParameters

Parameters controlling how a bundle is constructed. Extends BundlerPlugins and BundleOutputOptions.

NameTypeDescription
entryFilestring | undefinedPath to the entry-point .js file. Either absolute or relative to package.
assetsDeststring | undefinedPath where bundle assets are written.
treeShakeboolean | SerializerEsbuildOptionsEnable tree shaking via esbuild.
hermesboolean | HermesOptionsWhether to run the Hermes compiler on the output bundle.
pluginsPlugin[]List of plugins to add to the bundling process.

BundleOutputOptions

Output path and encoding options for a bundle, derived from Metro's OutputOptions.

NameTypeDescription
bundleOutputstring | undefinedPath to the output bundle file.
bundleEncodingstring | undefinedEncoding scheme (UTF-8, UTF-16 LE, or 7-bit ASCII).
sourcemapOutputstring | undefinedPath for the bundle source map file.
sourcemapSourcesRootstring | undefinedPath to package source files for portable source-map paths.
sourcemapUseAbsolutePathboolean | undefinedWhether SourceMapURL is reported as a full path or just a file name.

HermesOptions

Options for the Hermes bytecode compiler.

NameTypeDescription
commandstring | undefinedPath to hermesc binary.
flagsstring[] | undefinedArguments passed to hermesc.

Server Configuration

ServerConfig

Configuration for the Metro bundle server. Extends BundlerPlugins.

NameTypeDescription
projectRootstring | undefinedPath to the root of the react-native project.
assetPluginsstring[] | undefinedAdditional asset plugins for the Metro Babel transformer.
sourceExtsstring[] | undefinedAdditional source-file extensions to include when generating bundles.
pluginsPlugin[]List of plugins to add to the bundling process.

Bundler Plugin Types

Plugin

A plugin is either a module name string or a tuple of [name, options].

Platform Types

AllPlatforms

Union type of supported React Native platforms:

type AllPlatforms =
| "android"
| "ios"
| "macos"
| "visionos"
| "web"
| "win32"
| "windows";

ALL_PLATFORM_VALUES

Constant array containing all platform values (useful for iteration):

const ALL_PLATFORM_VALUES = [
"android",
"ios",
"macos",
"visionos",
"web",
"win32",
"windows",
] as const;