How to Integrate react-native-web in an existing react native application
August 13, 2021
For using react native on web we can use the template of many build tools. I would like to use Create React App for this example.
Please make sure to execute all the commands mentioned below in the root directory.
Install required packages for web
yarn add react-native-web react-dom
or npm install react-native-web react-dom
dev dependencies
yarn add --dev react-scripts babel-jest
or npm install --save-dev react-scripts babel-jest
Create project structure
1. Create public/
folder in root directory
mkdir public
- Create a html file and add basic html
touch index.html
- Create
manifest.json
file to make it Progressive Web App
touch manifest.json
2. Create src/
directory in root folder
- Create serviceWorker.js for PWA
A progressive web application is a type of application software delivered through the web, built using common web technologies including HTML, CSS and JavaScript.
Download serviceWorker.js from the link serviceWorker.js
- Create index.js file
Update script tag
Add
"web": "react-scripts start"
in package.json
inside scripts
tag
Execute npm run web
or yarn web
and it should start developer server at http://localhost:3000
References
- https://necolas.github.io/react-native-web/docs/?path=/docs/guides-multi-platform--page
- https://callstack.github.io/react-native-paper/using-on-the-web.html