2012-11-22 50 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' } } ''」 –