4

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)

Manuel Di Iorio
  • 3,631
  • 5
  • 29
  • 31
  • 3
    *I don't want a different syntax*?? So, you want different features with the same syntax? That doesn't make sense. SASS is a different syntax than CSS, as is SCSS. Sounds like you just want a task runner like Gulp or Grunt – CodingIntrigue Jun 23 '15 at 10:02
  • 1
    You're definitely looking for a task runner, google Gulp ! – Kaz Jun 23 '15 at 10:06
  • "Partials" is pretty meaningless when you're talking about JavaScript. – Andy Jun 23 '15 at 10:09
  • (1) "different syntax": means that should don't completely change the syntax like coffeescript but only adding some features like scss - (2) "partials": like @import "file.js" – Manuel Di Iorio Jun 23 '15 at 11:36

3 Answers3

2

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
    "Javascript is directly interpreted by your browser so there is no "partials precompiling" stuff." ..obviously I haven't ask to do this task directly on the browser but before to put the files on the server (precompilation). However I'm going to accept the answer because the task runners are probably what I need – Manuel Di Iorio Jun 23 '15 at 11:40
  • Yes I got it right, I juste meant you cannot "precompile" javascript files as they will be interpreted as is by the browser. It was just to clarify the term "precompile". If you're going to give Gulp a go, you can find a very simple gulpfile on this project (in this case, coffeescript compilation) : https://github.com/stephane-ruhlmann/mean-coffee-jade-template Glad it was helpful to you. – stephane-ruhlmann Jun 24 '15 at 12:23
  • @stephane-ruhlmann You say you can not "precompile" javascript and you're technically right it's not "compiled" (the way that C or Java is) on the back-end, but there is a fine line between concat/min and compile... they are pretty much the same thing. Closure (Google) even calls itself a "compiler" when it basically just concatenates and minifies. – Dustin Poissant Jun 04 '16 at 01:47
1

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.

Dustin Poissant
  • 3,201
  • 1
  • 20
  • 32
1

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!

Community
  • 1
  • 1
user38561
  • 93
  • 2
  • 8