CoffeeScript与JavaScript的发展及应用
模块构建与CoffeeScript实践
在开发过程中,构建工具的使用十分关键。例如以下代码展示了一种构建流程:
copy 'content', 'compiled', ->
createArtifact 'compiled', VERSION, ->
console.log 'Build complete'
与之类似的Makefile代码如下:
build: artifact
artifact: clean compile copy
tar –cvf artifact.tar compiled
Cake是一个简单的工具,但在某些情况下,使用专门的构建工具可能更好。不过,CoffeeScript提供了强大的语法技术,我们可以创建自己的流畅接口,示例代码如下:
task 'build', 'run the build', ->
clean('compiled')
.then(compile 'app')
.then(copy 'content', 'compiled')
.then(createArtifact 'compiled', VERSION)
.then(-> console.log 'done')
.run()
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



