問題描述
我正在嘗試使用 gulp 和 browserify 將我的 .jsx
文件轉換為 .js
文件.
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'))
});
```
上面拋出的path.resolve 的參數必須是字符串
.我設法通過使用 vinyl-source-stream
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')
...
為什么會這樣?我對 nodejs 和 gulp 還很陌生.看了項目的README和源碼,還是一頭霧水.有什么幫助嗎?
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.
基本上你可以說 vinyl-source-stream 轉換 可讀流你從 browserify 得到的 vinyl 流 這就是 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.
乙烯基流是一種虛擬文件格式,它是Gulp的基礎.多虧了這個乙烯基流,Gulp 不需要在不同的轉換之間編寫臨時文件.這是它優于 Grunt 的主要優勢之一.
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 has over Grunt.
這篇關于為什么我必須在 gulp 中使用vinyl-source-stream?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!