const gulp = require('gulp'); const autoprefixer = require('gulp-autoprefixer'); const cssnano = require('gulp-cssnano'); const jshint = require('gulp-jshint'); const uglify = require('gulp-uglify'); const rename = require('gulp-rename'); const concat = require('gulp-concat'); const cache = require('gulp-cache'); const htmlmin = require('gulp-htmlmin'); const htmlreplace = require('gulp-html-replace'); const stripDebug = require('gulp-strip-debug'); const scss = require('gulp-scss'); const sass = require('gulp-sass'); const googleWebFonts = require('gulp-google-webfonts'); const babel = require('gulp-babel'); // const watchify = require('watchify'); const browserify = require('browserify'); const source = require('vinyl-source-stream'); const buffer = require('vinyl-buffer'); const gutil = require('gulp-util'); const sourcemaps = require('gulp-sourcemaps'); const assign = require('lodash.assign'); const filePath = { 'build_dir': 'live' }; const dest = 'app/live'; const fontOptions = { }; const customOpts = { 'entries': ['./app/appV2.js'], 'debug': true }; const opts = assign({}, watchify.args, customOpts); const b = watchify(browserify(opts)); gulp.task('appJS', function() { return gulp.src(['app/js/websocket.js', 'app/js/slackSocket.js', 'app/js/modules/events.js', 'app/js/modules/bitcoin.js', 'app/js/modules/fx.js', 'app/js/modules/train.js', 'app/js/modules/weatherV2.js', 'app/js/modules/password.js', 'app/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': true, // 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(gulp.dest(`${dest }/js`)); }); gulp.task('customMUI', function() { return gulp.src(['app/css/custom.scss']) .pipe(sass({ 'outputStyle': 'compressed' }).on('error', sass.logError)) // .pipe(cssnano()) .pipe(rename('mui.custom.css')) .pipe(gulp.dest(`${dest}/css`)); }); gulp.task('vendor', function() { return gulp.src([ 'bower_components/zepto/zepto.min.js', 'bower_components/ejs/ejs.min.js', 'bower_components/underscore/underscore-min.js', 'bower_components/backbone/backbone-min.js', 'bower_components/moment/min/moment.min.js' ]) .pipe(concat('vendor.js')) /* .pipe(uglify({ 'mangle': false }))*/ .pipe(gulp.dest(`${dest }/js`)); }); gulp.task('fonts', function() { return gulp.src('./fonts.list') .pipe(googleWebFonts(fontOptions)) .pipe(gulp.dest(`${dest }/fonts`)) ; }); gulp.task('migrate', function() { return gulp.src(['./app/css/weather.css']) .pipe(gulp.dest(`${dest}/css`)); }); function bundle() { return b.bundle() // log errors if they happen .on('error', gutil.log.bind(gutil, 'Browserify Error')) .pipe(source('bundle.js')) // optional, remove if you don't need to buffer file contents .pipe(buffer()) // optional, remove if you dont want sourcemaps .pipe(sourcemaps.init({ 'loadMaps': true })) // loads map from browserify file // Add transformation tasks to the pipeline here. .pipe(sourcemaps.write('./')) // writes .map file .pipe(gulp.dest('./app')); } gulp.task('default', ['appJS', 'vendor', 'customMUI', 'fonts', 'migrate']); gulp.task('js', bundle); // so you can run `gulp js` to build the file b.on('update', bundle); // on any dep update, runs the bundler b.on('log', gutil.log); // output build logs to terminal