From 93fed1a459c420275fce28ca26cd7d28202689a5 Mon Sep 17 00:00:00 2001 From: Andrey Popp <8mayday@gmail.com> Date: Tue, 29 Apr 2014 21:55:06 +0400 Subject: [PATCH] Add basic CommonJS example with browserify --- examples/basic-commonjs/README.md | 7 +++++++ examples/basic-commonjs/index.html | 29 ++++++++++++++++++++++++++++ examples/basic-commonjs/index.js | 25 ++++++++++++++++++++++++ examples/basic-commonjs/package.json | 14 ++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 examples/basic-commonjs/README.md create mode 100644 examples/basic-commonjs/index.html create mode 100644 examples/basic-commonjs/index.js create mode 100644 examples/basic-commonjs/package.json diff --git a/examples/basic-commonjs/README.md b/examples/basic-commonjs/README.md new file mode 100644 index 0000000000..bd9d2499fa --- /dev/null +++ b/examples/basic-commonjs/README.md @@ -0,0 +1,7 @@ +# Basic example of using React with Browserify + +Run `npm install` in the directory to install React from npm. Then run: + + ./node_modules/.bin/browserify --debug --transform reactify ./index.js > ./bundle.js + +to produce `bundle.js` with example code and React. diff --git a/examples/basic-commonjs/index.html b/examples/basic-commonjs/index.html new file mode 100644 index 0000000000..12cb51a375 --- /dev/null +++ b/examples/basic-commonjs/index.html @@ -0,0 +1,29 @@ + + + + + Basic CommonJS Example with Browserify + + + +

Basic CommonJS Example with Browserify

+
+

+ To install React, follow the instructions on + GitHub. +

+

+ If you can see this, React is not working right. + If you checked out the source from GitHub make sure to run grunt. +

+
+

Example Details

+

This is written with JSX in a CommonJS module and precompiled to vanilla JS by running:

+
browserify --debug --transform reactify index.js > bundle.js
+

+ Learn more about React at + facebook.github.io/react. +

+ + + diff --git a/examples/basic-commonjs/index.js b/examples/basic-commonjs/index.js new file mode 100644 index 0000000000..9344c32cdd --- /dev/null +++ b/examples/basic-commonjs/index.js @@ -0,0 +1,25 @@ +/** + * @jsx React.DOM + */ + +var React = require('react'); + +var ExampleApplication = React.createClass({ + render: function() { + var elapsed = Math.round(this.props.elapsed / 100); + var seconds = elapsed / 10 + (elapsed % 10 ? '' : '.0' ); + var message = + 'React has been successfully running for ' + seconds + ' seconds.'; + + return

{message}

; + } +}); + +var start = new Date().getTime(); + +setInterval(function() { + React.renderComponent( + , + document.getElementById('container') + ); +}, 50); diff --git a/examples/basic-commonjs/package.json b/examples/basic-commonjs/package.json new file mode 100644 index 0000000000..d72927a431 --- /dev/null +++ b/examples/basic-commonjs/package.json @@ -0,0 +1,14 @@ +{ + "name": "react-basic-commonjs-example", + "description": "Basic example of using React with CommonJS", + "main": "index.js", + "devDependencies": { + "envify": "~1.2.1", + "react": "~0.10.0", + "reactify": "~0.13.1", + "browserify": "~3.44.2" + }, + "scripts": { + "build": "browserify --debug --transform reactify index.js > bundle.js" + } +}