Skip to main content

config

Build npm version

Query for a package's configuration.

Configuration influences how the CLI behaves. If you're not using the CLI, and instead using a specific tool programmatically, you can use this library to read configuration data and use it as tool input.

Schema

Package configuration is under the top-level rnx-kit entry in package.json. It is of type KitConfig.

KitConfig

Configuration information for an rnx-kit package. This is retrieved from 'rnx-kit' in package.json.

NameTypeDescription
kitType"app" | "library" | undefinedLibrary or App package. Used by the dependency manager when projecting capabilities into dependencies, devDependencies, and peerDependencies. Library package dependencies are private, in dev and peer. App package dependencies are public.
reactNativeVersionstring | undefinedReact Native version (or range) which this package supports.
reactNativeDevVersionstring | undefinedReact Native version to use during development of this package. If not specified, the minimum reactNativeVersion is used.
bundleBundleConfig | BundleConfig[] | undefinedSpecifies how the package is bundled.
serverServerConfig | undefinedSpecifies how the package's bundle server is configured.
capabilitiesCapability[] | undefinedList of capabilities that this package needs. A capability is a well-known name (string).
customProfilesstring | undefinedPath to a file containing custom profiles.

BundleConfig inherits BundleParameters

Defines how a package is bundled. Includes shared bundling parameters with platform-specific overrides.

NameTypeDescription
idstring | undefinedUnique identifier for this bundle definition. Only used as a reference within the build system.
targetsAllPlatforms[] | undefinedThe platform(s) for which this package may be bundled.
platformsRecord<AllPlatforms, BundleDefinition> | undefinedPlatform-specific overrides for bundling parameters. Any parameter not listed in an override gets its value from the shared bundle definition, or falls back to defaults.

AllPlatforms

Union of: "ios", "android", "windows", "win32", "macos"

BundleParameters

Parameters controlling how a bundle is constructed.

NameTypeDescription
entryFilestring | undefinedPath to the .js file which is the entry-point for building the bundle. Either absolute, or relative to the package.
bundleOutputstring | undefinedPath to the output bundle file. Either absolute or relative to the package.
bundleEncodingstring | undefinedEncoding scheme to use when writing the bundle file. Currently limited to UTF-8, UTF-16 (little endian), and 7-bit ASCII.
sourcemapOutputstring | undefinedPath to use when creating the bundle source map file. Either absolute, or relative to the package.
sourcemapSourcesRootstring | undefinedPath to the package's source files. Used to make source-map paths relative and therefore portable.
sourcemapUseAbsolutePathboolean | undefinedControls whether or not SourceMapURL is reported as a full path or just a file name.
assetsDeststring | undefinedPath where all bundle assets (strings, images, fonts, sounds, ...) are written. Either absolute, or relative to the package.
indexedBundleFormatboolean | undefinedForce the "Indexed RAM" bundle file format, even when targeting Android. Only applies to the rnx-ram-bundle command.
plugins(string | [string, any])[]List of plugins to apply. If unset, it falls back to ["@rnx-kit/metro-plugin-cyclic-dependencies-detector", "@rnx-kit/metro-plugin-duplicates-checker", "@rnx-kit/metro-plugin-typescript"].
treeShakeboolean | undefinedChoose whether to enable tree shaking.

CyclicDetectorOptions

NameTypeDefaultDescription
includeNodeModulesboolean | undefinedfalseWhen scanning for circular dependencies, include all external packages from node_modules.
linesOfContextnumber | undefined1When a cycle is detected, this controls the size of the module backtrace that is printed with the error message.
throwOnErrorboolean | undefinedtrueWhether or not to throw an exception when a cycle is detected.

DuplicateDetectorOptions

NameTypeDefaultDescription
ignoredModulesstring[] | undefinedList of modules to ignore when scanning for duplicate dependencies.
bannedModulesstring[] | undefinedList of modules that always cause a failure, regardless of whether or not they are duplicated.
throwOnErrorboolean | undefinedtrueWhether or not to throw an exception when a duplicate or banned module is detected.

TypeScriptValidationOptions

NameTypeDefaultDescription
throwOnErrorboolean | undefinedtrueControls whether an error is thrown when type-validation fails.

ServerConfig

NameTypeDescription
projectRootstring | undefinedPath to the root of your react-native application. The bundle server uses this root path to resolve all web requests. The root path should contain your Babel config, otherwise Metro won't be able to find it. Either absolute, or relative to the package.
assetPluginsstring[] | undefinedAdditional asset plugins to be used by the Metro Babel transformer. Comma-separated list containing plugin modules and/or absolute paths to plugin packages.
sourceExtsstring[] | undefinedAdditional source-file extensions to include when generating bundles. Comma-separated list, excluding the leading dot.
plugins(string | [string, any])[]List of plugins to apply. If unset, it falls back to ["@rnx-kit/metro-plugin-cyclic-dependencies-detector", "@rnx-kit/metro-plugin-duplicates-checker", "@rnx-kit/metro-plugin-typescript"].

API

getKitConfig({module, cwd})

Query for a package's rnx-kit configuration.

ParameterTypeDescription
modulestring | undefinedRead package configuration from the named module. When given, this takes precedence over cwd.
cwdstring | undefinedRead package configuration from the given directory. Ignored when module is given.
[Return]KitConfig | nullPackage configuration, or null if nothing was found.

getBundleConfig(config, id)

Get a bundle configuration from the rnx-kit configuration.

If an id is given, search for the matching bundle definition. Otherwise, use the first bundle definition.

ParameterTypeDescription
configKitConfigThe package's rnx-kit configuration
idstring | undefinedOptional identity of the target bundle configuration
[Return]BundleDefinitionBundle configuration, or undefined if nothing was found

getPlatformBundleConfig(bundle, platform)

Resolves the platform selector for a bundle configuration.

ParameterTypeDescription
bundleBundleConfigBundle config to resolve (includes the optional platform selectors)
platformAllPlatformsTarget platform
[Return]BundleDefinitionBundle config containing platform-specific overrides

getKitCapabilities(config)

Get capability information from the package configuration.

ParameterTypeDescription
configKitConfigPackage configuration.
[Return]KitCapabilitiesCapability information.

KitCapabilities

NameTypeDefaultDescription
kitType"app" | "library" | undefined"library"Library or App package. Used by the dependency manager when projecting capabilities into dependencies, devDependencies, and peerDependencies. Library package dependencies are private, in dev and peer. App package dependencies are public.
reactNativeVersionstringReact Native version (or range) which this package supports.
reactNativeDevVersionstring Min version in reactNativeVersionReact Native version to use during development of this package. If not specified, the minimum reactNativeVersion is used.
capabilitiesCapability[][]List of capabilities that this package needs. A capability is a well-known name (string).
customProfilesstring | undefinedPath to a file containing custom profiles.