podio / requirejs-react-jsx

A RequireJS plugin for loading jsx in development and compiling (with r.js). Supports bundling and 1:1 source maps in development and production.
MIT License
104 stars 20 forks source link

Babel in browser - update readme #16

Open cguinnup opened 8 years ago

cguinnup commented 8 years ago

Not sure if this is intended behavior, but the README is not clear that "JSXTransformer" must be pointed to Babel's browser.js for browser-based Babel transformation to work:

paths: {
...
JSXTransformer: libPath + 'babel/dist/browser',
...
}

This is necessary since React deprecated & removed JSXTransformer.

ericjang commented 8 years ago

I get a Cannot read property 'transformer' of undefined:

Uncaught Error: Load timeout for modules: jsx!app_unnormalized2,jsx!app
http://requirejs.org/docs/errors.html#timeoutmakeError @ require.js?v=2de44fdcc1fe5e939aa4ce80626b241d:165checkLoaded @ require.js?v=2de44fdcc1fe5e939aa4ce80626b241d:693(anonymous function) @ require.js?v=2de44fdcc1fe5e939aa4ce80626b241d:714
cguinnup commented 8 years ago

My full config is:

require.config({
    paths: {
        react:          libPath + 'react-with-addons',
        JSXTransformer: libPath + "babel/browser",
        jsx:            libPath + "jsx",
        text:           libPath + 'text',
    },

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

    config: {
        jsx: {
            transformer: 'babel',
            babelOptions: {
                sourceMaps: 'inline'
            }
        }
    }
});

require(['jsx!main'], function(Main) {
});

Where 'jsx' is in fact this lib (requirejs-react-jsx), and all libs are at their latest version (as of a week or two ago). Note that my paths dirs are custom, and won't match the structure you find using NPM etc.

I've confirmed that main.jsx renders React elements successfully.

ericjang commented 8 years ago

Just so I can reproduce your build environment as accurately as possible, what are your bower.json version entries for babel, requirejs-react-jsx, react? Also, the babel website suggested to me that I use requirejs-babel - should I be using the npm-based installation of babel instead?

cguinnup commented 8 years ago

Not using Bower, because integrating into a larger project which uses a non-JS-specific build system.

Versions: React (with addons) v0.14.3 Babel 6.1.18 RequireJS 2.1.21 RequireJS text 2.0.12

Yes, I just used browser.js from the main babel installation.

cguinnup commented 8 years ago

I should also note that I'm running this in a Java 8 WebView (inside a Swing component), so I can't be certain it's cross-browser compatible, just that it works in my case.