fathom/gulpfile.js

72 lines
1.8 KiB
JavaScript
Raw Normal View History

'use strict';
2016-12-08 11:43:13 +00:00
const babelify = require("babelify")
const browserify = require('browserify')
const gulp = require('gulp')
const source = require('vinyl-source-stream')
const buffer = require('vinyl-buffer')
const rename = require('gulp-rename')
const gutil = require('gulp-util')
const sass = require('gulp-sass')
const uglify = require('gulp-uglify')
const pump = require('pump')
2016-12-10 14:58:54 +00:00
const debug = process.env.NODE_ENV !== 'production';
2016-12-10 14:58:54 +00:00
let defaultTasks = [ 'browserify', 'sass', 'tracker' ] ;
if( ! debug ) {
defaultTasks.push( 'minify' );
}
gulp.task('default', defaultTasks);
gulp.task('browserify', function () {
return browserify({
entries: './assets/js/script.js',
2016-12-10 14:58:54 +00:00
debug: debug
})
.transform("babelify", {presets: ["es2015"]})
.bundle()
.on('error', function(err){
console.log(err.message);
this.emit('end');
})
.pipe(source('script.js'))
.pipe(buffer())
2016-11-22 19:57:16 +00:00
.pipe(gulp.dest('./static/js/'))
});
2016-12-08 11:43:13 +00:00
gulp.task('minify', function(cb) {
process.env.NODE_ENV = 'production';
2016-12-10 14:58:54 +00:00
2016-12-08 11:43:13 +00:00
pump([
gulp.src('./static/js/*.js'),
uglify().on('error', gutil.log),
gulp.dest('./static/js/')
], cb)
});
2016-11-26 15:17:52 +00:00
gulp.task('img', function() {
return gulp.src('./assets/img/**/*')
.pipe(gulp.dest('./static/img'))
});
gulp.task('tracker', function() {
return gulp.src('./assets/js/tracker.js')
.pipe(gulp.dest('./static/js'))
});
gulp.task('sass', function () {
var files = './assets/sass/[^_]*.scss';
return gulp.src(files)
.pipe(sass())
.on('error', gutil.log)
.pipe(rename({ extname: '.css' }))
2016-11-22 19:57:16 +00:00
.pipe(gulp.dest('./static/css'))
});
gulp.task('watch', ['default'], function() {
gulp.watch(['./assets/js/**/*.js'], ['browserify', 'tracker'] );
2016-12-04 12:23:09 +00:00
gulp.watch(['./assets/sass/**/**/*.scss'], ['sass'] );
});