gulp+browserify进行前端自动化以及打包问题
修改代码后编译特别慢,找了很多方法依然不行,忘指点一下。
var browserify = require('browserify');
var watchify = require('watchify');
// var bundleLogger = require('../util/bundleLogger');
var gulp = require('gulp');
// var handleErrors = require('../util/handleErrors');
var source = require('vinyl-source-stream');
var config = require('../config').browserify;
var buffer = require('vinyl-buffer');
var es3ify = require("gulp-es3ify");
gulp.task('browserify', ['bableConvert'], function(callback) {
var bundleQueue = config.bundleConfigs.length;
var browserifyThis = function(bundleConfig) {
var bundler = browserify({
// Required watchify args
cache: {}, packageCache: {}, fullPaths: false,
// Specify the entry point of your app
entries: bundleConfig.entries,
// Add file extentions to make optional in your requires
extensions: config.extensions,
// Enable source maps!
debug: config.debug
});
var bundle = function() {
// Log when bundling starts
// bundleLogger.start(bundleConfig.outputName);
return bundler
.bundle()
// Report compile errors
// .on('error', handleErrors)
// Use vinyl-source-stream to make the
// stream gulp compatible. Specifiy the
// desired output filename here.
.pipe(source(bundleConfig.outputName))
.pipe(buffer())
.pipe(es3ify())
// Specify the output destination
.pipe(gulp.dest(bundleConfig.dest))
.on('end', reportFinished);
};
if(global.isWatching) {
// Wrap with watchify and rebundle on changes
bundler = watchify(bundler);
// Rebundle on update
bundler.on('update', bundle);
}
var reportFinished = function() {
// Log when bundling completes
// bundleLogger.end(bundleConfig.outputName);
if(bundleQueue) {
bundleQueue--;
if(bundleQueue === 0) {
// If queue is empty, tell gulp the task is complete.
// https://github.com/gulpjs/gulp/blob/master/docs/API.md#accept-a-callback
callback();
}
}
};
return bundle();
};
// Start bundling with Browserify for each bundleConfig specified
config.bundleConfigs.forEach(browserifyThis);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论