Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Creates a Metro server based on the config and returns it. Its `processRequest`

**Required options:** `entry`

**Basic options:** `out`, `bundleOut`, `sourceMapOut`, `dev`, `minify`, `platform`, `sourceMap`, `sourceMapUrl`, `assets`, `onBegin`, `onProgress`, `onComplete`, `customResolverOptions`, `customTransformOptions`, `output`
**Basic options:** `out`, `bundleOut`, `sourceMapOut`, `dev`, `minify`, `platform`, `sourceMap`, `sourceMapUrl`, `assets`, `onBegin`, `onProgress`, `onComplete`, `customResolverOptions`, `customTransformOptions`, `unstable_transformProfile`, `output`

Bundles `entry` for the given `platform` (defaults to `'web'`). If `out` or `bundleOut` is given, saves the bundle to `bundleOut`, or to `out` with a `.js` extension. If `sourceMap` is set, also generates a source map. The source map will be inlined, unless `sourceMapUrl` is also defined, in which case `sourceMapUrl` is used as the bundle's `sourceMappingURL`. When saving to disk, the source map is also written to `sourceMapOut`, or to `out` with a `.map` extension. If `assets` is `true`, an array of `AssetData` will be generated and returned in the `assets` property of the result object.

Expand Down
33 changes: 33 additions & 0 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,14 @@ In a future release of Metro, this option will be removed.

:::

#### `unstable_forceFullRefreshPatterns` <div class="label experimental">Experimental</div>

Type: `Array<RegExp>`

Modules that should trigger a full reload instead of a Fast Refresh update when they change, e.g. modules with side effects (such as style registration) that don't re-run correctly when hot reloaded. Patterns are tested against module paths relative to [`projectRoot`](#projectroot). Only applies to development bundles. Defaults to `[]`.

---

### Transformer Options

<!-- Keep old links to `asyncRequireModulePath` working -->
Expand Down Expand Up @@ -611,6 +619,18 @@ Type: `string`

The URL path prefix written into each asset's `httpServerLocation`, which the app uses to request the asset. Metro's own server only serves assets under `/assets`, so with a different value you need to route those requests yourself, e.g. with [`rewriteRequestUrl`](#rewriterequesturl). Defaults to `'/assets'`.

#### `unstable_allowRequireContext` <div class="label experimental">Experimental</div>

Type: `boolean`

Enables `require.context()`, which imports all the files in a directory that match a pattern. Defaults to `false`.

#### `unstable_workerThreads` <div class="label experimental">Experimental</div>

Type: `boolean`

Whether to run transformer workers as worker threads instead of child processes. Defaults to `false`.

#### React Native Only

#### `assetPlugins`
Expand Down Expand Up @@ -736,6 +756,13 @@ Type: `(graph: ReadOnlyGraph, delta: DeltaResult) => mixed`

A function called with the dependency graph and the changes since the previous build, each time a graph is built or updated.

#### `unstable_lazilyDefineModules` <div class="label experimental">Experimental</div>

Type: `boolean`

Whether the default serializer defines each module lazily, on its first `require`, instead of running every `__d(...)` call at startup. This reduces startup cost and peak memory use for large bundles. Does not affect Fast Refresh updates. Defaults to `false`.

---
### Server Options

These options are used when Metro serves the content.
Expand All @@ -746,6 +773,12 @@ Type: `number`

Which port to listen on. Defaults to `8081`.

#### `unstable_serverRoot` <div class="label experimental">Experimental</div>

Type: `?string`

The directory that bundle URLs and entry files are resolved against, instead of [`projectRoot`](#projectroot). Defaults to `null` (use `projectRoot`).

#### `useGlobalHotkey`

Type: `boolean`
Expand Down
4 changes: 3 additions & 1 deletion docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ Given a configuration and a set of options that you would typically pass to a se
* `sourceMap (boolean)`: Whether Metro should generate source maps.
* `sourceMapOut (string)`: Where to save the source map, if `sourceMap == true`. No extension will be added.
* `sourceMapUrl (string)`: URL where the source map can be found, written as the bundle's `sourceMappingURL`. If `sourceMap` is `true` and `sourceMapUrl` is not set, the source map is inlined into the bundle.
* `unstable_transformProfile ('default' | 'hermes-stable' | 'hermes-canary')`: Passed to the Babel transformer, which can use it to target a specific JavaScript engine.

```js
const config = await Metro.loadConfig();
Expand Down Expand Up @@ -214,6 +215,7 @@ Any JS file can be used as the root for a bundle request. The file will be looke
* `runModule`: whether to end the bundle with the statements that run the entry point. Defaults to `true`.
* `shallow`: whether to include only the entry module itself, without its dependencies. Defaults to `false`.
* `sourcePaths`: how source files are referenced in the source map: as absolute file paths (`absolute`), or as URL paths on the server (`url-server`). Defaults to `absolute`.
* `unstable_transformProfile`: passed to the Babel transformer (`default`, `hermes-stable` or `hermes-canary`). Defaults to `default`.
* `resolver.<key>` and `transform.<key>`: [custom resolver options](./Resolution.md#customresolveroptions-string-mixed) and custom transform options, e.g. `transform.foo=bar` passes `{foo: 'bar'}` to the transformer.

For instance, requesting `http://localhost:8081/foo/bar/baz.bundle?dev=true&platform=ios` will create a bundle out of `foo/bar/baz.js` for iOS in development mode.
Expand All @@ -228,7 +230,7 @@ The JavaScript transformer ([`babelTransformerPath`](./Configuration.md#babeltra

### Method `transform(module)`

Mandatory method that will transform code. The object received has the module's `filename` (relative to the project root), its source code `src`, transformation `options` (e.g. `dev`, `platform`, `minify`, `projectRoot`, `customTransformOptions`), and Babel `plugins` that Metro wants applied. The returned object has to contain an `ast` key that is the AST representation of the transformed code, and may contain the Babel `metadata`. A minimal transformer only parses the code to AST:
Mandatory method that will transform code. The object received has the module's `filename` (relative to the project root), its source code `src`, transformation `options` (e.g. `dev`, `platform`, `minify`, `projectRoot`, `customTransformOptions`, `unstable_transformProfile`), and Babel `plugins` that Metro wants applied. The returned object has to contain an `ast` key that is the AST representation of the transformed code, and may contain the Babel `metadata`. A minimal transformer only parses the code to AST:

```js
const babylon = require('@babel/parser');
Expand Down
Loading