You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update Configuration docs for TypeScript, ESM support and YAML deprecation (#1632)
Summary:
Update docs to reflect recent additions to config file support
Pull Request resolved: #1632
Test Plan: Ran new TypeScript merging example through `tsc` to check it
Reviewed By: vzaidman
Differential Revision: D89770691
Pulled By: robhogan
fbshipit-source-id: 4d3f7d7771cc35b0d26c8703a6e3645ae5da68ae
You can also give a custom file to the configuration by specifying `--config <path/to/config>` when calling the CLI.
13
15
16
+
:::warning Deprecated
17
+
18
+
YAML config files (`.yaml`, `.yml`) are **deprecated** and will be removed in a future version of Metro. Please migrate to a JavaScript, TypeScript, or JSON config file. When Metro loads a YAML config file, it will display a deprecation warning.
19
+
20
+
:::
21
+
22
+
:::info TypeScript Config Support
23
+
24
+
TypeScript config files are supported in Node.js 24.0.0+ or Node.js 22.6.0+ with the `--experimental-strip-types` flag. If your Node.js version doesn't support loading TypeScript natively, you'll see an error with instructions when attempting to load a TypeScript config file.
25
+
26
+
:::
27
+
14
28
:::note
15
29
16
30
When Metro is started via the React Native CLI, some defaults are different from those mentioned below.
@@ -20,10 +34,13 @@ See the [React Native repository](https://github.com/facebook/react-native/blob/
20
34
21
35
## Configuration Structure
22
36
23
-
The configuration is based on [our concepts](./Concepts.md), which means that for every module we have a separate config option. A common configuration structure in Metro looks like this:
37
+
The configuration is based on [our concepts](./Concepts.md), which means that for every module we have a separate config option. A basic configuration structure in Metro looks like this:
24
38
25
-
```js
26
-
module.exports= {
39
+
```typescript
40
+
// metro.config.mts
41
+
importtype {MetroConfig} from'metro-config';
42
+
43
+
const config:MetroConfig= {
27
44
/* general options */
28
45
29
46
resolver: {
@@ -45,10 +62,17 @@ module.exports = {
45
62
}
46
63
}
47
64
};
65
+
66
+
exportdefaultconfig;
48
67
```
49
68
50
-
### General Options
69
+
:::note
51
70
71
+
See [Merging Configurations](#merging-configurations) below for more advanced forms.
requestCert?: boolean, // Whether to authenticate the remote peer by requesting a certificate
673
697
```
674
698
675
-
Notice that when overriding the base config, object tls configs extend the base tls config, false overrides the base tls configs, and `null` and `undefined` are ignored.
699
+
Notice that when overriding the base config, object `tls` configs extend the base `tls` config, `false` overrides the base `tls` configs, and `null` and `undefined` are ignored.
676
700
677
701
When running Metro with`Metro.runServer`with the `secureServerOptions` property Metro will likewise start an HTTPS server merging with the `config.server.tls` object if provided, overriding it.
678
702
@@ -768,50 +792,23 @@ This allows overriding and removing default config parameters such as `platforms
768
792
769
793
#### Merging Example
770
794
771
-
```js
772
-
// metro.config.js
773
-
const { mergeConfig } = require('metro-config');
774
-
775
-
const configA = {
776
-
/* general options */
777
-
778
-
resolver: {
779
-
/* resolver options */
780
-
},
781
-
transformer: {
782
-
/* transformer options */
783
-
},
784
-
serializer: {
785
-
/* serializer options */
786
-
},
787
-
server: {
788
-
/* server options */
789
-
}
790
-
};
791
-
792
-
constconfigB= {
793
-
/* general options */
794
-
795
-
resolver: {
796
-
/* resolver options */
797
-
},
798
-
transformer: {
799
-
/* transformer options */
800
-
},
801
-
serializer: {
802
-
/* serializer options */
803
-
},
804
-
server: {
805
-
/* server options */
806
-
}
807
-
};
808
-
809
-
// Function forms may be used to access the previous configuration
810
-
configCFn = (previousConfig /* result of mergeConfig(configA, configB) */) => {
0 commit comments