加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何在browserify中获取依赖树?

发布时间:2020-12-13 20:46:41 所属栏目:百科 来源:网络整理
导读:有没有办法检索browserify用来构建bundle的依赖树? Browserify需要一堆脚本并制作好的捆绑包,解决所有需要的依赖项.但是我希望看到那些依赖关系的结构. var scripts = [ 'a.js','b.js' ];//a b require a lot of other scriptsvar b = browserify({ entries
有没有办法检索browserify用来构建bundle的依赖树?

Browserify需要一堆脚本并制作好的捆绑包,解决所有需要的依赖项.但是我希望看到那些依赖关系的结构.

var scripts = [ 'a.js','b.js' ];//a & b require a lot of other scripts
var b = browserify({
        entries:scripts
    });
b.bundle().pipe(fs.createWriteStream('bundle.js'));
//looking on b in debugger I can't find anything like dependency tree
来自 --list handler in the Browserify bin/cmd.js script的这段代码将为您提供一个平面的文件列表:
// Your setup:
var scripts = [ 'a.js','b.js' ]; //a & b require a lot of other scripts
var b = browserify({
  entries: scripts
});

// Logging out each of the filenames:
b.pipeline.get('deps').push(require('through2').obj(
  function (row,enc,next) {
    console.log(row.file || row.id);
    next();
  }
));

// Bundle as normal:
b.bundle().pipe(fs.createWriteStream('bundle.js'));

(注意:您需要安装上面的through2 package才能开箱即用.)

可以使用the code from the --deps handler right next to it构建树,但是所有代码都会吐出JSON blob列表,每个blob包含它依赖的其他文件的列表;你需要自己建造树.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读