• Stars
    star
    138
  • Rank 256,432 (Top 6 %)
  • Language
    JavaScript
  • Created about 7 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A complete webpack configuration for react-native-web, optimized for both development and production

React Native for Web - Example App

This is a boilerplate React Native app with react-native-web installed and configured.

Features

  • index.html as an EJS template
  • Code-splitting
    • Saves time during development, saves bandwidth during updates
  • Offline Plugin
    • Caches all of your assets so your app works without an internet connection

Coming soon:

  • Pre-rendering as static HTML
  • react-hot-loader
  • Script to deploy your build to AWS S3, and optionally clear your CloudFlare cache

Note: This boilerplate project only contains an example webpack configuration for React Native Web. You should merge this into your favorite React Native starter project.

iOS and Android

Use the default React Native Packager for iOS and Android:

Script Description
react-native start Starts React Native Packager
react-native run-ios Runs the iOS app
react-native run-android Runs the Android app

Web

react-native-web does not use the React Native Packager, so you need to use webpack to compile your app. This example app contains a complete webpack configuration that is optimized for development and production.

Script Description
npm run web Starts the development server on port 3000.
npm run web:build:vendor-dev Builds the react-native-web library for development.
(The web task will automatically run this if it does not exist.)
npm run web:build Builds your app for production.
(Runs web:build:vendor and web:build:app.)
npm run web:build:vendor Builds the react-native-web library for production.
npm run web:build:app Builds your app, and any implicit vendored libraries.
npm run web:serve Serves the production build on port 3001.
npm run web:clean Deletes all generated files.

Note: If you haven't changed any libraries in vendor.webpack.config.js, you can run npm run web:build:app to just compile your app's source code. npm run web:build will recompile everything.

index.html

Your index file is generated from a template at web/templates/index.ejs. You can add variables to the HTMLWebpackPlugin config in web/webpack.config.js, and use these variables in the template.

Examples:

In web/webpack.config.js:

  new HtmlWebpackPlugin({
    filename: 'index.html',
    template: 'web/templates/index.ejs',
    myVariable: 'foo',
  }),

In web/templates/index.ejs:

<div><%= htmlWebpackPlugin.options.myVariable %></div>

or:

<% if (htmlWebpackPlugin.options.myVariable) { %>
  <div><%= htmlWebpackPlugin.options.myVariable %></div>
<% } %>

See the HtmlWebpackPlugin README for more information.

Code Splitting

You can add any react-* and react-native-* libraries to the entry section in vendor.webpack.config.js. Webpack will compile these libraries separately, and link them with your app's code. (See the DllPlugin). This saves a lot of time during development, because you don't have to keep recompiling your static libraries. This also saves bandwidth when you release an update, because your users will only need to download the updated app bundle.

You can add multiple entry sections to vendor.webpack.config.js. I recommend creating another entry for "core" libraries that don't change very often, but are unrelated to react or react-native-web. In addition to the explicit vendoring in vendor.webpack.config.js, webpack will also create an implicitly vendored bundle, for any libraries in node_modules/.

Here is an example of what your build directory will look like:

javascript/
    vendor/
        lib-6b8747b211107409.js
        react-853080ae05a52a66.dll.js
    app-6b8747b211107409.js
  • lib.*.js is an implicitly vendored bundle, for all libraries in node_modules
  • react.*.dll.js contains react-native-web and all of it's dependencies
  • app.*.js is your app's source code.

Offline Plugin

If you want your app to be available offline, you can change this line at the top of web/webpack.config.js:

const enableOfflinePlugin = false

This will automatically configure a ServiceWorker (or AppCache) to download and cache all of your assets, so people will be able to use your app even if they don't have an internet connection.

The Offline Plugin will only be enabled in the production build.

More Repositories

1

turbo-sprockets-rails3

Speeds up your Rails 3 assets:precompile by only recompiling changed files, and only compiling once to generate all assets
Ruby
977
star
2

raspberry_picrowave

Microwave controlled via Raspberry Pi
C
159
star
3

dotfiles

dotfiles! Now for macOS
Shell
72
star
4

capistrano_deploy_lock

Lock a server during deploy, to prevent people from deploying at the same time.
Ruby
47
star
5

mac_airtag_to_mqtt

Fetches airtag data from ~/Library/Caches/com.apple.findmy.fmipcore/Items.data, creates MQTT entities in Home Assistant with location data
Ruby
46
star
6

assets_precompile_enforcer

Raises an exception if assets are missing from config.assets.precompile during development
Ruby
21
star
7

