简体   繁体   中英

How to concatenate compiled coffeescript files?

With Coffeescript coffee command, it is possible to compile a coffee source file into its JavaScript equivalent with -c flag:

coffee -c toto.coffee

Shall produce an appropriate toto.js file.

Now what I would like to do is to compile many .coffee files into their respective .js equivalents and then concatenate them into a final library file. Something like this:

coffee -c toto.coffee
coffee -c foo.coffee
coffee -c bar.coffee
??? toto.js foo.js bar.js # Would produce a final .js file

The coffeescript command proposed me to do the following:

cat toto.coffee foo.coffee bar.coffee | coffee -c -s > library.js

But the problem is, if I modify one line in one coffee file, the entire library would have to be recompiled.

Neither the coffee command nor one of coffeescript build tools solved my problem.

I also looked at this question , where gruntjs is mentioned, but I didn't find any clear explanations on how I should use it in my specific case.

You could keep the coffeescript compiler watching for changes using -w flag. So everytime you change a line only this file will be recompiled just after save.

The concat can also automatically concatenate all files together after at least one changed. But as far as I know you have to code a nodejs helper therefor. I would use the chokidar library to do so.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM