Write once, run anywhere with Create React (Native) App and react-native-web

Write once, run anywhere with Create React (Native) App and react-native-web  #javascript

  • AmazeSince the first release of React Native, I’ve always hoped to build a React codebase that could run on any platform.I loved building multi platform apps using Cordova and web technologies, but React Native has raised the bar so high now with its native performance.So far, when you wanted to…
  • buckd/; Ignore unexpected extra Ignore duplicate module providers; For RN Apps installed via npm, “Libraries” folder is inside; “node_modules/react-native” but in the source repo it is in the Additional create-react-native-app ignores; Ignore duplicate module Ignore misbehaving Ignore missing expo-sdk dependencies (temporarily); Ignore react-native-fbads dependency of the expo – “expo”: {…
  • /src/App’export default class NativeApp extends React.Component { render() { return App / }}Let’s make a few changes to our package.json file and add some useful scripts// These scripts are merely copied from the create-react-native-app package.json file…”main”: { “start-web”: “react-scripts start”, “build-web”: “react-scripts build”, “test”: “react-scripts test –env=jsdom”, “eject-web”: “react-scripts eject”,…
  • js and add some platform agnostic code in it.You can now write all your code as if you were writing some React Native code.The trick here is that the webpack config of Create React App aliases automatically react-native to react-native-web (see the config here).
  • Everything is handled for us!import React, { Component } from ‘react’import { View, Text, StyleSheet } from ‘react-native’export default class App extends Component { render() { return ( View style={styles.app} View style={styles.appHeader} Text style={styles.appTitle}Welcome to React ⚛️/Text /View Text style={styles.appIntro} To get started, edit src/App.

Since the first release of React Native, I’ve always hoped to build a React codebase that could run on any platform. I loved building multi platform apps using Cordova and web technologies, but React…

Write once, run anywhere with Create React (Native) App and react-native-webaka when the tools exist … compose them!Wow! So engineering! Much platform! AmazeSince the first release of React Native, I’ve always hoped to build a React codebase that could run on any platform.I loved building multi platform apps using Cordova and web technologies, but React Native has raised the bar so high now with its native performance.So far, when you wanted to have a unified codebase of the Web and Native, you had to mess around with build systems (Webpack and React Native packager) in order to make everything work together.Now with Create React Native App and Create React App, we do not have to worry about this layer of complexity.I’ll guide you through the steps needed to have one codebase that runs anywhere!Phase 1 : The dirty workYou’ll need :the latest version of Node (when I wrote this post, it was 8.6.0)create-react-appFirst, create a React app using :create-react-app my-hybrid-app cd my-hybrid-appWe need to add a few dependencies to our project :npm install –save-dev babel-preset-expo jest-expo flow-bin react-native-scripts install –save expo@^21.0.2 react react-native@^0.48.4 react-native-webNow let’s add a few files necessary to build a React Native app :{ “presets”: [“babel-preset-expo”], “env”: { “development”: { “plugins”: “transform-react-jsx-source”] } }}{}[ignore]; We fork some components by platform.*/*[.]android.js; Ignore “BUCK” generated dirsPROJECT_ROOT/\.buckd/; Ignore unexpected extra Ignore duplicate module providers; For RN Apps installed via npm, “Libraries” folder is inside; “node_modules/react-native” but in the source repo it is in the Additional create-react-native-app ignores; Ignore duplicate module Ignore misbehaving Ignore missing expo-sdk dependencies (temporarily);…

Write once, run anywhere with Create React (Native) App and react-native-web