fathom/gulpfile.js

76 lines
2.0 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';
let defaultTasks = [ 'browserify', 'sass', 'tracker', 'html', 'img' ] ;
2016-12-10 14:58:54 +00:00
if( ! debug ) {
defaultTasks.push( 'minify' );
}
gulp.task('default', defaultTasks);
gulp.task('browserify', function () {
return browserify({
entries: './assets/src/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())
.pipe(gulp.dest('./assets/dist/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('./assets/dist/js/*.js'),
2016-12-08 11:43:13 +00:00
uglify().on('error', gutil.log),
gulp.dest('./assets/dist/js/')
2016-12-08 11:43:13 +00:00
], cb)
});
2016-11-26 15:17:52 +00:00
gulp.task('img', function() {
return gulp.src('./assets/src/img/**/*')
.pipe(gulp.dest('./assets/dist/img'))
2016-11-26 15:17:52 +00:00
});
gulp.task('html', function() {
return gulp.src('./assets/src/**/*.html')
.pipe(gulp.dest('./assets/dist'))
});
2016-11-26 15:17:52 +00:00
gulp.task('tracker', function() {
return gulp.src('./assets/src/js/tracker.js')
.pipe(gulp.dest('./assets/dist/js'))
});
gulp.task('sass', function () {
var files = './assets/src/sass/[^_]*.scss';
return gulp.src(files)
.pipe(sass())
.on('error', gutil.log)
.pipe(rename({ extname: '.css' }))
.pipe(gulp.dest('./assets/dist/css'))
});
gulp.task('watch', ['default'], function() {
gulp.watch(['./assets/src/js/**/*.js'], ['browserify', 'tracker'] );
gulp.watch(['./assets/src/sass/**/**/*.scss'], ['sass'] );
});