javascript 为什么我必须在 gulp 中使用乙烯基源流?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30794356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 12:42:21  来源:igfitidea点击:

Why do I have to use vinyl-source-stream with gulp?

javascriptnode.jsgulpbrowserify

提问by Sung Cho

I am trying to use gulp and browserify to transform my .jsxfiles into .jsfiles.

我正在尝试使用 gulp 和 browserify 将我的.jsx文件转换为.js文件。

var gulp = require('gulp');
var browserify = require('browserify');
var reactify = require('reactify');

gulp.task('js', function () {
  browserify('public/javascripts/src/app.jsx')
    .transform(reactify)
    .bundle()
    .pipe(gulp.dest('public/javascripts/dist'))
});

```

``

The above threw Arguments to path.resolve must be strings. I managed to get around it by using vinyl-source-stream

上面扔了Arguments to path.resolve must be strings。我设法通过使用绕过它vinyl-source-stream

var source = require('vinyl-source-stream');
...
.bundle()
.source('app.js')
...

Why does this work? I am fairly new to nodejs and gulp. After reading the README of the project and the source code, I am still confused. Any help?

为什么这样做?我对 nodejs 和 gulp 相当陌生。看了项目的README和源码,还是一头雾水。有什么帮助吗?

回答by Eloy Pineda

I think that reading this article gulpThe vision, history, and future of the projectcan help you to clarify a few concepts.

我认为阅读这篇文章gulp 项目的愿景、历史和未来可以帮助你理清几个概念。

Basically you can say that vinyl-source-streamconvert the readable streamyou get from browserifyinto a vinyl streamthat is what gulp is expecting to get.

基本上你可以说vinyl-source-stream你从browserify 得到可读流转换成gulp 期望得到的vinyl 流

A vinyl streamis a Virtual file format, and it is fundamental for Gulp. Thanks to this vinyl streamsGulp doesn't need to write a temporal file between different transformations. And this is one of the main advantages it has over Grunt.

乙烯基流是一个虚拟的文件格式,它是根本的咕嘟咕嘟。由于这种乙烯基流,Gulp 不需要在不同的转换之间编写临时文件。这是它相对于Grunt的主要优势之一。

回答by priya selvam

This module is just a bridge that makes it simple to use conventional text streams such as this in combination with gulp.

这个模块只是一个桥梁,它可以简单地将传统的文本流与 gulp 结合使用。