CoffeeScriptRedux
CoffeeScriptRedux copied to clipboard
Generate a single JavaScript asset
Firstly, this is incredibly cool. I'm in utter disbelief at how amazing this project turned out.
For most of my production work, I compile coffeescript to javascript as part of my build process using Mozilla Rhino. The standard coffeescript distribution includes a single coffee-script-1.3.3.js file. In my build process, I load this file into the JavaScript context and then call CoffeeScript.compile(coffeeScriptSrc);
to retrieve my compiled output.
However, the make output of CoffeeScriptRedux is split up into multiple files under lib/coffeescript
with several dependencies (requirejs, etc). This works great in node and the command line, but I'm wondering how hard it would be to configure the Redux build to generate a single file for use outside the command line? I imagine this would also be useful for anyone compiling CoffeeScript in the browser itself.
Alternatively, do you have any advice on the order in which I'd need to load each js file individually into the JavaScript context for compilation to work?
I've also been wondering about this and looking through the code for answers. Even though the docs say that "it's not recommended for serious use", the <script type="text/coffeescript">
feature of the original compiler is a lifesaver during development, especially when using a web host with no server side JS capabilities.
I'm also wondering about this (I'd like to get a browser version of coffee2ls running) - but as well, this seems necessary if replacing CS 1.x is desired.
I suggest using node-browserify to generate single file. In esmangle project, we generate it by using browserify.
I managed to use browserify to create a single file. I had to manually edit the original coffeescript in a few places and I had to rip out amdrequire stuff, which I think comes in from source-map.
Anyway, here it is: https://gist.github.com/4005706
I managed to get a simple script ("four = 2 + 2") to parse, compile, and output as javascript and source map. I didn't check that the source map was valid.
I'm not a javascript person, so I felt like a dog at the keyboard for most of this process. Hopefully this is helpful.
related, untested commit: dfe5782d3b3808b54d6176533e28ef7fd0e4e4ba
Browserify is working pretty well for me. I only have two issues: I can't get it to automatically export CoffeeScript
(probably an option I'm missing), and I can't get it to automatically ignore /lib/coffee-script/run.js
, which is needed to ignore the unsupported native module
module. Currently, building the browser version requires manually deleting the require('./run')
line in /lib/coffee-script/module.js
and manually adding var CoffeeScript = ...
to the output. I'm working on fixing these minor issues.
I can't get it to automatically export CoffeeScript (probably an option I'm missing)
In Esmangle, creating entry point JavaScript file tools/entry.js
and doing browserify tools/entry.js
.
https://github.com/Constellation/esmangle/blob/master/tools/entry.js
And because node-detective uses esprima and static analysis, we can remove dependency to some file by writing
runModule = './run'
require runModule