-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
90 lines (81 loc) · 2.29 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'use strict';
var
gulp = require('gulp'),
sass = require('gulp-sass'),
gutil = require('gulp-util'),
deploy = require('gulp-gh-pages'),
browserify = require('browserify'),
babelify = require('babelify'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
uglify = require('gulp-uglify'),
sourcemaps = require('gulp-sourcemaps'),
moduleShim = require('browserify-shim')
;
/*
* Transpile es6 code to es5 using Babel and browserify
*/
gulp.task('transpile', function() {
return browserify('source/js/main.js', { debug : true })
.transform('babelify', { presets: ['es2015'] })
.transform(moduleShim)
.bundle()
.on('error', function(err) {
gutil.log(err.stack);
this.emit('end');
})
.pipe(source('main.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./build'));
});
/*
* Copy non-browserify vendor dependencies to the build directory
*/
gulp.task('vendor', function() {
return gulp.src('./source/vendor/**/*')
.pipe(gulp.dest('./build/vendor'));
});
/*
* Copy resource files to the build directory
*/
gulp.task('resources', function() {
return gulp.src('./resources/**/*')
.pipe(gulp.dest('./build/resources'));
});
/*
* Copy HTML files over
*/
gulp.task('html', function() {
return gulp.src('source/**/*.html')
.pipe(gulp.dest('./build'));
});
/*
* Convert SASS files to CSS
*/
gulp.task('sass', function() {
return gulp.src('source/sass/**/main.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./build'));
});
/*
* Build the project and push contents of '/build' directory to the 'deploy-prod' branch
*/
gulp.task('deploy', ['build'], function() {
return gulp.src('./build/**/*')
.pipe(deploy());
});
/*
* Watch for when JS, HTML, or SCSS files change so they can be updated
*/
gulp.task('watch', function() {
gulp.watch('source/**/*.js', ['transpile']);
gulp.watch('source/**/*.html', ['html']);
gulp.watch('source/**/*.scss', ['sass']);
gulp.watch('source/vendor/**/*', ['vendor']);
gulp.watch('resources/**/*', ['resources']);
});
gulp.task('build', ['transpile', 'sass', 'html', 'vendor', 'resources']);
gulp.task('default', ['build']);