silvrgit/gulpfile.js

123 lines
4.5 KiB
JavaScript
Raw Normal View History

2017-03-22 15:48:36 +00:00
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');
2017-03-22 15:48:36 +00:00
const filePath = {
'build_dir': 'live'
2017-03-22 15:48:36 +00:00
};
const dest = 'app/live';
2017-03-22 15:48:36 +00:00
const fontOptions = { };
2017-04-11 13:30:48 +00:00
const customOpts = {
'entries': ['./app/appV2.js'],
'debug': true
};
const opts = assign({}, watchify.args, customOpts);
const b = watchify(browserify(opts));
2017-03-22 15:48:36 +00:00
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`));
2017-03-22 15:48:36 +00:00
});
2017-04-05 13:22:31 +00:00
gulp.task('customMUI', function() {
return gulp.src(['app/css/custom.scss'])
.pipe(sass({ 'outputStyle': 'compressed' }).on('error', sass.logError))
// .pipe(cssnano())
2017-04-05 13:22:31 +00:00
.pipe(rename('mui.custom.css'))
.pipe(gulp.dest(`${dest}/css`));
2017-04-05 13:22:31 +00:00
});
2017-03-22 15:48:36 +00:00
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`));
});
2017-04-02 23:07:55 +00:00
2017-04-05 13:22:31 +00:00
gulp.task('fonts', function() {
return gulp.src('./fonts.list')
.pipe(googleWebFonts(fontOptions))
.pipe(gulp.dest(`${dest }/fonts`))
;
2017-04-05 13:22:31 +00:00
});
2017-04-02 23:07:55 +00:00
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