admin管理员组文章数量:1424458
I have the following Gulpfile.js
:
'use strict';
const gulp = require('gulp'),
request = require('request');
const paths = {
vendor: [
'.min.js',
'.js'
]
};
gulp.task('vendor', (res) => {
const url = request.get(paths.vendor).pipe(res);
return gulp.src(url)
.pipe(gulp.dest('public/vendor'));
});
gulp.task('default', gulp.parallel('vendor'));
I'm getting the following error:
Error: options.uri is a required argument
With this method I trying to dicthing client-side package managers, like Bower. Is there a way to use request
with gulp
and looping through a list of object?
EDIT:
I placed this code for testing, only returning the first line from the loop:
gulp.task('vendor', () => {
for (let i=0; i<paths.vendor.length; i++) {
return console.log(paths.vendor[i]);
};
});
Just like:
gulp.task('vendor', (res) => {
const url = request.get(paths.vendor[index++]).pipe(res);
return gulp.src(url)
.pipe(gulp.dest('public/vendor'));
});
I have the following Gulpfile.js
:
'use strict';
const gulp = require('gulp'),
request = require('request');
const paths = {
vendor: [
'https://raw.githubusercontent./jquery/jquery-dist/master/dist/jquery.min.js',
'https://raw.githubusercontent./kenwheeler/slick/master/slick/slick.js'
]
};
gulp.task('vendor', (res) => {
const url = request.get(paths.vendor).pipe(res);
return gulp.src(url)
.pipe(gulp.dest('public/vendor'));
});
gulp.task('default', gulp.parallel('vendor'));
I'm getting the following error:
Error: options.uri is a required argument
With this method I trying to dicthing client-side package managers, like Bower. Is there a way to use request
with gulp
and looping through a list of object?
EDIT:
I placed this code for testing, only returning the first line from the loop:
gulp.task('vendor', () => {
for (let i=0; i<paths.vendor.length; i++) {
return console.log(paths.vendor[i]);
};
});
Just like:
gulp.task('vendor', (res) => {
const url = request.get(paths.vendor[index++]).pipe(res);
return gulp.src(url)
.pipe(gulp.dest('public/vendor'));
});
Share
Improve this question
edited Jul 15, 2016 at 18:47
Lanti
asked Jul 15, 2016 at 18:00
LantiLanti
2,3393 gold badges40 silver badges71 bronze badges
2
-
request.get({ uri: paths.vendor })
– Rob M. Commented Jul 15, 2016 at 18:02 -
I've got this error message:
Error: Invalid URI "/"
– Lanti Commented Jul 15, 2016 at 18:17
2 Answers
Reset to default 5You cannot pass a URL to gulp.src()
. The gulp
instance inherits src()
and dest()
from vinyl-fs
meaning you can only use it to read from and write to the local file system.
Try gulp-download
instead, which wraps request
into a vinyl stream:
var download = require('gulp-download');
gulp.task('vendor', () => {
return download(paths.vendor)
.pipe(gulp.dest('public/vendor'));
});
request.get
only works on one URI at a time and you are passing an array, also AFAIK parallel
expects a list of tasks, not one task that processes many items. Maybe this would work for you:
'use strict';
const gulp = require('gulp'),
request = require('request');
const paths = {
vendor: [
'https://raw.githubusercontent./jquery/jquery-dist/master/dist/jquery.min.js',
'https://raw.githubusercontent./kenwheeler/slick/master/slick/slick.js'
]
};
let index = 0;
gulp.task('vendor', (res) => {
const url = request.get(paths.vendor[index++]).pipe(res);
return gulp.src(url)
.pipe(gulp.dest('public/vendor'));
});
let parallelTasks = (new Array(paths.vendor.length)).fill('vendor');
gulp.task('default', gulp.parallel(...parallelTasks));
本文标签: javascriptUsing gulp with requestStack Overflow
版权声明:本文标题:javascript - Using gulp with request - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745393211a2656695.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论