0

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?

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

so the command would be coffee -w controllers/loginCtrl.js -c coffeescripts/loginCtrl.coffee -b right?
Not exactly. If you want to specify the output dir (e.g. "controllers"), you have to provide -o controllers.
1
  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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.