petehunt / node-jsx

transparently require() jsx from within node
164 stars 32 forks source link

Add CoffeeScript support #4

Closed nickdima closed 10 years ago

nickdima commented 10 years ago

Add the abbility to require coffescript files that contain JSX wrapped in backticks by specifying the .coffee extension like so:

require('node-jsx').install({extension: '.coffee'})

Then simply require your coffeescript module just like a js one, without specifying its extension.

petehunt commented 10 years ago

How about an "additionalTransform" option that is a function the user provides? That way we can break the dependency on coffeescript for users who don't use it and can support other compile to js languages. Seem reasonable?

nickdima commented 10 years ago

That's a great idea! I'll do that. Thanks Pete!

nickdima commented 10 years ago

Added additionalTransform option to install function for performing an additional transform on the source file before the react transform. Here's an example with coffeescript transform:

coffee = require('coffee-script');
require('node-jsx').install({
  extension: '.coffee',
  additionalTransform: function(src) {
    return coffee.compile(src, {
      'bare': true
    });
  }
});
petehunt commented 10 years ago

Thanks for this!