javascript - 带有 Coffeescript 和 gulp 的 Node 应用程序

标签 javascript node.js coffeescript gulp

我对 Node 还很陌生,但我正在尝试通过采用已经构建的框架( skeleton )并将其转换为 CoffeeScript 来深入研究。

因此,它有一个 config 文件夹,其中包含 config.jspassport.jsutils.js 文件……显然,也位于根目录 app.js 中。他使用的是 gulp,因此有一个 gulpfile.js。我想将这些文件转换为coffeescript,而不仅仅是用户js 文件。这是不好的做法吗?我已添加 gulp-coffee 作为 devDependency,并将 Coffee-script 添加为依赖项。

重建上述文件并重命名它们...

[12:23:40] 'coffee' errored after 61 μs
[12:23:40] Error: Invalid glob argument
  at Gulp.src (/Users/brett/Dropbox/Apps/mean_projects/skeleton/node_modules/gulp/node_modules/vinyl-fs/lib/src/index.js:17:11)

... and further down

[gulp] [nodemon] starting `coffee --debug app.coffee`
/Users/brett/Dropbox/Apps/mean_projects/skeleton/config/config.coffee: line 1, col 1, Expected an assignment or function call and instead saw an expression.
/Users/brett/Dropbox/Apps/mean_projects/skeleton/config/config.coffee: line 1, col 13, Missing semicolon.
/Users/brett/Dropbox/Apps/mean_projects/skeleton/config/config.coffee: line 3, col 1, Expected an identifier and instead saw '#'.

这显示了 config.coffee,并且我从 js 转换为 Coffee 的每个文件(app、app_cluster、gulpfile、utils、passport 等)都有错误 block 。

有关该主题的任何帮助都会很好...我已经阅读了很多文章(有些讨厌 CoffeeScript ),但没有任何内容真正说明如何处理这个问题。

最佳答案

如果您使用 gulp 3.7+,则开箱即用地支持 gulpfile.coffee。无需进行任何额外设置。

如果您必须使用较早的版本,则可以引导 CoffeeScript ,只需将其放入其中即可:

// Note the new way of requesting CoffeeScript since 1.7.x
require('coffee-script/register');
// This bootstraps your Gulp's main file
require('./Gulpfile.coffee');

然后你可以将设置放入 gulpfile.coffee 中。

你是这个意思吗?

关于javascript - 带有 Coffeescript 和 gulp 的 Node 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24564058/

相关文章:

javascript - 在共享外部模块中强制使用单例模式

javascript - Google Map Javascript API 不在 Ruby 循环中显示 InfoWindows

node.js - 如何使用 NodeJS 捕获全局错误

javascript - CoffeeScript 和 JavaScript 中三元(问号运算符)之间的区别?

javascript - 如何在 Rails 3.1 上使用 coffeescript 注册 Jquery 单击事件

javascript - 如何将事件从子窗口发送到其父窗口

javascript - 对象作为 JavaScript 中的变量容器

ios - Google Cloud 功能中仅接收部分 Apple 订阅通知

node.js - 如何使Azure Functions按顺序连续消费/处理Azure Service Bus Queue消息?

CoffeeScript 语法高亮未显示在 Sublime Text 2 中