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));
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745393212a4625759.html
评论列表(0条)