Giter Club home page Giter Club logo

react-cordova-boilerplate's Introduction

Build Status Dependency Status devDependency Status npm version

React Cordova boilerplate

Demo - click the image to try it

Why cordova and React

Cordova is really simple to build cross platform mobile applications for any of your needs, this boilerplate provides a great starting point for your next react project, and can be used to maintain a website and mobile application from same source code (and maybe transitioning later to react-native).
I highly advise to check out my other boilerplate, which is similar in many ways but produces a native app.

Features

  • eslint
  • Smart build using Webpack 2
    • ES6
    • React (jsx)
    • Server rendering for initial page
    • Style: Radium + SASS
  • React router
  • Testing
    • Mocha
    • jsdom (blazing fast testing on nodeJs)
    • Sinon
    • Chai
    • Coverage using nyc

Installing

  1. Install dependencies: npm i or yarn install
  2. Install global tools: npm install -g cordova
  3. Add your cordova platform by running cordova platform add %PLATFORM% (android and more)

Usage

  • npm run lint[:report] - runs linting against src folder and fix some of the issues, report option to generate html report to ./report.html.
  • npm run start[:prod] - starts a server, with react model replacement and devtools on localhost:8080, prod option to minify the build (same build eventually integrated with the cordova app).
  • npm run build[:prod][:watch] - builds the project (single html file and single js file) as it does for development.
  • npm run test[:watch][:coverage] - runs Mocha testing, outputs result to console, watch options to watch files and test again after file modification, coverage option to generate coverage reports to ./coverage folder (index.html is a usuful one!).

Build and run as application

As you do with any cordova application, cordova build android, cordova run android and more.

cordova runs npm run build:prod before any cordova command (using hooks).

Style practice

To style your html, simply inline style your DOM (here is why).

You can use Radium (which is included) to easily add 'css like' event listeners to your components (like hover).

Sass/CSS is included to complete some of the missing features or already written style you want to use. To use Sass/CSS simply import that file!

custom-font.scss

@font-face {
	font-family: 'custom-font';
	src:url('./custom-font.eot') format('embedded-opentype'),
		url('./custom-font.ttf') format('truetype'),
		url('./custom-font.woff') format('woff'),
		url('./custom-font.svg') format('svg');
	font-weight: normal;
	font-style: normal;
}
.customFont {
  font-family: 'custom-font';  
  &.customFontIcon {
    content: "\e600";
    &:hover {
      color: blue;
    }
  }
}

ExampleComponent.jsx

import React, { Component } from 'react';
import customFont from './custom-font.scss'

export default class ExampleComponent extends Component {
  render() {
    return (
      <div style={{backgroundColor: 'red'}}>
        Hello world!
        <span className={customFont.customFont + ' ' + customFont.customFontIcon}></span>
      </div>
      );
  }
}

Advantages:

  • Complete styling ability to go with inline style.
  • Easily use third party styles.
  • No globals - import style files and use the class (minifies signature - example .a instead of .customFont)

Sass style will be minified, bundled and included to the server rendered file.

Troubleshooting

  • Node Sass could not find a binding for your current environment: OS X 64-bit with Node.js X.x If you get an error like this means you previously installed Node SASS in an older version of Node which no longer applies to you. To fix run npm rebuild node-sass

react-cordova-boilerplate's People

Contributors

adi518 avatar farhadg avatar fulla avatar iammathew avatar marissa27 avatar sam3k avatar unimonkiez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-cordova-boilerplate's Issues

is cordova truly integrated with react?

I'm trying out to integrate cordova and react, and the issue i'm running into is that, this react app is compiled beforehand and then handed to cordova. Which means using plugins like the device plugin is not possible? device.platform in any react component gives me undefined and breaks the build.

How am I supposed to use Cordova's power to talk to the device from my react components?

How to add Cordova-Plugins

Hey guys,

how i can add Cordova-Plugins and use them :?
Because even if i installed them the console says, that for example FCMPlugin isnt defined.
How can i fix that?

How to integrate React-Big-Calendar

Hey dear Community,

everyday i get a little forward with my app ^^ Today i want to add the Calendar and found react-big-calendar (a FullCalendar synonym for React). I installed it properly and added it to the Calendar-Page.

One thing i didnt managed to do is to give it the appropiate style ^^

In normal cases i can use like TESTCSS[testclass] to give the object the corresponding css.
But since this is a Package i dont managed to do it.

Here is the Container, where i build the Calendar (LINK)

Thanks for any help in advance

Unit tests not working

