使用npm模块编译coffeescript测试
答
的咖啡脚本模块提供了一个“编译”方法:
var cs = require('coffee-script');
var js = cs.compile('foo = -> "bar"');
答
如果你在谈论的coffee
命令行实用程序,然后是你可以(虽然它不是太漂亮):
echo "alert 'Hello World'" | coffee -sc
上面的代码编译CoffeeScript的回声并且输出到stdout 。如果你想在文件编译后的输出,你可以这样做:
echo "alert 'Hello World'" | coffee -sc > path/to/file.js
有一个在命令行实用程序在这里的一些好的文档:http://coffeescript.org/#usage
如果你的意思是编制内 CoffeeScript的代码串中,coffee-script
模块提供了一个编译函数:
coffee = require 'coffee-script'
js = coffee.compile "alert 'Hello World'"