[英]Gulp + Browserify task not working (no output)
I have the following task on my gulpfile.js
我在
gulpfile.js
上执行以下任务
gulp.task('default', ['browserify'])
gulp.task('browserify', function () {
return browserify('./public/js/x.js')
.bundle()
.pipe(source('y.js'))
.pipe(gulp.dest('./public/dist/js'))
})
But after running $ gulp
it gives no output. 但是在运行
$ gulp
它没有输出。 Am I missing something? 我想念什么吗?
I am not sure what your browserify
is but I'm gonna assume it's not the deprecated gulp-browserify
. 我不确定您的
browserify
是什么,但我将假定它不是已弃用的gulp-browserify
。
This should work. 这应该工作。 I tested it:
我测试了它:
var gulp = require('gulp');
var browserify = require('browserify');
var source = require('vinyl-source-stream'); // MAKE SURE THIS IS THERE
gulp.task('default', ['browserify'])
gulp.task('browserify', function() {
return browserify('./public/js/x.js').bundle() // .bundle is a browserify function
.pipe(source('y.js')) // Pass to output using vinyl-source-stream
.pipe(gulp.dest('./public/dist/js'));
});
Since my code looks exactly as yours, can you make sure you have vinyl installed? 由于我的代码与您的代码完全一样,因此您可以确定已安装黑胶唱片吗?
npm install --save vinyl-source-stream
and if you haven't already: 如果还没有:
npm install --save gulp browserify
npm install -g gulp
I'm now maintaining a repository which collecting all the gulp tasks I use in daily work. 我现在正在维护一个存储库 ,该存储库收集我在日常工作中使用的所有gulp任务。
This is the browserify task code 这是browserify任务代码
var gulp = require('gulp') var gulpif = require('gulp-if') var browserify = require('browserify') var gutil = require('gulp-util') var through2 = require('through2') var watchify = require('watchify') var assign = require('object-assign') var babelify = require('babelify') var config = require('config').gulp module.exports = function (is_dev) { var options = { paths: [config.src.js] } if (is_dev) { options = assign({}, options, { debug: true, cache: {}, packageCache: {} }) } var bundler = function () { return through2.obj(function (file, enc, next) { var b = browserify(file.path, options) .transform(babelify.configure({ presets: ['es2015', 'react'], compact: false })) if (is_dev) { b = watchify(b) b.on('update', bundle) b.pipeline.on('file', function (filename) { gutil.log(gutil.colors.green('Bundled: '), filename) }) } return b.bundle(function (err, res) { if(err) { return next(err) } file.contents = res next(null, file) }) }) } function bundle() { is_dev ? gutil.log(gutil.colors.yellow('Bundling...')) : null return gulp.src([ config.src.js + '/**/*.js', '!' + config.src.js + '/lib/**/*.js' ]) .pipe(bundler()) .on('error', function(e) { gutil.log(gutil.colors.red(e.message)) is_dev ? this.emit('end') : null }) .pipe(gulp.dest(config.dist.js)) } return bundle() }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.