To run unit tests need to run in command line - npm run test.
Should output successful and failed unit tests, instead it always writes this -

~/dev/react-cordova-boilerplate master* 24s
❯ npm run test

> [email protected] test /home/uv/dev/react-cordova-boilerplate
> node ./bin/test.js

28 03 2017 14:54:18.403:ERROR [preprocess]: Can not load "sourcemap", it is not registered!
  Perhaps you are missing some plugin?
(node:28777) DeprecationWarning: loaderUtils.parseQuery() received a non-string value which can be problematic, see https://github.com/webpack/loader-utils/issues/56
parseQuery() will be replaced with getOptions() in the next major version of loader-utils.
28 03 2017 14:54:26.491:INFO [karma]: Karma v1.5.0 server started at http://0.0.0.0:9876/
28 03 2017 14:54:26.492:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
28 03 2017 14:54:26.493:ERROR [karma]: Found 1 load error
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test: `node ./bin/test.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] test script 'node ./bin/test.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the react-cordova-boilerplate package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node ./bin/test.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs react-cordova-boilerplate
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls react-cordova-boilerplate
npm ERR! There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/uv/.npm/_logs/2017-03-28T11_54_26_636Z-debug.log

npm run start fails

Calling npm run start fails with the message below:

npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
npm info prestart [email protected]
npm info start [email protected]

> [email protected] start /Users/tommy/src/devgeeks/react-cordova-boilerplate
> better-npm-run start

env: node\r: No such file or directory

npm info [email protected] Failed to exec start script
npm ERR! Darwin 14.4.0
npm ERR! argv "/Users/tommy/.nvm/versions/node/v0.12.2/bin/node" "/Users/tommy/.nvm/versions/node/v0.12.2/bin/npm" "run" "start"
npm ERR! node v0.12.2
npm ERR! npm  v2.7.4
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: `better-npm-run start`
npm ERR! Exit status 127
npm ERR! 
npm ERR! Failed at the [email protected] start script 'better-npm-run start'.
npm ERR! This is most likely a problem with the react-cordova-boilerplate package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     better-npm-run start
npm ERR! You can get their info via:
npm ERR!     npm owner ls react-cordova-boilerplate
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/tommy/src/devgeeks/react-cordova-boilerplate/npm-debug.log

And this is the contents of npm-debug.log:

0 info it worked if it ends with ok
1 verbose cli [ '/Users/tommy/.nvm/versions/node/v0.12.2/bin/node',
1 verbose cli   '/Users/tommy/.nvm/versions/node/v0.12.2/bin/npm',
1 verbose cli   'run',
1 verbose cli   'start' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info prestart [email protected]
6 info start [email protected]
7 verbose unsafe-perm in lifecycle true
8 info [email protected] Failed to exec start script
9 verbose stack Error: [email protected] start: `better-npm-run start`
9 verbose stack Exit status 127
9 verbose stack     at EventEmitter.<anonymous> (/Users/tommy/.nvm/versions/node/v0.12.2/lib/node_modules/npm/lib/utils/lifecycle.js:213:16)
9 verbose stack     at EventEmitter.emit (events.js:110:17)
9 verbose stack     at ChildProcess.<anonymous> (/Users/tommy/.nvm/versions/node/v0.12.2/lib/node_modules/npm/lib/utils/spawn.js:14:12)
9 verbose stack     at ChildProcess.emit (events.js:110:17)
9 verbose stack     at maybeClose (child_process.js:1015:16)
9 verbose stack     at Process.ChildProcess._handle.onexit (child_process.js:1087:5)
10 verbose pkgid [email protected]
11 verbose cwd /Users/tommy/src/devgeeks/react-cordova-boilerplate
12 error Darwin 14.4.0
13 error argv "/Users/tommy/.nvm/versions/node/v0.12.2/bin/node" "/Users/tommy/.nvm/versions/node/v0.12.2/bin/npm" "run" "start"
14 error node v0.12.2
15 error npm  v2.7.4
16 error code ELIFECYCLE
17 error [email protected] start: `better-npm-run start`
17 error Exit status 127
18 error Failed at the [email protected] start script 'better-npm-run start'.
18 error This is most likely a problem with the react-cordova-boilerplate package,
18 error not with npm itself.
18 error Tell the author that this fails on your system:
18 error     better-npm-run start
18 error You can get their info via:
18 error     npm owner ls react-cordova-boilerplate
18 error There is likely additional logging output above.
19 verbose exit [ 1, true ]

How to import non CommonJS JavaScript?

I need to include a non CommonJS third party library which I am able to include by dropping the file in the root of the project; and then adding <script src="someGlobalLogic.min.js"></script> in src/index.ejs.

This works on the browser but when compiling and previewing in Android, the following error occurs:

HTML Webpack Plugin > Reference Error: someThirdPartyVar is not defined

Any suggestions?

www folder should not be commited

www folder (bin files) is commited to the git, to be used later in gh-pages.
Should change npm run deploy so the folder will only be commited in the branch and not in master branch.

How to work with Cordova Plugins

Is there a way to use Cordova plugins with this boilerplate?
For example, I'm trying to see if I can have push notifications with this todoMVC.
Here's the link to the plugin: https://github.com/phonegap/phonegap-plugin-push

They also have an example of the implementation using cordova here: http://macdonst.github.io/push-workshop/module1.html
In their example at module 2, they say to put the code in onDeviceReady function in index.js.

Where would it be appropriate to put these in the react boilerplate?

eslint errors

hi,
Enviroment:

  • VS Code: 1.10.2
  • react-cordova-boilerplate: 2.0.0
  • vscode-eslint:: 1.2.7
  • eslint: 3.10.10

while using the latest version of react-cordova-boilerplate , out of the box without any changes, getting on VS Code the following errors:

Cannot read config file: c:\projects\banking-app-cordova-react\bin\webpack-eslint.js
Error: Could not locate the bindings file.
Tried: → c:\projects\banking-app-cordova-react\node_modules\deasync\build\deasync.node
→ c:\projects\banking-app-cordova-react\node_modules\deasync\build\Debug\deasync.node
→ c:\projects\banking-app-cordova-react\node_modules\deasync\build\Release\deasync.node
→ c:\projects\banking-app-cordova-react\node_modules\deasync\out\Debug\deasync.node → c:\projects\banking-

image

Integrate Material-ui

Hi, thx for sharing this boilerplate. can anyone write ana implementation with material-ui or react-bootstrap ?

clean install, constant errors in the console, but app works

After a clean download of the repo, npm install and npm start... it "works" correctly but there are continual errors in the console.

GET http://localhost/info?t=1449285338378 net::ERR_CONNECTION_REFUSED
[WDS] Disconnected!

The URL being used in the failed GET is "localhost" but missing the port. And nothing is listening for that request. I can't figure out where the issue was coming from.

Simpler version

Hi, thanks for the boilerplate!
I was wondering since I'm recently starting with React and I'm not using Redux for the current project, how could I get a simpler boilerplate?
I'm talking specifically about all the actions, containers, etc. (Sadly AppRouter and App are entangled in there with other containers)

Also, why two entry points for webpack? I'm trying to understand why do I need both Client and Server entry points for just a Cordova app. Do I need both of them just for a simple app?

how to use images with the boilerplate?

hi,
i am putting a png file inside: '/resources' and referencing the file in this way:

<img style={titlebarImage} src='resources/device-titlebar.jpg'/>

while running npm start and check it in the web, using chrome, it runs OK.
while running:

npm run build
cordova run android

app loads to the android studio emulator, but images are not loaded.
when inspecting with chrome i see this error:

file:///android_asset/www/resources/device-titlebar.jpg Failed to load resource: net::ERR_FILE_NOT_FOUND

i cannot find any android_asset folder being created.

Node Sass could not find a binding for your current environment

ERROR in .//css-loader!.//resolve-url-loader?{"fail":true}!./~/sass-loader/lib/loader.js!./src/style/custom-font.scss
Module build failed: Error: Missing binding /Users/Me/Projects/my_app/node_modules/node-sass/vendor/darwin-x64-48/binding.node
Node Sass could not find a binding for your current environment: OS X 64-bit with Node.js 6.x

Found bindings for the following environments:

  • OS X 64-bit with Node.js 5.x

This usually happens because your environment has changed since running npm install.
Run npm rebuild node-sass --force to build the binding for your current environment.
at module.exports (/Users/Me/Projects/my_app/node_modules/node-sass/lib/binding.js:15:13)
at Object. (/Users/Me/Projects/my_app/node_modules/node-sass/lib/index.js:14:35)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (/Users/Me/Projects/my_app/node_modules/sass-loader/lib/loader.js:3:14)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
@ ./src/style/custom-font.scss 4:14-186 13:2-17:4 14:20-192
@ ./src/containers/login.jsx
@ ./src/containers/app-route.jsx
@ ./src/entry-points/client.jsx
@ multi webpack-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/entry-points/client.jsx

ERROR in .//css-loader!.//resolve-url-loader?{"fail":true}!./~/sass-loader/lib/loader.js!./src/style/todo-style.scss
Module build failed: Error: Missing binding /Users/Me/Projects/my_app/node_modules/node-sass/vendor/darwin-x64-48/binding.node
Node Sass could not find a binding for your current environment: OS X 64-bit with Node.js 6.x

Found bindings for the following environments:

  • OS X 64-bit with Node.js 5.x

This usually happens because your environment has changed since running npm install.
Run npm rebuild node-sass --force to build the binding for your current environment.
at module.exports (/Users/Me/Projects/my_app/node_modules/node-sass/lib/binding.js:15:13)
at Object. (/Users/Me/Projects/my_app/node_modules/node-sass/lib/index.js:14:35)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (/Users/Me/Projects/my_app/node_modules/sass-loader/lib/loader.js:3:14)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
@ ./src/style/todo-style.scss 4:14-185 13:2-17:4 14:20-191
@ ./src/containers/todo-app.jsx
@ ./src/containers/app-route.jsx
@ ./src/entry-points/client.jsx
@ multi webpack-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/entry-points/client.jsx

Unpin react version

In my pull request #12 I've pinned the version of react and react-dom to 15.3, because version 15.4 break tests (as travis CI).
After facebook fixes the issue facebook/react#8314, it will be necessary to unpin the version so the repo continues using latest version

Unable to add platforms in cordova

Hi, I'm trying to use this npm package and I can't add packages using "cordova platform add "
I have included the error message I receive below. Thanks for your package and any help you can provide

npm ERR! Darwin 14.5.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build:cordova"
npm ERR! node v4.0.0
npm ERR! npm v2.14.2
npm ERR! code ELIFECYCLE
npm ERR! [email protected] build:cordova: webpack -c
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build:cordova script 'webpack -c'.
npm ERR! This is most likely a problem with the react-cordova-boilerplate package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! webpack -c
npm ERR! You can get their info via:
npm ERR! npm owner ls react-cordova-boilerplate
npm ERR! There is likely additional logging output above.

How ToDoApp gets the todos

Hey dear community :)

I need a little bit of help:
The ToDoApp takes as prop todos (i guess from store).
But i dont find from where it gets this prop?

Any help?

Login page is not server rendered on production dev server

running npm run start:prod serves index.html but without login page pre-rendered there.
Here is the content -

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>TodoMVC app</title>
  <script src="cordova.js"></script>
</head>
<body>
  <div id="app">
    
  </div>
<script type="text/javascript" src="app.min.js"></script></body>
</html>

Here are the expected content (as produced by npm run build:prod) -

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>TodoMVC app</title>
  <script src="cordova.js"></script>
<link href="app.min.css" rel="stylesheet"></head>
<body>
  <div id="app">
    <div data-reactroot="" data-reactid="1" data-react-checksum="1366081669"><div style="position:fixed;left:0;top:0;width:100%;height:100%;text-align:center;background-color:#F7DF1E;color:black" data-reactid="2"><div style="position:relative;top:50%;transform:translateY(-50%)" data-reactid="3"><div data-reactid="4"><span class="tpJdUoGgIZVGQWKpIcyGt _1ZoB4ANsZJx_40KTyB6OTX" style="font-size:200px" data-reactid="5"><span class="_3Ilvhfs8Ya99e5XovM7gsx" data-reactid="6"></span><span class="_1OKxmoaQuP81R7zk2D1aEU" data-reactid="7"></span></span><h1 data-reactid="8">TodoMVC example</h1></div><div style="max-height:0px;overflow:hidden;transition:max-height 0.5s ease-in-out" data-reactid="9"><h1 style="margin:0px;padding:20px 0" data-reactid="10">Login</h1><form style="width:200px;margin:auto" data-reactid="11"><div style="padding-top:5px" data-reactid="12"><input type="text" placeholder="Email" style="width:100%;height:25px" data-reactid="13"></div><div style="padding-top:5px" data-reactid="14"><input type="password" placeholder="Password" style="width:100%;height:25px" data-reactid="15"><div style="height:1em;color:#383838;font-weight:400" data-reactid="16"></div></div><div style="padding-top:5px" data-reactid="17"><button type="submit" style="width:100%;height:25px" data-reactid="18">Login</button></div></form></div></div></div></div>
  </div>
<script type="text/javascript" src="app.min.js"></script></body>
</html>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.