复制.js并在Makefile任务期间编译.coffee

时间:2013-07-03 06:12:38

标签: javascript node.js coffeescript makefile

我有一个节点项目:

  • .coffeescript src
  • 中的来源
  • 将coffeescript输出编译为 lib
  • bin
  • 中的shell脚本

如何调整Makefile,如下所示,还将 src 中的.js个文件复制到 lib 目录?

BIN = ./node_modules/.bin
SRC = $(wildcard src/*.coffee)
LIB = $(SRC:src/%.coffee=lib/%.js)

init:
    npm install

clean:
    @rm -r -f $(LIB)

build: $(LIB)

dist: clean init build

lib/%.js: src/%.coffee
    $(call coffeetime)

define coffeetime
    @mkdir -p $(@D)
    $(BIN)/coffee -bcp $< > $@
endef

此外,如果您有任何其他建议来改进Makefile,请分享。

2 个答案:

答案 0 :(得分:3)

这样的事情可能有用。

  • 添加SRCJS = $(wildcard src/*.js)
  • LIB = $(SRC:src/%.coffee=lib/%.js)更改为LIB = $(SRC:src/%.coffee=lib/%.js) $(SRCJS:src/%=lib/%)
  • 添加:

    lib/%.js: src/%.js
        @cp $< $@
    

如果它不起作用(由于某种原因),那么你可能需要使用静态模式规则,但我认为上述内容应该有效。

答案 1 :(得分:-2)

我建议你改用Grunt。 有一些巧妙处理Coffeescript编译的任务。喜欢:https://github.com/gruntjs/grunt-contrib-coffee

此外,根据您的需要,Node.js可以根据需要直接处理Coffeescript。