简体   繁体   English

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

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

I am trying to use gulp and browserify to transform my .jsx files into .js files.我正在尝试使用.jsx.jsx将我的.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 .上面抛出的Arguments to path.resolve must be strings I managed to get around it by using vinyl-source-stream我设法通过使用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.我对 nodejs 和 gulp 相当陌生。 After reading the README of the project and the source code, I am still confused.看了项目的README和源码,还是一头雾水。 Any help?有什么帮助吗?

I think that reading this article gulp The vision, history, and future of the project can help you to clarify a few concepts.我认为阅读这篇文章gulp 项目的愿景、历史和未来可以帮助你理清几个概念。

Basically you can say that vinyl-source-stream convert the readable stream you get from browserify into a vinyl stream that is what gulp is expecting to get.基本上,您可以说vinyl-source-stream将从browserify 获得可读转换为gulp 期望获得的vinyl 流

A vinyl stream is a Virtual file format , and it is fundamental for Gulp .乙烯基流是一种虚拟文件格式,它是Gulp 的基础 Thanks to this vinyl streams Gulp doesn't need to write a temporal file between different transformations.由于这种乙烯基流, Gulp 不需要在不同的转换之间编写临时文件。 And this is one of the main advantages it has over Grunt .这是它相对于Grunt的主要优势之一。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将Vinyl-source-stream输出输出到目标目录? - How can I make vinyl-source-stream output to my destination directory? 为什么在Gulp / Vinyl-ftp上传bootstrap.min.css之前,我必须保存两次LESS源文件? - Why do I have to save the LESS source file twice before Gulp/Vinyl-ftp uploads the bootstrap.min.css? 如何从乙烯基物体中获取吞咽流? - How to get a gulp stream from a vinyl object? 如何使用对象列表作为gulp源流 - How to use objects list as gulp source stream 为什么vinyl.isVinyl()对于gulp发出的乙烯基文件返回false? - Why does vinyl.isVinyl() return false for vinyl files emitted by gulp? 如何使用gulp来源地图? - How can I use source maps with gulp? Gulp:访问添加的乙烯基属性 - Gulp: Accessing Added Vinyl Properties Vinyl-fs(gulp文件流)在触发回调或promise之前未完成.dest写入 - vinyl-fs (gulp file stream) not finishing .dest write before firing callback or promise 从流库抛出错误时正确处理Gulp.js乙烯基流错误 - Handling Gulp.js vinyl stream errors properly when errors are thrown from streaming libs 为什么我有重新加载页面以便在运行服务器时显示脚本? (Gulp / Webpack / React) - Why do I have reload page in order for script to display when I run the server? (Gulp/Webpack/React)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM