我对 Node 还很陌生,但我正在尝试通过采用已经构建的框架( skeleton )并将其转换为 CoffeeScript 来深入研究。
因此,它有一个 config 文件夹,其中包含 config.js
、passport.js
和 utils.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/