1、安装nodejs
2、nodejs 安装 coffee-script模块,npm install -g coffee-script
3、sublime 安装 better coffeescript插件
第一种方式
参考这两篇文章:
http://freewind.me/blog/20111020/450.html
https://github.com/alisey/CoffeeScript-Compiler-for-Windows/blob/master/README.md
很简单,照着处理就可以了。
第二种方式
第一种方式无法创建全局环境下都可以用的CoffeeScript库,要实现全局都可用的CoffeeScript库,可以这么做:
先用npm ls -g查看全局路径,如:C:\Users\username\AppData\Roaming\npm,如果里面没有node_modules目录,就建一个。
建立环境变量,NODE_PATH=C:\Users\username\AppData\Roaming\npm\node_modules。
把刚才下载的CoffeeScript的ZIP包,解压到C:\Users\username\AppData\Roaming \npm\node_modules\coffee-script目录中,记得是coffee-script目录中,注意名称是“coffee- script”。
这样就可以了,在cmd命令行窗口里敲node,输入require('coffee-script'),出现一长串的json格式串,就成功了。
可在命令行分别输入node -v、coffee -v查看当前nodejs和coffeescript版本。
C:\Users\zengyl\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\cake.js:111
throw new Error("Cakefile not found in " + (process.cwd()));
^
Error: Cakefile not found in D:\前端
----------------------------------------------------
{
"cmd": ["coffee.cmd","-c", "$file","&&", "coffee", "$file"]
, "path": "C:\\Users\\zengyl\\AppData\\Roaming\\npm\\node_modules\\coffee-script\\bin"
, "selector": "source.coffee"
, "working_dir": "$project_path"
, "encoding": "cp936"
, "variants":
[
{
"name":"Run",
"cmd": ["coffee", "$file"]
}
]
}
--------------------------------------------------------------
{
"cmd": ["C:\\Users\\zengyl\\AppData\\Roaming\\npm\\coffee.cmd","-c", "$file","&&", "C:\\Users\\zengyl\\AppData\\Roaming\\npm\\coffee.cmd", "$file"]
, "path": "C:\\Users\\zengyl\\AppData\\Roaming\\npm\\node_modules\\coffee-script\\bin"
, "selector": "source.coffee"
, "working_dir": "$project_path"
, "encoding": "cp936"
, "variants":
[
{
"name":"Run",
"cmd": ["coffee", "$file"]
}
]
}
--------------------------------------------------------------------------------------------------
问题在https://packagecontrol.io/packages/Better%20CoffeeScript 得到解答。 alt+shift +w 对照编译结果,js实时预览
参考:http://coffee-script.org/
http://blog.csdn.net/tizzy_joel/article/details/8719037
http://blog.csdn.net/tizzy_joel/article/details/8719037
http://my.oschina.net/u/152550/blog/304788