内存不足错误:汇编构build任务和浏览器同步手表

我有一个问题,我有一个节点服务任务,监视.hbs文件的变化,如果发生变化触发另一个节点任务称为'styleguide'。

此样式指南构build任务使用汇编(v0.23.0)的节点API版本。

发生的事情是,随着时间的推移,构build任务需要更长,更长的时间才能执行,直到最终以Out of Memory和JS堆栈跟踪的错误结束。

这是服务任务的styleguide手表部分。

const styleguideWatchFiles = [ './src/templates/layouts/styleguide.hbs', './src/templates/styleguide/**/*.hbs', './src/components/styleguide/**/*.hbs' ]; //watch STYLEGUIDE chokidar.watch(styleguideWatchFiles, { ignoreInitial: true }) .on('error', error => log.error(error)) .on('all', (event, path) => { log.file('File Changed', path); run(styleguide).then(() => { browserSync.reload('*.html'); }).catch(err => { log.error(err); }); }); 

这是styleguide构build任务。

 /*eslint no-console: 0 */ /** * styleguide.js * * Build script for handling styleguide html templates * using category collections in front-matter to categorise parts of styleguide * with Assemble and Handlebars. * * Handlebars: http://handlebarsjs.com/ * Assemble: https://github.com/assemble/assemble * */ import assemble from 'assemble'; import yaml from 'js-yaml'; import plumber from 'gulp-plumber'; import log from './utils/log'; import getPageData from './utils/getPageData'; import renameExt from './utils/renameExtension'; import expand from './utils/expandMatter'; import { styleguidePathConfig as path } from '../config'; export default function styleguide() { return new Promise( (resolve, reject) => { // Create assemble instance let templates = assemble(); templates.dataLoader('yml', function(str) { return yaml.safeLoad(str); }); templates.data(path.data); templates.preRender(/\.(hbs|html)$/, expand(templates)); // Create styleguide pages templates.task('preload', (cb) => { templates.partials(path.sgPartials); templates.layouts(path.layouts); // Register helpers templates.helpers(path.helpers); // Add pages templates.pages(path.sgPages); // Styleguide page data - used for building dynamic menus templates.data({ coreItems: getPageData('./src/templates/styleguide/core-elements'), componentItems: getPageData('./src/templates/styleguide/components'), generalItems: getPageData('./src/templates/styleguide/general'), sectionItems: getPageData('./src/templates/styleguide/sections') }); cb(); }); templates.task('styleguide', ['preload'], () => { // Render out the template files to 'dist/styleguide' return templates.toStream('pages') // Define our own handler for more error information. .pipe(plumber({ errorHandler: err => { // If we encounter this error on a build task, kill the promise if (process.argv.includes('build')) return reject(err); log.error(`${err.message} in ${err.path}.`); } })) .pipe(templates.renderFile()) .pipe(plumber.stop()) .pipe(renameExt()) .pipe(templates.dest('dist/styleguide')); }); // Run the Assemble build methods templates.build('styleguide', err => { if (err) return reject(err); return resolve(); }); }); } 

getPageData函数只是循环遍历指定的文件夹,并build立一个由handlebars模板使用的对象数组,以build立一个基于正在编译的页面的dynamic菜单。

所以我的问题是什么导致内存泄漏?

是每次调用styleguide.js任务时,在返回parsing之后,assemble()实例不会被垃圾回收?

我是否需要把所有的东西都放在手表上。 调用“preload”和styleguide任务?

谢谢阅读。

自己运行styleguide任务(而不是作为npm start一部分),我看到承诺没有解决。

所以这个问题是一些事情

首先:在'styleguide'任务中,大口水pipe工应该给我提供的错误日志是在错误的地方(在拒绝之下)。 拉出一切,并逐件重build给我看(谢谢@doowb)

其次,一旦我在控制台中显示错误,我就能够确定发生了什么事情。 原来的任务不解决是因为汇编无法find一个部分的参考。 这导致我的configuration文件,我设置partials数组,它不包括我需要的一切。

我现在感觉非常愚蠢,但是感谢在正确的轨道上指引我。