与请求一起使用gulp [英] Using gulp with request

查看:166
本文介绍了与请求一起使用gulp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 Gulpfile.js

 'use严格'; 
$ b $ const gulp = require('gulp'),
request = require('request');

const paths = {
vendor:[
'https://raw.githubusercontent.com/jquery/jquery-dist/master/dist/jquery.min.js' ,
'https://raw.githubusercontent.com/kenwheeler/slick/master/slick/slick.js'
]
};
$ b $ 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'));

我收到以下错误:

 错误:options.uri是必填参数

这种方法我试图解决客户端包管理器,比如鲍尔。有没有办法使用 request gulp 并循环一个对象列表?



编辑:

我放置这段代码进行测试,只返回循环的第一行:

  gulp.task('vendor',()=> {
for(let i = 0; i< paths .vendor.length; i ++){
return console.log(paths.vendor [i]);
};
});

就像:

  gulp.task('vendor',(res)=> {
const url = request.get(paths.vendor [index ++])。pipe(res);
return gulp.src(url)
.pipe(gulp.dest('public / vendor'));
});


解决方案

您无法将网址传递到 gulp.src() gulp 实例继承 src() dest() vinyl-fs ,这意味着您只能使用它来读取和写入本地文件系统。



尝试请求包装为乙烯流: / p>

  var download = require('gulp-download'); 

gulp.task('vendor',()=> {
return download(paths.vendor)
.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.com/jquery/jquery-dist/master/dist/jquery.min.js',
    'https://raw.githubusercontent.com/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'));
});

解决方案

You 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'));
});

这篇关于与请求一起使用gulp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