编译和连接coffeescript文件 [英] compile and join coffeescript files
问题描述
我有以下结构:
/lib
/ myfile.js.cofee
/ secondfile.js
/src
我想把它们编译成
/lib
/ myfile.js.cofee
/ secondfile.js
/src
/ awesomefile.min.js
我读过关于Cakefiles,但我不知道如何做这个。
I have read about Cakefiles, but i'm not sure how to exactly do this.
感谢,
Mike
Thanks, Mike
推荐答案
要使用基于connect(例如express)的东西,我建议使用连接资源。如果没有,则咕噜可能是一个好的赌注,如先前建议的。如果你想使用 Cakefile
自己这样做,这里是一个你可以使用的方法:
If you happen to be using something based on connect (e.g. express), I'd recommend using connect-assets. If not, then grunt may be a good bet, as was previously suggested. If you'd like to do this yourself using a Cakefile
, here is one approach you could use:
注意该约定是从src到lib(这是你在问题中所说的相反)。
Note that the convention is to build from src to lib (which is the reverse of what you stated in the question). I'll use that convention below, but you can easily switch it back if needed.
$ npm install snockets
如果需要,
在 src / awesomefile.coffee
中放置以下内容:
#= require secondfile.js
#= require myfile.js.coffee
使用以下命令创建 Cakefile
:
fs = require 'fs'
Snockets = require 'snockets'
NAME = 'awesomefile'
INPUT_FILE = "src/#{NAME}.coffee"
OUTPUT_FILE = "lib/#{NAME}.min.js"
task 'build', 'Build lib/ from src/', ->
snockets = new Snockets()
js = snockets.getConcatenation INPUT_FILE, async: false, minify: true
fs.writeFileSync OUTPUT_FILE, js
task 'clean', "remove #{OUTPUT_FILE}", ->
fs.unlinkSync OUTPUT_FILE
现在你可以这样做:
$ cake build
会创建
您可以将文件放在 src
跟踪自己的依赖关系,或者您可以列出要包含在单个文件中的顺序,如我上面所做的。有关详情,请查看 snockets 存储库。另请注意,的编译章一章arcturo.github.com/library/coffeescript/rel =nofollow>关于CoffeeScript的小书是一个学习蛋糕文件的好资源。
You can have the files in src
track their own dependencies, or you can list the order to be included in a single file like I've done above. For more, you can check out the snockets repository. Also note that the compiling chapter chapter of The Little Book on CoffeeScript is a good resource for learning about cake files.
这篇关于编译和连接coffeescript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!