Weird transpiling of coffeescript to javascript

I just setup the webstorm environement to work with coffeescript transpiling to javascript, this is installing node,npm,coffeescript on my mac.
All seems fine, I created a coffeescript file, added a watcher to it which creates and updates the corresponding js file.

I tried with very simple code in coffeescript file, declaring variables:

coffeescript code:

myamount = 5

javascript code:

// Generated by CoffeeScript 1.6.3
(function() {
  var myamount;

  myamount = 5;


Why does it put everything into a function ?? There is no way I can get rid of this function
Comment actions Permalink


this is the way the coffeescripty transpiler works - it wraps each file in a function. See for more info
You can modify the 'arguments' field of your file watcher to pass a --bare option to compiler to avoid this wrapping:
'-b', '--bare',            'compile without a top-level function wrapper'

Comment actions Permalink

Thanks for your answer.
And to enable the bare option, should I just run coffee --bare from the mac command line ? Or should I recompile it ?

Comment actions Permalink

no and no. You need to add --bare to transpiler arguments in your file watcher (Settings/File Watchers, select you coffeescript watcher)


Please sign in to leave a comment.