-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
109 lines (85 loc) · 2.62 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var lib = require('bower-files')({
"overrides":{
"bootstrap" : {
"main": [
"less/bootstrap.less",
"dist/css/bootstrap.css",
"dist/js/bootstrap.js"
]
}
}
});
var utilities = require('gulp-util');
var buildProduction = utilities.env.production;
var del = require('del');
var browserSync = require('browser-sync').create();
var shell = require('gulp-shell');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
////////////////////// TYPESCRIPT //////////////////////
gulp.task('tsClean', function(){
return del(['app/*.js', 'app/*.js.map']);
});
gulp.task('ts', ['tsClean'], shell.task([
'tsc'
]));
////////////////////// BOWER //////////////////////
gulp.task('jsBowerClean', function(){
return del(['./build/js/vendor.min.js']);
});
gulp.task('jsBower', ['jsBowerClean'], function() {
return gulp.src(lib.ext('js').files)
.pipe(concat('vendor.min.js'))
.pipe(uglify())
.pipe(gulp.dest('./build/js'));
});
gulp.task('cssBowerClean', function(){
return del(['./build/css/vendor.css']);
});
gulp.task('cssBower', ['cssBowerClean'], function() {
return gulp.src(lib.ext('css').files)
.pipe(concat('vendor.css'))
.pipe(gulp.dest('./build/css'));
});
gulp.task('bower', ['jsBower', 'cssBower']);
////////////////////// SASS //////////////////////
gulp.task('sassBuild', function() {
return gulp.src(['resources/styles/*'])
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(sourcemaps.write())
.pipe(gulp.dest('./build/css'));
});
////////////////////// SERVER //////////////////////
gulp.task('serve', ['build'], function() {
browserSync.init({
server: {
baseDir: "./",
index: "index.html"
}
});
gulp.watch(['resources/js/*.js'], ['jsBuild']); // vanilla js changes, reload.
gulp.watch(['*.html'], ['htmlBuild']); // html changes, reload.
gulp.watch(['resources/styles/*.css', 'resources/styles/*.scss'], ['cssBuild']); gulp.watch(['app/*.ts'], ['tsBuild']); // typescript files change, compile then reload.
});
gulp.task('jsBuild', function(){
browserSync.reload();
});
gulp.task('htmlBuild', function(){
browserSync.reload();
});
gulp.task('cssBuild', ['sassBuild'], function(){
browserSync.reload();
});
gulp.task('tsBuild', ['ts'], function(){
browserSync.reload();
});
////////////////////// GLOBAL BUILD TASK //////////////////////
gulp.task('build', ['ts'], function(){
// we can use the buildProduction environment variable here later.
gulp.start('bower');
gulp.start('sassBuild');
});