我设置了一个 gulp 文件,并且我已经正确缩小了我的所有脚本和 css 文件,除了 mybundle.js
和 my homeBundle.js
. 我的uglify()
每个任务都在运行该功能,但是当我尝试吞咽时收到以下错误。
events.js:141 抛出错误;// 未处理的“错误”事件 ^ 错误:/Users/Documents/RTVS360/bundle.js:不支持流式传输
当 gulp 尝试 uglify 时是否存在问题,因为它每次运行 gulp 时都会重新创建文件?
下面你可以看到我的 gulpfile。任何帮助将不胜感激。
var gulp = require('gulp');
var reactify = require('reactify');
var browserify = require('browserify');
var watchify = require('watchify');
var source = require('vinyl-source-stream');
var uglify = require('gulp-uglify');
var uglifycss = require('gulp-uglifycss');
var glob = require('glob');
var streamify = require('gulp-streamify');
gulp.task('watchify', function () {
var bundler = browserify({
entries: ['./client/main.jsx'],
transform: [reactify],
debug: true,
cache: {},
packageCache: {},
fullPaths: true
});
var watcher = watchify(bundler);
return watcher
.on('update', function () {
watcher.bundle()
.on('error', function (err) {
console.log('There was an error compiling the components.', err.message);
})
.pipe(source('bundle.js'))
.pipe(gulp.dest('./dest/'));
})
.bundle()
.on('error', function (err) {
console.log('There was an error compiling the components.', err.message);
})
.pipe(source('bundle.js'))
.pipe(gulp.dest('./dest/'));
});
gulp.task('browserify', function () {
var testFiles = glob.sync('./client/main.jsx');
var bundler = browserify({
entries: testFiles,
transform: [reactify],
debug: true,
cache: {},
packageCache: {},
fullPaths: true
});
function rebundle() {
bundler
.bundle()
.on('error', function(err) {
console.log('There was an error compiling the components.', err.message);
})
.pipe(source('bundle.js'))
.pipe(uglify())
.pipe(gulp.dest('./dest/'));
}
return rebundle();
});
gulp.task('home', function () {
var testFiles = glob.sync('./client/homepage.jsx');
var bundler = browserify({
entries: testFiles,
transform: [reactify],
debug: true,
cache: {},
packageCache: {},
fullPaths: true
});
function rebundle() {
bundler
.bundle()
.on('error', function(err) {
console.log('There was an error compiling the components.', err.message);
})
.pipe(source('homeBundle.js'))
.pipe(uglify())
.pipe(gulp.dest('./dest/'));
}
return rebundle();
});
// Uglify Scripts
gulp.task('scripts', function() {
gulp.src('assets/js/*.js')
.pipe(uglify())
.pipe(gulp.dest('dist/js'))
});
// Minify Styles
gulp.task('styles', function() {
gulp.src('./assets/css/**/*.css')
.pipe(uglifycss({
"max-line-len": 80
}))
.pipe(gulp.dest('./dist/css'));
});
gulp.task('default', ['browserify', 'home','scripts', 'styles']);