我正在使用Node.js并希望将CoffeeScript合并到我的工作流程中.我有两个用例:
require()CoffeeScript模块的JavaScript文件对于情况#1:我可以从编译.coffee到.js与require()该.js模块,作为一种解决方法.
对于案例#2:现在我正在eval()输出coffee-script.compile().
有没有更好,更统一的方法来做到这一点?
我正在运行Node.js 0.10.21.我尝试了两种CoffeeScript 1.6.3,无论是否使用require('coffee-script/extensions').将这两个文件编译为JavaScript并直接在Node中运行它们当然可以正常工作.
# ./folder/a.coffee
require('../b').test()
# ./b.coffee
exports.test = -> console.log 'yay'
# $ coffee folder/a.coffee
#
# Error: Cannot find module '../b'
# at Function.Module._resolveFilename (module.js:338:15)
# at Function.Module._load (module.js:280:25)
# at Module.require (module.js:364:17)
# at require (module.js:380:17)
# at Object.<anonymous> (/Users/test/folder/a.coffee:1:1)
# at Module._compile (module.js:456:26)
Run Code Online (Sandbox Code Playgroud)