-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
71 lines (61 loc) · 2.24 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Task Automation to make my life easier.
* Author: Jean-Pierre Sierens
* ===========================================================================
*/
// declarations, dependencies
// ----------------------------------------------------------------------------
var gulp = require('gulp');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var log = require('fancy-log');
var babelify = require('babelify');
var uglify = require('gulp-uglify');
var buffer = require('vinyl-buffer');
var less = require('gulp-less');
var minifyCSS = require('gulp-csso');
var gulpif = require('gulp-if');
var production = process.env.NODE_ENV === 'production';
// Gulp tasks
// ----------------------------------------------------------------------------
gulp.task('scripts', function () {
return bundleApp(production);
});
gulp.task('less', function(){
return gulp.src('./less/style.less')
.pipe(less())
.pipe(gulpif(production, minifyCSS({keepBreaks:true})))
.pipe(gulp.dest('www/css'));
});
gulp.task('deploy', function (){
return bundleApp(true);
});
gulp.task('watch', function () {
gulp.watch(['./scripts/**/*.js'], gulp.series('scripts'));
gulp.watch(['./less/**/*.less'], gulp.series('less'));
});
// When running 'npx gulp' on the terminal this task will fire.
// It will start watching for changes in every .js file.
// If there's a change, the task 'scripts' defined above will fire.
gulp.task('default', gulp.series(gulp.parallel('scripts', 'less'), 'watch'));
// When deploying, run 'npx gulp build' to fire this, one-shot.
gulp.task('build', gulp.series('deploy', 'less'));
// Private Functions
// ----------------------------------------------------------------------------
function bundleApp(isProduction) {
// Browserify will bundle all our js files together in to one and will let
// us use modules in the front end.
var appBundler = browserify({
entries: './scripts/app.js',
debug: !isProduction
})
return appBundler
// transform ES6 and JSX to ES5 with babelify
.transform(babelify, {presets: ["es2015", "react"]})
.bundle()
.on('error', log)
.pipe(source('app.js'))
.pipe(buffer())
.pipe(gulpif(production, uglify()))
.pipe(gulp.dest('./www/js/'));
}