是否有像 Sass 这样的 JavaScript 的预编译器?

Is there a precompiler for JavaScript like Sass?

早上好,是否有针对 JavaScript 的预编译器解决方案,例如针对 CSS 的 Sass?

我唯一需要的功能是部分预编译(减少 js 文件)和文件自动压缩。

我在谷歌上搜索了 Coffeescript,但这不是我要找的,因为我不想要不同的语法..

如果有类似 Koala for Sass 的软件将不胜感激,但即使从命令行 (我在 Windows) 也可以,提前谢谢你!

PS:我的意思是:

@import "file.js"

该工具找到这个并将其替换为文件的内容,创建一个新文件,可能在我指定的另一个文件夹中(正如我所说,如 Koala)

Javascript 由您的浏览器直接解释,因此没有 "partials precompiling" 东西。

您正在寻找的是像 Gulp or Grunt 这样的任务运行器,它可以启动一个任务(以及其他任务)来连接您的文件。

这是一个concat task for Gulp

当您说 "precompiled" 时,您的意思是 "concatenate and minify",是的,它们在技术上是不同的,因为 "compiled" 代码仍在 JS 中,但它们本质上是相同的。

Google 有一个工具调用 Closure "Compiler",这可能就是您要找的东西。

找到 Andy Tran 对问题 "What are the HTML and JavaScript equivalents of Sass?":

的回答

I’m sure there are plenty of options but I’ve only heard of CoffeeScript, TypeScript, Babel, and LiveScript.

[...]

CoffeeScript does create some shorthand versions of certain things aimed to make it easier to read/write, but in my opinion, I found it just to be more messy.

Babel was the second that I picked up and I immediately loved it. Babel allows you to write the newer version of EMCAScript (ES6, ES7) but compiles it to plain old JavaScript to support older versions browsers and IE that doesn’t support have support for it.

TypeScript and LiveScript, I’m not familiar about. However, I’ve heard a lot of positive feedback on TypeScripts and everyone been recommending me to check it out and use it instead of CoffeeScript!

希望对您有所帮助!