剛開始玩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
絕對路徑是正確的,不過,該文件確實存在。
任何意見,將不勝感激。
我用你的例子,對於拼接嘗試一些常見的js文件與grunt但運行任務時出現此錯誤:node_modules/stitch/node_modules/async/lib/async.js:22 if(called)throw new Error(「Callback was already called。」); 有什麼想法?謝謝! –
對不起,不是真的OOTB。也許你想打開一個單獨的問題? – polarblau
對我來說,「回調已被調用」問題是由於Gruntfile中缺少一個選項,特別是「dest」選項。我gruntfile看起來像針以下內容: ''」 針:{ 選項:{ 路徑:[__dirname + '/ WWW/JS /觀點',__dirname + '/ WWW/JS /模型',__dirname + '/ WWW/JS /集合',__dirname + '/ WWW/JS /佈局'], DEST:__dirname + '/www/js/package.js' } } ''」 –