Open grassmu opened 10 years ago
把你的邮件发这里吧
/
./
那如果不支持的话,是不是应该打包都会失败的呢,为何只有4层以上依赖会失败?
就是没有提取,直接用的 require 的
我发给你的邮件内容有详细的代码,亲,是我哪里写的不对?
我也有相同的问题,无法提取第四层的,请问楼主找到问题了吗?
第四层依赖无法提取的原因是顶级 ID
不会递归查找依赖,而相对 ID
会。
伪代码
fetchModule(id)
return module.factory + loadDepsModule(module.depIds)
loadDepsModule(depIds)
result = ''
forEach id in depIds
if isRelativeId(id)
result += fetchModule(id)
else
result += getModule(id).factory
return result
所以想全部合并的话,只有两个办法:
ID
,利用递归查找相对依赖的特性ID
模块,再进行下一步合并工作经分析, 其实不是层级的原因. 是绝对与相对路径的原因. 比如有以下目录
src/
a.js
b.js
c.js
d.js
依赖关系是a -> b -> c -> d
现在分析a的依赖关系. 如果在每个依赖都是用相对的路径来包含, 比如require('./b/'), './c', './d'. 分析a时就能把b, c, d都包含进来.
如果在a中require('/src/b') 是以绝对路径依赖b的, 此时只能分析到a的依赖关系为: 'b', 'c'. 表明, 绝对模块的依赖不会递归分析.
分析代码就可以看出. https://github.com/spmjs/grunt-cmd-transport/blob/master/tasks/lib/script.js#L160
return parsed.dependencies.map(function(id) {
// 如果是相对模块
if (id.charAt(0) === '.') {
var origId = id;
id = iduri.appendext(id);
var depFilepath = path.join(path.dirname(filepath), id);
var depFile = getFileInfo(depFilepath);
if (!depFile) return;
var obj = {
id: origId,
path: depFile.path,
contents: depFile.contents,
hash: depFile.hash,
relative: true
};
if (depMap) depMap[origId] = obj;
// 递归分析子模块依赖
return [obj].concat(parseFileDependencies(depFilepath));
} else {
// 绝对模块不递归分析
return parseModuleDependencies(id);
}
});
解决方法: http://life.leanote.com/post/grunt-cmd-transport-deps-bugs
问题依旧,难道transport不更新了么。。。
A依赖B,B依赖C,C依赖D,我打包A模块,打包的结果是D模块没有了