Real React Native on Web Platform
Install:
First initialize your react-native project
react-native init MyProjectcd MyProject
Install this module.
yarn add react-native-web-platform
Configure your rn-cli.config.js to add web platform & provideModuleNodeModules:
'use strict'; const config = // Add these lines if you already have a rn-cli.config.js { return 'web'; } { return 'react-native' 'react-native-web-platform' ; }; moduleexports = config;
Add a launch.web.js and index.html in your project root:
// launch.web.js // Install polyfills in native thread.;;;const Bridge = ; const bridge = __DEV__ ? './index.bundle?platform=web' : './index.bundle.js'; bridgestart; bridge;
Note: if your react native version <= 0.48.x, use following instead:
// launch.web.jsconst Bridge = ; const bridge = __DEV__ ? './index.web.bundle?platform=web' : './index.bundle.js'; bridgestart; bridge;
index.html:
YOUR_APP_NAME_HERE
index.release.html:
YOUR_APP_NAME_HERE
If your react native version <= 0.48.x, you should also create a index.web.js
with the content like index.ios.js
or index.android.js
:
Debug
npm start
Then visit http://localhost:8081/index.html to visit your page.
Publish
version >= 0.49.x:
Linux & Mac:
mkdir buildmkdir build/webreact-native bundle --entry-file launch.web.js --platform web --dev false --bundle-output build/web/launch.bundle.js --assets-dest build/webreact-native bundle --entry-file index.js --platform web --dev false --bundle-output build/web/index.bundle.js --assets-dest build/webcp index.release.html build/web/index.html
Windows:
md buildmd build\webreact-native bundle --entry-file launch.web.js --platform web --dev false --bundle-output build/web/launch.bundle.js --assets-dest build/webreact-native bundle --entry-file index.js --platform web --dev false --bundle-output build/web/index.bundle.js --assets-dest build/webcopy index.release.html build\web\index.html
version <= 0.48.x
Linux & Mac:
mkdir buildmkdir build/webreact-native bundle --entry-file launch.web.js --platform web --dev false --bundle-output build/web/launch.bundle.js --assets-dest build/webreact-native bundle --entry-file index.web.js --platform web --dev false --bundle-output build/web/index.bundle.js --assets-dest build/webcp index.release.html build/web/index.html
Windows:
md buildmd build\webreact-native bundle --entry-file launch.web.js --platform web --dev false --bundle-output build/web/launch.bundle.js --assets-dest build/webreact-native bundle --entry-file index.web.js --platform web --dev false --bundle-output build/web/index.bundle.js --assets-dest build/webcopy index.release.html build\web\index.html
Then publish everything in build/web
into your server.