简体   繁体   English

桌面Javascript继承编译器?

[英]Desktop Javascript inheritance compiler?

Wondering if anyone if there is a desktop JS compiler out there that does for JS what the desktop Less application does for CSS. 想知道是否有人可以使用桌面JS编译器来处理JS,而桌面Less应用程序可以处理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: 文件foo.js:

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

File foo_plus.js: 文件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 现在保存后,编译器将语句“ @import 'foo.js'; ”替换为

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. 理想情况下,这将是诸如Less应用程序之类的桌面编译器,它监听文件上的更改并相应地进行编译。

I think it makes sense for you to consider one of C preprocessors. 我认为您可以考虑使用C预处理器之一。 So your import will look like as 所以您的导入看起来像

#include "someotherfile.js"

See: Is there a standalone C++ source preprocessor? 请参阅: 是否有独立的C ++源预处理器?

Another option would be HTML preprocesor kind of thing. 另一个选择是HTML preprocesor之类的东西。 See for example: http://htp.sourceforge.net/ and others: http://htmlhelp.com/links/preprocessors.html 参见例如: http : //htp.sourceforge.net/和其他: http : //htmlhelp.com/links/preprocessors.html

http://code.google.com/p/minify/ will do this, as well as “compress” the resulting script. http://code.google.com/p/minify/会执行此操作,并“压缩”生成的脚本。

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. 您既可以在服务器上运行它,也可以运行一次,仅上传缩小版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM