从 browserify API 获取依赖项列表
Get list of dependencies from browserify API
我正在尝试编写一个可识别 browserify 的 Makefile,并确定我的捆绑构建目标的依赖项,我想请 browserify 列出它们。
我已经取得的成就:
browserify index.js --deps
会将它们列为 JSON,我可以对其进行解析,以提取列表。但是我想知道如果我尝试通过 browserify 的 API.
这样做是否会更有效率
browserify(path.resolve('index.js'))
.pipeline.get('deps').on('dep', (dep) => console.log('dep'))
这行不通:(
我最终找到了一种从 browserify 获取依赖项的方法 API:
const through = require('through2')
const bundler = browserify('index.js')
bundler.pipeline.get('deps').push(through.obj((row, enc, next) => {
// simply write the filename to the console
console.log(row.id)
next()
}))
bundler.bundle()
好处是当我只想解析 id 时,我不必将整个 json 缓冲到 stdout,这会占用较大树的大量内存。
我正在尝试编写一个可识别 browserify 的 Makefile,并确定我的捆绑构建目标的依赖项,我想请 browserify 列出它们。
我已经取得的成就:
browserify index.js --deps
会将它们列为 JSON,我可以对其进行解析,以提取列表。但是我想知道如果我尝试通过 browserify 的 API.
这样做是否会更有效率browserify(path.resolve('index.js'))
.pipeline.get('deps').on('dep', (dep) => console.log('dep'))
这行不通:(
我最终找到了一种从 browserify 获取依赖项的方法 API:
const through = require('through2')
const bundler = browserify('index.js')
bundler.pipeline.get('deps').push(through.obj((row, enc, next) => {
// simply write the filename to the console
console.log(row.id)
next()
}))
bundler.bundle()
好处是当我只想解析 id 时,我不必将整个 json 缓冲到 stdout,这会占用较大树的大量内存。