Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate a single JavaScript asset #42

Open
divideby0 opened this issue Sep 8, 2012 · 7 comments
Open

Generate a single JavaScript asset #42

divideby0 opened this issue Sep 8, 2012 · 7 comments
Labels

Comments

@divideby0
Copy link

divideby0 commented Sep 8, 2012

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).
@osuushi
Copy link

osuushi commented Sep 18, 2012

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.

@gkz
Copy link
Contributor

gkz commented Oct 10, 2012

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.

@Constellation
Copy link
Contributor

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

@samwgoldman
Copy link

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.

@michaelficarra
Copy link
Owner

related, untested commit: dfe5782

@michaelficarra
Copy link
Owner

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.

@Constellation
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants