• Stars
    star
    104
  • Rank 319,811 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 10 years ago
  • Updated over 8 years ago

Reviews

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

Repository Details

A RequireJS plugin for loading jsx in development and compiling (with r.js). Supports bundling and 1:1 source maps in development and production.

requirejs-react-jsx

NPM version Dependency Status

A RequireJS plugin for compiling React JSX files. Will use react-tools when compiling using r.js, and will use JSXTransformer or Babel when running in the browser in development. This allows us to support multiple bundles in r.js and exclude the JSXTransformer from all of them since we're requiring it dynamically and not explicitly. This also means that we can get 1:1 Source Maps in both development and production.

Example

http://i.imgur.com/upv8B0g.png

Install

$ bower install requirejs-react-jsx --save

If you're not using bower to manage your dependencies (you should), you can just download the jsx.js file manually.

Since we're also using react-tools for the build step while running in a node process, and not in the browser, you will need to install that also:

$ npm install react-tools --save

Usage

Setup

app.jsx

define(function(require){

  var React = require('react');

  function App() {
    this.AppView = React.createClass({
      render: function () {
        return (
          <div>
            <p>Hello, React!</p>
          </div>
        );
      }
    });
  }

  App.prototype.init = function () {
    React.render(<this.AppView />, document.body);
  };

  return App;

});

main.js

require.config({
  paths: {
    "react": "bower_components/react/react-with-addons",
    "babel": "bower_components/requirejs-react-jsx/babel-5.8.34.min",
    "jsx": "bower_components/requirejs-react-jsx/jsx",
    "text": "bower_components/requirejs-text/text"
  },

  shim : {
    "react": {
      "exports": "React"
    }
  },

  config: {
    babel: {
      sourceMaps: "inline", // One of [false, 'inline', 'both']. See https://babeljs.io/docs/usage/options/
      fileExtension: ".jsx" // Can be set to anything, like .es6 or .js. Defaults to .jsx
    }
  }
});

require(['jsx!app'], function(App){

  var app = new App();
  app.init();

});

Building

Call with $ node bower_components/r.js/dist/r.js -o build.js

In your r.js build.js config:

// add `optimize=none` to skip script optimization (useful during debugging).

({
  appDir: "./",
  baseUrl: "./",
  dir: "./compiled",
  mainConfigFile: "./main.js",

  optimize: "uglify2",
  skipDirOptimize: true,
  generateSourceMaps: true,
  findNestedDependencies: true,
  preserveLicenseComments: false,

  onBuildWrite: function (moduleName, path, singleContents) {
    return singleContents.replace(/jsx!/g, '');
  },

  modules: [
    {
      name: "main",
      exclude: ['jsx']
    }
  ]
})

Istanbul Code Coverage

If you want code coverage with Istanbul you will have to do a little extra work. Istanbul only instruments code required by nodes require function by default. However, you can make Istanbul also instrument RequireJS loaded dependencies in a node environment by adding the --hook-run-in-context switch.

requirejs-react-jsx will automatically detect that it is being run in an Istanbul enabled environment and

The --hook-run-in-context only makes Istanbul pick up normally loaded RequireJS files though, and not the ones transformed by RequireJS plugins. So requirejs-react-jsx will automatically detect that it is being run in an Istanbul enabled environment and manually instrument the transpiled code so Istanbul can collect coverage.

A full example of a coverage script in package.json could look like this:

{
  "scripts": {
    "test": "mocha",
    "coverage": "istanbul cover --hook-run-in-context _mocha"
  }
}

Changelog

1.0 - Eliminated all other transformer options than Babel. Switched config variable from jsx to babel. Added browser compatible babel 5.x build to repository to use for in-browser compilations

License

MIT

More Repositories

1

jquery-mentions-input

JavaScript
984
star
2

ios-view-frame-builder

A small library for semantic layout of UIViews.
Objective-C
383
star
3

valideer

Lightweight data validation and adaptation Python library.
Python
264
star
4

podio-rb

The official Ruby wrapper for the Podio API used and maintained by the Podio team
Ruby
66
star
5

podio-py

Podio Python client
Python
48
star
6

podio-js

Official Podio JavaScript SDK for node and the browser
JavaScript
45
star
7

podio-objc

PodioKit is the Objective-C client library for the Podio API.
Objective-C
26
star
8

podio-dotnet

Podio .NET client
C#
19
star
9

podio_rails_sample

Sample Rails project with authentication and item read/create
Ruby
18
star
10

podio-java

The Java client for the Podio API. This will be a full mapping of the Podio API to an easy to use Java library.
Java
18
star
11

istanbul-react

Instrumenter for 1:1 mapping of React JSX components. Can be used with karma-coverage
JavaScript
12
star
12

podio-android

The Android SDK for the Podio API.
Java
9
star
13

sample-basecamp

Ruby
9
star
14

sample-dropbox

Downloads files from Podio and uploads them to your dropbox. Done by the Team Dropbox!
Java
7
star
15

sample-jenkins

A plugin for Hudson that will post build results to an app in Podio. On failed builds tasks will be created for the relevant users.
Java
7
star
16

asp-net-sample

ASP.NET MVC example of using Podio
C#
6
star
17

conssert

Content Assertion library for Python
Python
5
star
18

sample-alerts

Integration between Google Alerts and Podio
Java
4
star
19

platform-todo-app-tutorial

JavaScript
4
star
20

plugin-jst

JST loader plugin
JavaScript
2
star
21

sample-flask

JavaScript
2
star
22

sample-twitter

Example of integration between Podio and Twitter built on the Podio API and it's Java client
Java
2
star
23

node-requirejs

Lets you use you requirejs configuration in Node
JavaScript
1
star
24

work_quest_frontend

WorkQuest frontend
Ruby
1
star
25

integration-zendesk

An incomplete Java interface to the Zendesk API
Java
1
star
26

sample-delicious

Simple importer that will parse RSS feeds from delicious and post them in an app in Podio.
Java
1
star
27

openpyxl

copy of https://bitbucket.org/hlmrn/openpyxl@a00915cc57bd89086fd0a2ffa52436f5abe0fdbd
Python
1
star