针和咕噜声 – 文件未find
刚开始玩Grunt ,想用Stitch来组合我的模块,以便在客户端使用。 我一般都没有太多的经验,而且这两个文库都是我的新手,所以请耐心等待。
下面是我的Grunt文件的摘录:
var fs = require('fs'); var stitch = require('stitch'); module.exports = function(grunt) { grunt.initConfig({ … SNIP … stitch: { dist: { src: ['lib'], dest: 'dist/<%= pkg.name %>.js' } } }); grunt.registerMultiTask('stitch', 'Compile common.js modules with stitch', function() { var done = this.async(); var paths = this.file.src.map(function(dir){ return __dirname + '/' + dir; }); stitch.createPackage({ paths: paths }).compile(function(error, src){ if (error) { return grunt.log.writeln(error); } file.write(name, src); grunt.log.writeln("File '" + name + "' created."); done(); }); }); };
当运行grunt stitch
但是,我得到:
ReferenceError: can't compile /path/to/file.js file is not defined
绝对path是正确的,但是,文件确实存在。
任何意见,将不胜感激。
事实certificate,我试图结合其中一个文件中的引用是不正确的。
这个问题可能应该被closures为过于本地化,但在不太可能的情况下,有人可能会有同样的问题 – 检查所有require
调用,看看他们是否指向正确的文件 。 请记住,path将相对于根而不是要求的文件。
但是,这个错误信息特别是非常神秘而基本没用的IMO。
鉴于编译器的本质是asynchronous的针,通过与grunt.util.async.forEachSeries
文件循环解决了我的问题: https : //github.com/fahad19/grunt-stitch-extra/blob/master/tasks/stitch_extra .js文件#L43
咕噜插件可以在这里find: https : //github.com/fahad19/grunt-stitch-extra