为什么我必须使用乙烯源流与吞咽? [英] Why do I have to use vinyl-source-stream with gulp?
问题描述
我正尝试使用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'))
});
```
以上投掷对path.resolve的参数必须是字符串
。我设法通过使用 vinyl-source-stream
var source = require('vinyl-source-stream');
...
.bundle()
.source('app.js')
...
为什么这会起作用?我对nodejs和gulp相当陌生。在阅读了项目的README和源代码之后,我仍然感到困惑。任何帮助?
我认为阅读这篇文章 gulp
项目的远景,历史和未来可以帮助您澄清一些概念。
基本上,您可以将 vinyl-source-stream 转换为 可读你可以从browserify 将它转换成一个乙烯基流,这就是gulp期待得到的结果。
A vinyl stream 是一种虚拟文件格式,它是 Gulp 的基础。感谢这个乙烯流 Gulp不需要在不同的转换之间编写一个临时文件。这是它的主要优势之一 Grunt 。
I am trying to use gulp and browserify to transform my .jsx
files into .js
files.
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
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?
I think that reading this article gulp The vision, history, and future of the project can help you to clarify a few concepts.
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.
A vinyl stream is a Virtual file format, and it is fundamental for Gulp. Thanks to this vinyl streams Gulp doesn't need to write a temporal file between different transformations. And this is one of the main advantages it have over Grunt.
这篇关于为什么我必须使用乙烯源流与吞咽?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!