Skip to content
A require.js plugin that allows you to use JSX files as require.js dependencies.
JavaScript
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md
jsx.js
package.json

README.md

require-jsx

A RequireJS plugin for JavaScript files containing JSX.

It can be used to load JS source file that contain JSX code. This is helpful when using React with RequireJS.

Install

Download the plugin here

Place this in the directory that is your baseUrl for your project, or set up a paths config for it for the module ID jsx.

Usage <a name="usage".

First, you need to configure RequireJS to use Facebook's JSXTransformer which also is in React:

require.config({
    deps: ["main"],
    
    paths: {
        jsx: "../lib/jsx",
        JSXTransformer: '../lib/JSXTransformer'
    },
    
    shim: {
        JSXTransformer: {
            exports: "JSXTransformer"
        }
    }
});

Then, you can reference JSX files via the jsx! plugin syntax. For example, to load the router.js file that is in your app directory:

require(['jsx!app/router'], function (Router) {
    
});

The Plugin is then going to load the JavaScript source file app/router.js, parse it with Facebook's JSXTransformer and execute the resulting JavaScript source.

You can’t perform that action at this time.