Javascript 针线活;格朗特&x2014 ;找不到文件
刚开始玩,想用它来组合我的模块,以便在客户端使用。一般来说,我对commonJS没有太多经验,这两个库对我来说都是新的,所以请容忍我 以下是我的Grunt文件的摘录:Javascript 针线活;格朗特&x2014 ;找不到文件,javascript,node.js,gruntjs,node-stitch,Javascript,Node.js,Gruntjs,Node Stitch,刚开始玩,想用它来组合我的模块,以便在客户端使用。一般来说,我对commonJS没有太多经验,这两个库对我来说都是新的,所以请容忍我 以下是我的Grunt文件的摘录: var fs = require('fs'); var stitch = require('stitch'); module.exports = function(grunt) { grunt.initConfig({ … SNIP … stitch: { dist: {
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();
});
});
};
但是,绝对路径是正确的,并且文件确实存在
任何建议都将不胜感激。事实证明,我试图合并的一个文件中的引用不正确 此问题可能因过于本地化而关闭,但在不太可能的情况下,可能有人会遇到相同的问题-检查所有
require
调用,查看它们是否指向正确的文件。请记住,路径将相对于根目录,而不是所需的文件
但是,这个错误消息非常隐晦,在我看来基本上是无用的。鉴于编译器对于stitch来说是异步的,使用
grunt.util.async.forEachSeries在文件中循环解决了我的问题:
grunt插件可以在这里找到:我尝试使用您的示例,用grunt缝合一些常见的js文件,但我在运行任务时遇到了这个错误:node_modules/stitch/node_modules/async/lib/async.js:22 if(called)抛出新错误(“回调已被调用”);有什么想法吗?谢谢对不起,不是真的。也许你想另外问一个问题?对我来说,“回调已经被调用”的问题是由于Grunfile中缺少一个选项,特别是“dest”选项。对于stitch,我的gruntfile类似于以下内容:''stitch:{options:{path:[\uuuu dirname+'/www/js/views'、\uu dirname+'/www/js/models'、\uu dirname+'/www/js/collections'、\uu dirname+'/www/js/layouts'],dest:\uu dirname+'/www/js/package.js'}'}'
ReferenceError: can't compile /path/to/file.js
file is not defined