带有through2的gulp插件以类似XML的格式返回文件

时间:2016-02-11 15:35:32

标签: javascript node.js gulp vinyl

我正在为 Gulp 编写插件,为了处理文件我需要获得它的完整路径。我使用了through2包,然后编写了mainApplicationModule.controller('SearchController',['$scope','ResultService','$location', function($scope,ResultService,$location) { ResultService.add(1) // Adds 1 to 'results' array in ResultService $scope.test = function() { ResultService.add(2); // Adds 2 to Results array in ResultService $location.path("/results") // replace with path to your results view } $scope.results1 = ResultService.getResults(); // will have [1,2] } 函数,但作为来自through2的参数,它接收的文件采用类似XML的格式,而不是processFile(file)file.path等对象。

当through2以下列格式返回每个文件时,如何接收file.path:

file.encoding

完整代码:

<File "relative/path/to/file/aaa.js" ...

1 个答案:

答案 0 :(得分:1)

您在控制台上获得的是File对象如何通过console.log转换为字符串,这就是执行console.log(file)时会发生的情况。最终,调用inspect method并获得您看到的结果(顺便说一下,这不是XML)。

如果我使用您的代码并转储到控制台file.path,我会得到正确的值。与file.basefile.relative相同。

相关问题