Skip to main content

Metro CLI Options

The metro CLI has three commands:

Run npx metro <command>; metro --help shows all options.

React Native apps typically use npx react-native start and npx react-native bundle instead, which call the same APIs, runServer and runBuild, with React Native's configuration.

build <entry>​

Builds a bundle from the given entry point and its dependencies, and writes it to --out. Equivalent to runBuild.

npx metro build index.js --out bundle.js --platform ios

Options​

OptionAliasDescriptionValue
outOOutput file name (required)String
platformpPlatform to bundle for (e.g. web, android, ios)String
minifyzMinify the bundleBoolean
devgCreate a development build, in which __DEV__ is trueBoolean
configcPath to the metro.config.js to useString
max-workersjNumber of transformer workers. Overrides maxWorkers which defaults to a number based on os.availableParallelism()Number
source-mapGenerate a source mapBoolean
source-map-urlSource map URL (e.g. --source-map --source-map-url bundle.map adds //# sourceMappingURL=bundle.map to the bundle)String
resolver-optionCustom resolver options as URL-encoded key=value. Repeatable (e.g. --resolver-option foo=bar --resolver-option baz=1 passes {foo: 'bar', baz: '1'})Array
transform-optiontransformer-optionCustom transform options as URL-encoded key=value. Repeatable (e.g. --transform-option foo=a%20b passes {foo: 'a b'})Array
reset-cacheDeprecated. Clear Metro's caches before building, like resetCacheBoolean
project-rootsPAccepted but ignoredArray
legacy-bundlerAccepted but ignoredBoolean
output-typetAccepted but ignoredString

serve​

Alias: start

Starts a Metro development server that builds bundles on request, and restarts it when the config file changes. Equivalent to runServer.

npx metro serve --port 8082

Options​

OptionAliasDescriptionValue
hosthHost to listen on. Defaults to localhostString
portpPort to listen on. Defaults to 8081, overriding server.portNumber
configcPath to the metro.config.js to useString
max-workersjNumber of transformer workers. Overrides maxWorkers which defaults to a number based on os.availableParallelism()Number
secure-server-optionssHTTPS server options, in dot notation (e.g. -s.cert="$(cat path/to/cert)" -s.key="$(cat path/to/key)")Object
secureDeprecated. Serve over HTTPS. Use secure-server-options insteadBoolean
secure-keyDeprecated. Path to the key file for HTTPS when secure is setString
secure-certDeprecated. Path to the cert file for HTTPS when secure is setString
reset-cacheDeprecated. Clear Metro's caches on startup, like resetCacheBoolean
project-rootsPAccepted but ignoredArray
hmr-enabledhmrAccepted but ignoredBoolean

get-dependencies [entryFile]​

Lists all files bundled for a given entry point as absolute paths, one per line, including every resolution of an asset. For example, npx metro get-dependencies "$PWD/index.js" --platform ios prints:

/path/to/app/index.js
/path/to/app/App.js
/path/to/app/logo.png
/path/to/app/logo@2x.png

Options​

OptionDescriptionValue
entry-fileAbsolute path to the root JS file. Or pass it as the first positional argumentString
outputOutput file name, e.g. /tmp/dependencies.txtString
platformPlatform extension used for selecting modulesString
transformerCustom transformer to useString
max-workersMaximum number of transformer workers. Overrides maxWorkers which defaults to a number based on os.availableParallelism()Number
devIf false, skip dev-only code paths. Defaults to trueBoolean
verboseEnables logging. Defaults to falseBoolean