刚开始玩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' } } ''” –