-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
96 lines (85 loc) · 2.72 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
var gulp = require('gulp'),
gutil = require('gulp-util'),
sass = require('gulp-sass'),
csso = require('gulp-csso'),
uglify = require('gulp-uglify'),
jade = require('gulp-jade'),
concat = require('gulp-concat'),
livereload = require('gulp-livereload'), // Livereload plugin needed: https://chrome.google.com/webstore/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei
tinylr = require('tiny-lr'),
express = require('express'),
connect = require('gulp-connect'),
app = express(),
marked = require('marked'), // For :markdown filter in jade
path = require('path'),
server = tinylr(),
rename = require('gulp-rename'),
ts = require('gulp-typescript'),
argv = require('yargs').argv,
gulpif = require('gulp-if'),
sourcemaps = require('gulp-sourcemaps');
gulp.task('css', function() {
return gulp.src('src/assets/stylesheets/main.scss')
.pipe(
sass( {
includePaths: ['src/assets/stylesheets'],
errLogToConsole: true
} ) )
.pipe( csso() )
.pipe( gulp.dest('dist/assets/stylesheets/') )
.pipe( connect.reload());
});
// Concatenate & Minify JS
gulp.task('ts', function() {
var tsResult = gulp.src('src/assets/scripts/*.ts')
.pipe(sourcemaps.init()) // This means sourcemaps will be generated
.pipe(ts({
target: 'ES5',
module: 'system',
moduleResolution: 'node',
sourceMap: true,
declaration: true,
emitDecoratorMetadata: true,
experimentalDecorators: true,
removeComments: false,
noImplicitAny: false,
out: 'scripts.js'
}));
return tsResult.js
.pipe(concat('scripts.min.js')) // You can use other plugins that also support gulp-sourcemaps
.pipe(uglify())
.pipe(gulpif(argv.dev, sourcemaps.write())) // Now the sourcemaps are added to the .js file
.pipe(gulp.dest('dist/assets/scripts/'))
.pipe( connect.reload());
});
gulp.task('templates', function() {
return gulp.src('src/*.jade')
.pipe(jade({
pretty: true
}))
.pipe(gulp.dest('dist/'))
.pipe( connect.reload());
});
gulp.task('express', function() {
app.use(express.static(path.resolve('./dist')));
app.listen(1337);
gutil.log('Listening on port: 1337');
});
gulp.task('watch', function () {
server.listen(35729, function (err) {
if (err) {
return console.log(err);
}
gulp.watch('src/assets/stylesheets/*.scss',['css']);
gulp.watch('src/assets/scripts/*.ts',['ts']);
gulp.watch('src/**/*.jade',['templates']);
});
});
gulp.task('connect', function() {
connect.server({
root: 'dist',
livereload: true
});
});
// Default Task
gulp.task('default', ['ts','css','templates','express', 'watch', 'connect']);