/** * Created by martin on 11/23/16. */ var gulp = require('gulp'); var autoprefixer = require('gulp-autoprefixer'); var cssnano = require('gulp-cssnano'); var jshint = require('gulp-jshint'); var uglify = require('gulp-uglify'); var rename = require('gulp-rename'); var concat = require('gulp-concat'); var notify = require('gulp-notify'); var cache = require('gulp-cache'); var livereload = require('gulp-livereload'); var htmlmin = require('gulp-htmlmin'); var inject = require('gulp-inject'); var update = require('gulp-banner'); var atob = require('atob'); var del = require('del'); var htmlreplace = require('gulp-html-replace'); var stripDebug = require('gulp-strip-debug'); var babel = require('gulp-babel'); var filePath = { build_dir: './dist' }; var fontOptions = { }; gulp.task('appJS', function() { return gulp.src(['app/js/websocket.js','app/js/tempSocket.js','app/js/modules/clock.js','app/js/modules/temp.js','app/js/app.js']) .pipe(stripDebug()) .pipe(jshint('.jshintrc')) .pipe(jshint.reporter('default')) .pipe(babel({presets: ['es2015']})) .pipe(concat('app.js')) .pipe(uglify({mangle: true, compress: {sequences: true, // Join consecutive statemets with the “comma operator” properties: true, // Optimize property access: a["foo"] → a.foo dead_code: true, // Discard unreachable code drop_debugger: true, // Discard “debugger” statements unsafe: false, // Some unsafe optimizations (see below) conditionals: true, // Optimize if-s and conditional expressions comparisons: true, // Optimize comparisons evaluate: true, // Evaluate constant expressions booleans: true, // Optimize boolean expressions loops: true, // Optimize loops unused: true, // Drop unused variables/functions hoist_funs: true, // Hoist function declarations hoist_vars: false, // Hoist variable declarations if_return: true, // Optimize if-s followed by return/continue join_vars: true, // Join var declarations cascade: true, // Try to cascade `right` into `left` in sequences side_effects: true, // Drop side-effect-free statements warnings: true, // Warn about potentially dangerous optimizations/code global_defs: {} // global definitions }})) .pipe(update(atob('LyogPT09PT09PQ0KDQpEZXZlbG9wZWQgYnkgTWFydGluIERvbm5lbGx5IG1hcnRpbmQyMDAwe2F0fWdtYWlsLmNvbQ0KDQo9PT09PT09ICovDQoNCg=='))) .pipe(gulp.dest('dist/js')); }); gulp.task('vendor', function() { return gulp.src([ 'bower_components/jquery/dist/jquery.min.js', 'bower_components/underscore/underscore-min.js', 'bower_components/backbone/backbone-min.js', 'app/libs/sugar-full.min.js' ]) .pipe(concat('vendor.js')) .pipe(uglify({mangle: false})) .pipe(gulp.dest('dist/js')); }); gulp.task('styles', function() { return gulp.src([ 'app/css/custom.css', 'app/css/today.css']) .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4')) .pipe(cssnano()) .pipe(concat('app.css')) .pipe(gulp.dest('dist/css')); }); gulp.task('index', function() { return gulp.src(['app/index.html']) .pipe(htmlreplace({ mui: 'css/custom.css', css: 'css/app.css', js: 'js/app.js', vendor: 'js/vendor.js' })) .pipe(htmlmin({removeComments: true, collapseWhitespace: true, keepClosingSlash: true})) .pipe(gulp.dest('dist/')); }); gulp.task('buildJS', function() { gulp.start('appJS','vendor'); }); gulp.task('clean', function() { return del(['dist']); }); gulp.task('default', ['clean'], function() { gulp.start('buildJS','styles','index'); });