我正在使用gulp将React JSX编译为JS,Sass编译为css以及实时重新加载。一切都很好,但“建立”.js文件需要2.5s-3s。当我在9-10秒之后尝试在我的.jsx gulp完成构建中导入React-Bootstrap。有没有办法加快建设?这是我的gulp.config:
var gulp = require('gulp');
var browserify = require('browserify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var browserSync = require('browser-sync').create();
var sass = require('gulp-sass');
function swallowError(error) {
console.log(error.toString())
this.emit('end')
}
gulp.task('build', function() {
return browserify({ entries: './docs/Main.jsx', extensions: ['.jsx'], debug: true })
.transform('babelify', { presets: ['es2015', 'react'] })
.on('error', swallowError)
.bundle()
.on('error', swallowError)
.pipe(source('bundle.js'))
.on('error', swallowError)
.pipe(gulp.dest('docs/dist'))
.pipe(browserSync.stream())
.on('error', swallowError);
});
gulp.task('serve', ['sass'], function() {
browserSync.init({
server: "./docs"
});
gulp.watch("docs/scss/*.scss", ['sass']);
gulp.watch('docs/*.js*', ['build']);
gulp.watch(["docs/*.html"]).on('change', browserSync.reload);
});
// Compile sass into CSS & auto-inject into browsers
gulp.task('sass', function() {
return gulp.src("docs/scss/*.scss")
.pipe(sass())
.on('error', swallowError)
.pipe(gulp.dest("docs/css"))
.pipe(browserSync.stream());
});
gulp.task('default', ['serve']);