1

Wondering if anyone if there is a desktop JS compiler out there that does for JS what the desktop Less application does for CSS. Ideally you would be able to "import" a script at the top of the document and write extended code for it. Upon saving this compiler would combine the two files into a single source file to a new output file. An example:

File foo.js:

 var Foo = function() {};
 Foo.prototype.doSomething = function(){alert('doing stuff...');};

File foo_plus.js:

 @import 'foo.js';
 Foo.prototype.doSomethingElse = function(){alert('doing other stuff...');};

Now upon saving, the compiler is replacing the statement "@import 'foo.js';" with

var Foo = function() {};
Foo.prototype.doSomething = function(){alert('doing stuff...');};

then adding:

Foo.prototype.doSomethingElse = function(){alert('doing other stuff...');};

and saving this to a chosen location and name.

Ideally, this would be a desktop compiler like the Less application that listens to changes on the file and compiles accordingly.

1
  • If all you're looking for is combining scripts, you can set that up with php. Just configure apache to process .js files as php scripts, and use PHP includes. Commented Dec 19, 2011 at 17:07

2 Answers 2

1

I think it makes sense for you to consider one of C preprocessors. So your import will look like as

#include "someotherfile.js"

See: Is there a standalone C++ source preprocessor?

Another option would be HTML preprocesor kind of thing. See for example: http://htp.sourceforge.net/ and others: http://htmlhelp.com/links/preprocessors.html

Sign up to request clarification or add additional context in comments.

1 Comment

A C preprocessor is a good idea. I use it in one of my JavaScript projects too. In order to still have valid JS code, I precede these directives with //!, i.e. //!#include "someotherfile.js" and then remove all //! in my build script before the preprocessor is invoked.
0

http://code.google.com/p/minify/ will do this, as well as “compress” the resulting script.

You'd want to keep a separate working-copy; think of it as a compiler: the output that it produces is harder to debug and somewhat “mangled” at times.

You can either run this on the server, or run it once and only upload the minified versions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.