CoffeeScriptRedux icon indicating copy to clipboard operation
CoffeeScriptRedux copied to clipboard

Generate a single JavaScript asset

Open divideby0 opened this issue 12 years ago • 7 comments

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?

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/85549-generate-a-single-javascript-asset?utm_campaign=plugin&utm_content=tracker%2F33145&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F33145&utm_medium=issues&utm_source=github).

divideby0 avatar Sep 08 '12 04:09 divideby0

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.

osuushi avatar Sep 18 '12 21:09 osuushi

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.

gkz avatar Oct 10 '12 08:10 gkz

I suggest using node-browserify to generate single file. In esmangle project, we generate it by using browserify.

Constellation avatar Oct 10 '12 14:10 Constellation

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.

samwgoldman avatar Nov 03 '12 04:11 samwgoldman

related, untested commit: dfe5782d3b3808b54d6176533e28ef7fd0e4e4ba

michaelficarra avatar Nov 04 '12 18:11 michaelficarra

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.

michaelficarra avatar Dec 16 '12 18:12 michaelficarra

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

Constellation avatar Dec 17 '12 02:12 Constellation