LinkedInAttic / inject

AMD and CJS dependency management in the browser
http://www.injectjs.com
Other
464 stars 48 forks source link

Coffeescript plugin support #214

Open brianmhunt opened 11 years ago

brianmhunt commented 11 years ago

It would be wonderful to have support for the CoffeeScript cs! plugin. Example implementations:

jakobo commented 11 years ago

I think that's a pretty reasonable request. Out of the box, it does support the AMD plugin in 0.4.1.

Do you think there's any value in adding a direct-plugin, which would enable localStorage support and some of Inject's other features such as pointcuts?

Thanks for the feedback!

brianmhunt commented 11 years ago

I think a direct plugin could benefit from being added to Inject proper if localStorage could be used, but let me know what you think.

There are a few stages of coffee-script building that a loader could perform:

  1. downloading the .coffee file
  2. compiling the coffee-script into javascript
  3. creating a source-map between the coffeescript & javascript
  4. caching a. the javascript b. the source map c. the coffeescript

Parts 1 & 2 are the sine qua non of the plugin. Part 4.a would definitely provide an incredible performance boost if it eliminated the download and compilation parts, and it sounds like localStorage/Inject could provide that sort of caching.

Parts 3, 4.b and 4.c would be coffee-script developers' heaven, but obviously they are somewhat more challenging.

EDIT One prerequisite to using coffee-script with Inject is that the CoffeeScript compiler would need to be downloaded. The Inject plugin could detect whether there is a window.CoffeeScript object, or make 'coffee-script' a dependency of the cs! plugin, but I have not wrapped my head around how that work work.

For my purposes I am simply including <script src='coffee-script.js'></script> before the Inject require.run call i.e. not loading coffee-script with Inject. In an ideal world, coffee-script would be loaded by Inject.