如何从 node_modules ( node_modules / gulp-up / index.js )中的gulp.src('json/username.json')
读取数据文件?
username.json
{
"name": "Rikardo",
"city": "Mosscov",
"age": "18"
}
gulpfile.js
upmodul = require("gulp-up");
gulp.task('gulp-ren', function () {
return gulp.src('json/username.json')
.pipe(myfunction());
});
gulp.task('ge', ['gulp-ren']);
node_modules / gulp-up / index.js
'use strict';
var Stream = require('stream');
function loger() {
//The needed maybe not Transform and Read file
var stream = new Stream.Transform({ objectMode: true });
stream._transform = function (file, unused, callback) {
console.log('test !!! - ' + file.contents);
return stream;
}
}
module.exports = loger;
我在控制台命令中写道:gulp ge
,并给出错误:
[00:19:39] TypeError: Cannot read property 'on' of undefined
at DestroyableTransform.Readable.pipe (E:\Developers\WebDeveloper\OpenServer
-WebProg\domains\progectapi2\node_modules\vinyl-fs\node_modules\readable-stream\
lib\_stream_readable.js:516:7)
at Gulp.<anonymous> (E:\Developers\WebDeveloper\OpenServer-WebProg\domains\p
rogectapi2\gulpfile.js:159:9)
at module.exports (E:\Developers\WebDeveloper\OpenServer-WebProg\domains\pro
gectapi2\node_modules\orchestrator\lib\runTask.js:34:7)
at Gulp.Orchestrator._runTask (E:\Developers\WebDeveloper\OpenServer-WebProg
\domains\progectapi2\node_modules\orchestrator\index.js:273:3)
at Gulp.Orchestrator._runStep (E:\Developers\WebDeveloper\OpenServer-WebProg
\domains\progectapi2\node_modules\orchestrator\index.js:214:10)
at Gulp.Orchestrator.start (E:\Developers\WebDeveloper\OpenServer-WebProg\do
mains\progectapi2\node_modules\orchestrator\index.js:134:8)
at C:\Users\Tiki
\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:129:20
at nextTickCallbackWith0Args (node.js:433:9)
at process._tickCallback (node.js:362:13)
at Function.Module.runMain (module.js:432:11)
答案 0 :(得分:0)
我真的不明白你的问题...但是如果你想阅读function display(){
$.get('https://URL', function(data){
var parser = new DOMParser()
, doc = parser.parseFromString(data, "text/xml");
console.log(doc);
var elements = doc.querySelectorAll( 'body *' );
console.log(elements[0].innerHTML);
})
}
display()
文件,那么你可以这样做,就像这样:
json/username.json
json变量将包含username.json文件中的数据。