2016-11-21 12:24:50 +00:00
|
|
|
'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-11-21 12:24:50 +00:00
|
|
|
|
2018-04-20 11:12:23 +00:00
|
|
|
let defaultTasks = [ 'browserify', 'sass', 'tracker', 'html', 'img' ] ;
|
2016-12-10 14:58:54 +00:00
|
|
|
if( ! debug ) {
|
|
|
|
defaultTasks.push( 'minify' );
|
|
|
|
}
|
|
|
|
|
|
|
|
gulp.task('default', defaultTasks);
|
2016-11-21 12:24:50 +00:00
|
|
|
|
|
|
|
gulp.task('browserify', function () {
|
|
|
|
return browserify({
|
2018-04-20 11:12:23 +00:00
|
|
|
entries: './assets/src/js/script.js',
|
2016-12-10 14:58:54 +00:00
|
|
|
debug: debug
|
2016-11-21 12:24:50 +00:00
|
|
|
})
|
2016-11-23 14:51:19 +00:00
|
|
|
.transform("babelify", {presets: ["es2015"]})
|
2016-11-21 12:24:50 +00:00
|
|
|
.bundle()
|
2016-11-23 14:51:19 +00:00
|
|
|
.on('error', function(err){
|
|
|
|
console.log(err.message);
|
|
|
|
this.emit('end');
|
|
|
|
})
|
2016-11-21 12:24:50 +00:00
|
|
|
.pipe(source('script.js'))
|
|
|
|
.pipe(buffer())
|
2018-04-20 11:12:23 +00:00
|
|
|
.pipe(gulp.dest('./assets/dist/js/'))
|
2016-11-21 12:24:50 +00:00
|
|
|
});
|
|
|
|
|
2016-12-08 11:43:13 +00:00
|
|
|
gulp.task('minify', function(cb) {
|
2016-12-08 12:09:21 +00:00
|
|
|
process.env.NODE_ENV = 'production';
|
2016-12-10 14:58:54 +00:00
|
|
|
|
2016-12-08 11:43:13 +00:00
|
|
|
pump([
|
2018-04-20 11:12:23 +00:00
|
|
|
gulp.src('./assets/dist/js/*.js'),
|
2016-12-08 11:43:13 +00:00
|
|
|
uglify().on('error', gutil.log),
|
2018-04-20 11:12:23 +00:00
|
|
|
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() {
|
2018-04-20 11:12:23 +00:00
|
|
|
return gulp.src('./assets/src/img/**/*')
|
|
|
|
.pipe(gulp.dest('./assets/dist/img'))
|
2016-11-26 15:17:52 +00:00
|
|
|
});
|
|
|
|
|
2018-04-20 11:12:23 +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
|
|
|
|
2016-11-25 15:03:47 +00:00
|
|
|
gulp.task('tracker', function() {
|
2018-04-20 11:12:23 +00:00
|
|
|
return gulp.src('./assets/src/js/tracker.js')
|
|
|
|
.pipe(gulp.dest('./assets/dist/js'))
|
2016-11-25 15:03:47 +00:00
|
|
|
});
|
|
|
|
|
2016-11-21 12:24:50 +00:00
|
|
|
gulp.task('sass', function () {
|
2018-04-20 11:12:23 +00:00
|
|
|
var files = './assets/src/sass/[^_]*.scss';
|
2016-11-21 12:24:50 +00:00
|
|
|
return gulp.src(files)
|
|
|
|
.pipe(sass())
|
2016-11-23 14:51:19 +00:00
|
|
|
.on('error', gutil.log)
|
2016-11-21 12:24:50 +00:00
|
|
|
.pipe(rename({ extname: '.css' }))
|
2018-04-20 11:12:23 +00:00
|
|
|
.pipe(gulp.dest('./assets/dist/css'))
|
2016-11-21 12:24:50 +00:00
|
|
|
});
|
2016-11-21 15:01:14 +00:00
|
|
|
|
|
|
|
gulp.task('watch', ['default'], function() {
|
2018-04-20 11:12:23 +00:00
|
|
|
gulp.watch(['./assets/src/js/**/*.js'], ['browserify', 'tracker'] );
|
|
|
|
gulp.watch(['./assets/src/sass/**/**/*.scss'], ['sass'] );
|
2016-11-21 15:01:14 +00:00
|
|
|
});
|