seiffert / require-jsx

A require.js plugin that allows you to use JSX files as require.js dependencies.
96 stars 17 forks source link

using requirejs.undef call seems to break this lib #10

Open ORESoftware opened 9 years ago

ORESoftware commented 9 years ago

hey there!

I tried Carvalho's jsx library and yours, and both seem to fail in a particular case and I am trying to figure out why.

I am trying to enable hot reloading with RequireJS, and using requirejs.undef seems to be the way to go.

I am able to get the hot reloading / hot swapping to work with RequireJS for .html files, and next up is JavaScript files.

The problem I have seems to boil down to this:

require(['jsx!one.js'],function(one){

//no problems

});

but when I want to reload a module like so, I get problems:

require.undef('jsx!one');

require([jsx!one.js],function(one){  //this line fails

//now we have problems, I get the classic React error: "SyntaxError: expected expression, got '<'"
//so it seems that the jsx transformer is not being reinvoked upon "reloading" the same file

});

I really am not sure why this is happening, but I do strongly believe that the jsx plugin and / or JSXTransformer is not being re-invoked when the same file is reloaded.

Does this make any sense? Do you think you could help me investigate while the JSXTransformer is not being re-invoked upon reloading a file with require([]) ?

ORESoftware commented 9 years ago

and here's the rub:

whereas the above with require fails, using define works!

             require.undef('jsx!two');
             define(['jsx!two'],function(file){
                    cb(null,file);
              });

so there seems to be some difference between require and define that I am missing

ORESoftware commented 9 years ago

the following link to a project serves as an example as to the problems I am having using JSXTransformer with this library and RequireJS https://github.com/ORESoftware/requirejs-jsx-example/tree/master