我不能使用gulp-browserify。我的输入文件是_ / components / js / script.js(这有require('jquery')。我希望它输出到_ / js / script.js。我的配置有什么问题?我得到一个路径错误。< / p>
var gulp = require('gulp'),
sass = require('gulp-sass'),
uglify = require('gulp-uglify'),
browserify= require('browserify');
gulp.task('watch', function(){
gulp.watch('_/components/sass/*.scss', ['sass']);
});
gulp.task('browserify', function(){
var b = browserify({entries: './_/components/js/script.js', debug: true});
return b.bundle()
.pipe(gulp.dest('./js/'));
});
gulp.task('default', ['sass', 'browserify', 'watch']);
答案 0 :(得分:1)
您无法将browserify
捆绑流管道传输到gulp.dest
流。它期待乙烯基流。您可以使用vinyl-source-stream
对其进行转换。这很常见:
var gulp = require('gulp'),
browserify = require('browserify'),
source = require('vinyl-source-stream');
var files = ['./js/admin.js', './js/login.js', './js/main.js']
gulp.task('browserify', function(){
var b = browserify(files);
b.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest('public'))
});