From 0193315dd52bf763d7b8f570039cd1771b2e725c Mon Sep 17 00:00:00 2001 From: Indrajith K L Date: Sun, 12 Aug 2018 17:52:54 +0530 Subject: :arrow_up: :gem: * Support ES6 * Integrates jsfxr --- gulpfile.js | 64 +++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 21 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 68c26f3..0bb7f86 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,56 +1,78 @@ 'use strict'; var gulp = require('gulp'); -var browserSync = require('browser-sync').create(); +var browserSync = require('browser-sync'); var uglify = require('gulp-uglify'); -const zip = require('gulp-vinyl-zip').zip; +var zip = require('gulp-vinyl-zip').zip; var size = require('gulp-size'); +var runSequence = require('run-sequence'); +let rollup = require('rollup-stream'); +var source = require('vinyl-source-stream'); var libs = ['./node_modules/kontra/kontra.min.js', './node_modules/tinymusic/dist/TinyMusic.min.js']; +var devLibs = ['./node_modules/jsfxr/jsfxr.js']; var libFolder = 'libs/'; var outputTemp = 'temp/'; -gulp.task('serve', ['copylibs'], function () { - +gulp.task('serve', ['copylibs', 'copylibsDev', 'uglyfy_copy'], function () { browserSync.init({ - server: './' + server: { + baseDir: "./" + } }); - gulp.watch("./**/*.js", { cwd: './' },function(){ - gulp.run('uglyfy_copy') - }).on('change', browserSync.reload);; + gulp.watch("src/js/**/*.js", { cwd: './' }, ['uglyfy_copy', 'reload']) gulp.watch("./**/*.html", { cwd: './' }).on('change', browserSync.reload); browserSync.watch() }); +gulp.task('reload', function () { + browserSync.reload(); +}); + + gulp.task('uglyfy_copy', function () { - return gulp.src('src/js/*.js') - .pipe(uglify()) - .pipe(gulp.dest('public/js')); + return rollup({ + "format": "iife", + input: './src/js/main.js' + }) + .pipe(source('main.js')) + .pipe(gulp.dest('public/js')); }); gulp.task('copylibs', function () { return gulp - .src(libs) - .pipe(gulp.dest(libFolder)) + .src(libs) + .pipe(gulp.dest(libFolder)) }); -gulp.task('zipFiles',['prepare_dist_folder'], function () { +gulp.task('copylibsDev', function () { + return gulp + .src(devLibs) + .pipe(uglify()) + .pipe(gulp.dest(libFolder)) +}); + +gulp.task('zipFiles', function () { return gulp.src('temp/**/*.*') - .pipe(zip('archive.zip')) - .pipe(gulp.dest('dist')) - .pipe(size({ - title: '### Final Archive Size => ' - })) + .pipe(zip('archive.zip')) + .pipe(gulp.dest('dist')) + .pipe(size({ + title: '### Final Archive Size => ' + })) }); gulp.task('prepare_dist_folder', function () { return gulp - .src(['libs/*','public/**/*.*','index.html'],{base: './'}) - .pipe(gulp.dest(outputTemp)) + .src(['libs/*', 'public/**/*.*', 'index.html'], { base: './' }) + .pipe(gulp.dest(outputTemp)) +}); + +gulp.task('release', function () { + runSequence('copylibs', 'copylibsDev', 'uglyfy_copy', 'prepare_dist_folder', 'zipFiles'); }); -- cgit v1.2.3