How to pass an object from gulpfile to another JavaScript file in nodejs?

杀马特。学长 韩版系。学妹 提交于 2019-12-12 17:15:31

问题


I have an object in my Gulp task which contains the data of my Yaml files. Now I want to access this object from other JavaScript files.

This is what my Gulp Task looks like:

Gulpfile.js

var mergedYaml

gulp.task('LoadYamlFiles', function() {
mergedYaml = global.mergedYaml;
    try {
        //Load all the Yaml files available inside pom folder
        glob("tests/acceptance/wdio/utilities/pom/*.yml", function (er, files) {
            mergedYaml = yamlMerge.mergeFiles(files);
        })
    }
    catch (e){
        console.log(e);
    }
});

exports.mergedYaml = mergedYaml

This is how I am trying to access it:

Test.js

try {


    var mergedYaml = require('../../../../gulpfile.js').mergedYaml;
    console.log(mergedYaml);
}

catch (e){
    console.log(e);
}

Console.log is displaying Undefined as the output.

来源:https://stackoverflow.com/questions/34702620/how-to-pass-an-object-from-gulpfile-to-another-javascript-file-in-nodejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!