使用AngularJS编译CoffeeScript而不使用Yeoman

时间:2014-04-13 20:52:22

标签: angularjs coffeescript

我尝试将a little app in AngularJS从JavaScript翻译为CoffeeScript,作为学习CoffeeScript的练习。

script appcoffee.coffee现在以

开头
'use strict'

UsrAdmApp = angular.module 'UsrAdmApp', ['ngAnimate', 'ui.bootstrap']

UsrAdmApp.controller 'UsrAdmCtrl', class

    constructor: (@$scope, @$http, @$timeout) ->
        # Init scope
        # etc.

我尝试使用简单的coffee appcoffee.coffee进行编译,但找不到angular模块。

ReferenceError: angular is not defined
    at Object.<anonymous> (.../appcoffee.coffee:6:15)
    at Object.<anonymous> (.../appcoffee.coffee:56:4)
    at Module._compile (module.js:456:26)

我尝试了-r angular选项,但后来我得到了Error: Cannot find module 'angular'。我尝试将angular.js文件放在与咖啡文件相同的目录中,我也尝试了-r angular.js,让npm install angularjsnode_modules文件夹置于同一级别,但我不知道#39;得到编译的脚本......

我现在不想使用自耕农或咕噜声,因为我想先了解整个小项目是如何工作的。

1 个答案:

答案 0 :(得分:4)

我遇到了同样的问题,并在用户icktoofay的另一个帖子中找到了答案:

  

选项必须在文件之前,例如:

 coffee -cw script.coffee
     

否则,它会尝试运行script.coffee然后作为Node.js脚本运行,并传递选项-c和-w。那不是你想要的;如果你想让CoffeeScript编译器获得选项,它必须在文件名之前。

换句话说,没有&#39; -c&#39;选项,咖啡尝试编译和运行脚本,你的终端不知道角度是什么。