2012-03-11 56 views
0

我有2個文件。 ./main.coffee./shared.coffee。我想使用makefile來編譯,然後將其分解爲./main.js使用makefile從coffeescript編譯後合併javascript文件

這是我目前有:

public: main.min.js 


main.min.js: main.js 
uglifyjs ./main.js > ./main.min.js 

#combine the shared files with the compiled main.coffee 
main.js: ./main.coffee 
coffee -c ./main.coffee #problem1 
cat ./main.js ./shared.js > ./main.js 

shared: ./shared.coffee 
coffee -c ./shared.coffee 

我知道這會給出錯誤的cat操作。如何編譯並將標記爲problem1的行內容傳遞給cat方法,而不從其生成main.js。

例如, coffeescript網站給了這個:Pipe in CoffeeScript to STDIN and get back JavaScript over STDOUT. Good for use with processes written in other languages. An example: cat src/cake.coffee | coffee -sc我該如何將這種方法與貓合併文件?

+1

查看[coffee --join](http://jashkenas.github.com/coffee-script/#usage)。 – 2012-03-11 22:09:54

回答

1

使用coffee --join

main.js: 
coffee -c -j main.js main.coffee shared.coffee 

編輯:由於特雷弗伯納姆指出,這是不完全一樣的提問者想要的東西:

--join第一合併main.coffee和shared.coffee,然後編譯合併的源代碼。這意味着你沒有得到範圍分離。

+0

這實際上與asker想要的不同:'--join首先合併'main.coffee'和'shared.coffee',然後編譯合併的源文件。這意味着你沒有得到範圍分離。 – 2012-03-11 23:28:15

+0

特雷弗:沒錯,給這個答案加上這個警告。 – 2012-03-12 11:22:24