git-remove-debug

Remove debugging statements with a single command.
Ruby
19
star
8

goto_sleep

Because sometimes you look out the window and it's already 6am.
Ruby
16
star
9

octopus

Ruby class for reading Octopus card IDs (Hong Kong payment card system) on Linux
Ruby
13
star
10

rails_shell

Aliases, functions and tab completions for Rails development.
7
star
11

sessionproof

Non-interactive zero-knowledge proofs for any TLS sessions that use HTTP Signatures (work in progress)
6
star
12

quickscrollplus

Quickly scroll through anything on your iPhone. PDF paging. Initiate with two-finger or triple tap. Extended with 'tilt' scrolling feature.
Objective-C
6
star
13

reddit_username_finder

Finds Reddit Usernames
Ruby
4
star
14

ransack_chronic

Parses natural language queries with Chronic when searching time/date columns with Ransack
Ruby
4
star
15

youtube_jukebox

download youtube videos, convert them to mp3, and play them in a vlc playlist as they are processed
Ruby
4
star
16

mfp_scraper

Because MyFitnessPal is taking forever to open up their API.
Ruby
3
star
17

bundler_local_development

Ruby
3
star
18

rubyk8055

Ruby Wrapper for Vellman K8055 USB Experiment Interface
C
3
star
19

flat_control_panel

Provides octopus card (RFID) and HTTP access to unlock flat door, turn on lights, etc
Ruby
3
star
20

ios_replace_operator_with_balance

Replace Operator on iOS 4.x with current prepaid balance. (For PCCW)
Objective-C
3
star
21

disable_assets_logger

Stop asset requests from being logged in your terminal, during Rails development.
Ruby
3
star
22

linux_on_t20

Scripts for installing TinyCore Linux bootloaders on a Compaq Evo T20 thin client
Shell
3
star
23

home-assistant-config

Home Assistant YAML configuration files
Jinja
2
star
24

grocerygadgets_lcd_client

Grocery Gadget Client for use with a thin client PC, 20x2 LCD Screen and USB barcode scanner
Ruby
2
star
25

gedit_i18n_helper

Menu and keyboard shortcut for internationalizing strings in Rails templates.
Python
2
star
26

ndbroadbent.github.io

my blog on ruby, rails, linux, iphone, electronics
JavaScript
2
star
27

ios_cydia_themes

umbrella repository for custom iPhone ringtones and themes
Shell
2
star
28

mac_2fa_autopaste

Monitors Mac clipboard (shared with iOS) and automatically enters 2FA codes
Shell
2
star
29

flat_voice_commands

Java voice recognition controller with Sphinx4
Java
2
star
30

shell-fm_sinatra

Sinatra server to control shell.fm remotely
JavaScript
2
star
31

SwiftEvents

An iPhone app with a streamlined UI for quickly adding events to your Google Calendar.
1
star
32

arcanist-prompts

A thin wrapper around arcanist that prompts for each field instead of opening a message file in your editor
1
star
33

nyt-spelling-bee-ios-automation

Script to automate the Spelling Bee game in the New York Times Crossword app
JavaScript
1
star
34

SwiftSuperCrash

Crash POC
Swift
1
star
35

shell-fm_X2040_interface

Shell.FM interface for Pertelian X2040 LCD Screen
Ruby
1
star
36

cobol_examples

Playing around with COBOL
COBOL
1
star
37

dictionary_order_sort

Sort an array of strings with the same logic as `sort --dictionary-sort`
Ruby
1
star
38

localstorageshim-rails

Add localstorageshim.js to your Rails application
Ruby
1
star
39

geoexpat_notifier

Simple Rails 3 app to notify of any classifieds that match a filter on geoexpat.com
Ruby
1
star
40

linux_iphone_backup

Make backups of your iPhone on Linux
Shell
1
star
41

ios_flat_10c

iPhone app for controlling my apartment.
Objective-C
1
star
42

project_euler

My solutions to Project Euler problems in Ruby
Ruby
1
star
43

shell-fm_dsp420lcd

Displaying shell.fm track information on a DSP-420 LCD display (20x2 chars)
Ruby
1
star
44

rubyX2040

Ruby interface to the Pertelian X2040 LCD Display
Ruby
1
star
45

authlogic

A simple model based ruby authentication solution.
Ruby
1
star
46

xbmc_scripts

Scripts and cron jobs to automate XBMC
Ruby
1
star
47

airbrake

Reports exceptions to Airbrake
Ruby
1
star
48

premailer

Preflight for HTML email
Ruby
1
star