2012-11-22 30 views
2

刚开始玩Grunt,并希望使用Stitch将我的模块结合起来用于客户端。我对commonJS一般没有太多经验,并且这两个libaries对我来说都是新手 - 所以请耐心等待。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 

绝对路径是正确的,不过,该文件确实存在。

任何意见,将不胜感激。

回答

1

事实证明,我试图合并的其中一个文件中的引用是不正确的。

这个问题也许应该被关闭太本地化,但在偶然的情况下有人可能有同样的问题 - 检查所有require电话,看看他们是否指向正确的文件。请记住,路径将相对于根而不是要求文件。

但是,这个错误消息特别是非常神秘和基本没用的国际海事组织。

+0

我用你的例子,对于拼接尝试一些常见的js文件与grunt但运行任务时出现此错误:node_modules/stitch/node_modules/async/lib/async.js:22 if(called)throw new Error(“Callback was already called。”); 有什么想法?谢谢! –

+0

对不起,不是真的OOTB。也许你想打开一个单独的问题? – polarblau

+0

对我来说,“回调已被调用”问题是由于Gruntfile中缺少一个选项,特别是“dest”选项。我gruntfile看起来像针以下内容: ''” 针:{ 选项:{ 路径:[__dirname + '/ WWW/JS /观点',__dirname + '/ WWW/JS /模型',__dirname + '/ WWW/JS /集合',__dirname + '/ WWW/JS /布局'], DEST:__dirname + '/www/js/package.js' } } ''” –