Is there a precompiler for JavaScript like Sass?

3.7k views Asked by At

Good morning, is there a precompiler solution for JavaScript like Sass for CSS ?

The only features I need are the partials precompiling (to have fewer js files) and the auto-compression of the file.

I googled for Coffeescript but it's not what I'm looking for and because I don't want a different syntax..

If is there a software like Koala for Sass would be appreciated but even from command line (I'm on Windows) is ok, thank you in advance!

PS: with partials I mean:

@import "file.js"

The tool find this and replace it with the content of the file, creating a new file, maybe in another folder specified by me (As I said, like Koala)

3

There are 3 answers

3
stephane-ruhlmann On BEST ANSWER

Javascript is directly interpreted by your browser so there is no "partials precompiling" stuff.

What you are looking for is a task runner like Gulp or Grunt that can launch a task (amongst others) that will concatenate your files.

Here is a concat task for Gulp

1
Dustin Poissant On

When you say "precompiled" you mean "concatenate and minify", yes they are technically different because the "compiled" code is still in JS, but they are essentially the same thing.

Google has a tool call Closure "Compiler" that is probably what you are looking for.

0
user38561 On

Found this answer, by Andy Tran, to the question "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!

Hope it helps!