Newtt
Newtt

Reputation: 6190

Compile CoffeeScript to particular Javascript file

I'm new to using CoffeeScript and this is my first time trying it out. I have two questions.

  1. Compile to particular file

I want to compile a particular coffee file to javascript on the fly.

To do this, I've done the following:

coffee -w -o controllers/loginCtrl.js -c coffeescripts/loginCtrl.coffee

This gives me

ENOENT, open 'c:\path\to\public\testassets\js\controllers\loginCtrl.js\loginCtrl.js'

I believe this is happening because the js file already exists. If I remove the js file, the same command creates a folder called loginCtrl.js and then adds a file inside it.

How do I get coffeeScript to compile to a particular existing file or to a proper path?

  1. Remove unneeded code from compiled file

Assuming that the file gets compiled, the new js file gets compiled as

(function() {
....  
}).call(this);

Is it possible for me to remove the first and last lines of this compiled code?

Upvotes: 0

Views: 73

Answers (2)

Pavel Komiagin
Pavel Komiagin

Reputation: 748

  1. With param -o you can set output directory but the name of your js file will be the same as name of coffee file
  2. If you want to prevent coffeescript from wrapping the code into immediately invoked function, you need to add param -b or --bare ("Compile the JavaScript without the top-level function safety wrapper." from official docs)

Upvotes: 1

mgrim
mgrim

Reputation: 1302

The -o option specifies the output directory. You sholud get the expected output if you remove the file name from this argument.

To compile without the top-level function safety wrapper, use the -b option.

Please read about the coffee command options here: http://coffeescript.org/#usage

Upvotes: 3

Related Questions