简体   繁体   中英

How to preprocess or include a coffee script in a coffee script?

I'm taking over my co-worker's coffee script project. He coded all the classes in one single coffee script file.

I like to separate all the classes into their own files. I found out that I can separate files then export the class to 'window' object. The problem with that method is that coffee script generates separate javascript files.

Is there a way to separate coffee script files then compile them into one single js file?

Yes. Coffescript compiler has a --join command exactly for this case. You can do it like this:

coffee --join project.js --compile myCoffeeFolder/*.coffee

You might want to compile your coffeescript files into separate js files to quickly check whether the generated js code matches your expectations. In that case you could use uglifyjs in a second step to compile them into one file and even minify it (for faster loading etc.).

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