From 70e3ea8b5724a82507d9a43a892715ec9af91bc2 Mon Sep 17 00:00:00 2001 From: MoOx Date: Fri, 29 Mar 2019 19:40:02 +0100 Subject: [PATCH] Add documentation for Node.js module aliasing Close #1315 --- docs/guides/getting-started.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/guides/getting-started.md b/docs/guides/getting-started.md index 3ca183d3..c8783220 100644 --- a/docs/guides/getting-started.md +++ b/docs/guides/getting-started.md @@ -50,7 +50,7 @@ Now you can create your components and applications with the React Native API. ## Configuring Babel -If you need to do the aliasing with Babel you can use +[Babel](https://babeljs.io/) supports module aliasing using [babel-plugin-module-resolver](https://www.npmjs.com/package/babel-plugin-module-resolver) ``` @@ -92,6 +92,22 @@ You may also need to include a custom libdef ([example](https://gist.github.com/paularmstrong/f60b40d16fc83e1e8e532d483336f9bb)) in your config. +## Configuring Node.js + +Node.js can alias `react-native` to `react-native-web` using +[`module-alias`](https://www.npmjs.com/package/module-alias). This is useful if +you want to pre-render the app (e.g., server-side rendering or build-time +rendering). + +```js +// Install the `module-alias` package as a dependency first +const moduleAlias = require("module-alias"); +moduleAlias.addAliases({ + "react-native": require.resolve("react-native-web"), +}); +moduleAlias(); +``` + ## Other notes ### Safari flexbox performance