gulpjs手表上的空数组

时间:2017-12-06 16:11:02

标签: node.js gulp gulp-watch

我是nodejs新手 我需要在两个子目录上观察文件更改,当发生任何更改时我需要更新服务工作者

一切正常,但为什么lista数组是空的?

var gulp = require('gulp');
var watch = require('gulp-watch');
var path = require('path'); 
var fs = require('fs');

root = '/var/www/website.it';
dest = root + '/var/cache/misc/assets/'

var dests = [dest + 'js/tygh/*.js', dest + 'design/themes/responsive/css/*.css'];

gulp.task('default', function(){
    watch(dests, function () {

        var lista = [];     

        dests.forEach(function(dirname){
            dirname = path.dirname(dirname);
            fs.readdir(dirname, (err, files) => {
                files.forEach(file => {
                    lista.push(dirname + '/' + file);
                });
            });
            console.log(lista); // here print list of files
        });

        console.log(lista);  // here print empty array []
    });
});

0 个答案:

没有答案