-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
110 lines (100 loc) · 3.12 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
110
var gulp = require('gulp'); // Main gulp module
//var ts = require('gulp-typescript'); // Compiles Typescript
//var del = require('del'); // Deletes files
var browserify = require('browserify'); // Combines js files
var uglify = require('gulp-uglify'); // Minifies files
//var glob = require('glob'); // Lets you use * in filenames
//var requirejs = require('requirejs'); // AMD module loader
var tsify = require('tsify'); // Compiles typescript after combining with browserify
var source = require('vinyl-source-stream'); // Converts output file to stream
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var browserSync = require('browser-sync').create();
var sass = require('gulp-sass');
// Setup browser-sync
gulp.task('browserSync', function(){
browserSync.init({
server: {
baseDir: 'dist'
}
});
});
// Just browserifyies looking for app.js Not being used right now.
/*
gulp.task('browserify', function() {
return browserify('./src/app.js')
.bundle()
//Pass desired output filename to vinyl-source-stream
.pipe(source('bundle.js'))
// Start piping stream to tasks!
.pipe(gulp.dest('./dist/'));
});
*/
// Just compiles ts into js. Old, didn't work for what I needed.
/*
gulp.task('compile', function(){
return gulp.src('./src/ts/*.ts')
.pipe(ts({
noImplicitAny: true,
declaration: true,
module: 'amd',
out: 'app.js'
}))
.pipe(gulp.dest('./src/js'));
});
*/
// Build app.ts by browserifying it to get dependencies and run through tsify to compile typescript to javascript
gulp.task('build', function(){
browserify()
.add("./src/ts/app.ts")
.plugin(tsify, { noImplicitAny: true, target: 'ES5' })
.bundle()
.on('error', function(error){console.error(error.toString());})
.pipe(source('bundle.js'))
.pipe(gulp.dest('./src/js'))
.pipe(browserSync.reload({
stream: true
}));
});
// Setup watch files
gulp.task('watch', ['build', 'scripts', 'css', 'browserSync'], function(){
gulp.watch('./src/ts/*.ts', ['build']);
gulp.watch('./src/js/*.js', ['scripts']);
gulp.watch('./src/**/*.+(html|htm)', ['html']);
gulp.watch('./src/css/**/*.css', ['css']);
gulp.watch('./src/sass/**/*.+(scss|sass)', ['sass']);
});
gulp.task('html', function(){
return gulp.src('./src/**/*.+(html|htm)')
.pipe(gulp.dest('./dist'))
.pipe(browserSync.reload({
stream: true
}));
});
// Concatenate and minifiy scripts
gulp.task('scripts', function(){
return gulp.src('./src/**/*.js')
.pipe(concat('all.js'))
.pipe(gulp.dest('./dist/js'))
.pipe(uglify())
.pipe(rename('all.min.js'))
.pipe(gulp.dest('./dist/js'))
.pipe(browserSync.reload({
stream: true
}));
});
gulp.task('sass', function(){
return gulp.src('./src/sass/**/*.+(sass|scss)')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./src/css'));
});
gulp.task('css', ['sass'], function(){
return gulp.src('./src/css/**/*.css')
.pipe(concat('all.css'))
.pipe(gulp.dest('./dist/css'))
.pipe(browserSync.reload({
stream: true
}));
});
gulp.task('default', ['watch'], function(){
});