Commit 89284091 authored by Jed Simson's avatar Jed Simson

Improve compile/build tasks

parent 321aa7e2
var gulp = require('gulp');
var gulpBrowser = require("gulp-browser");
var reactify = require('reactify');
var del = require('del');
var size = require('gulp-size');
var gulp = require('gulp'),
glob = require('glob'),
clean = require('gulp-clean'),
browserify = require('gulp-browserify'),
babel = require('gulp-babel'),
plumber = require('gulp-plumber'),
react = require('gulp-react'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify'),
flatten = require('gulp-flatten'),
concat = require('gulp-concat'),
size = require('gulp-size');
gulp.task('clean', function() {
return gulp.src(['./static/scripts/build/', './static/scripts/dist/'], {read: false})
.pipe(clean());
})
// tasks
gulp.task('transform', function () {
var stream = gulp.src('./static/scripts/jsx/*.js')
.pipe(gulpBrowser.browserify({transform: ['reactify']}))
.pipe(gulp.dest('./static/scripts/js/'))
.pipe(size());
return stream;
gulp.task('compile-jsx', function() {
return gulp.src('./static/scripts/src/*.js')
.pipe(plumber())
.pipe(react())
.on('error', function(e) {
console.error(e.message + '\n in ' + e.fileName)
})
.pipe(babel({
presets: ['es2015']
}))
.pipe(flatten())
.pipe(gulp.dest('./static/scripts/build/'))
.pipe(size());
});
gulp.task('del', function () {
// add task
gulp.task('build-js', ['compile-jsx'], function(){
var stream = gulp.src(['./static/scripts/build/*.js'])
.pipe(plumber())
.pipe(browserify())
.on('prebundle', function(bundle) {
glob.sync('*.js', {cwd: './static/scripts/build'}).forEach(function(module) {
var expose = module.split('.').shift()
if (expose == 'app') return
bundle.require('./' + module, {expose: expose})
})
})
.on('error', function(e) {
console.error(e)
})
.pipe(concat('app.js'))
.pipe(gulp.dest('./static/scripts/dist/'))
.pipe(rename('app.min.js'))
.pipe(uglify())
.pipe(gulp.dest('./static/scripts/dist/'))
.pipe(size());
return stream;
});
gulp.task('default', function() {
gulp.start('transform');
//gulp.start('compile-jsx');
gulp.start('build-js');
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment