-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
91 lines (70 loc) · 1.83 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
'use strict';
var gulp = require('gulp'),
htmlbuild = require('gulp-htmlbuild'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
livereload = require('gulp-livereload'),
rimraf = require('rimraf'),
http = require('http'),
opn = require('opn'),
clivereload = require('connect-livereload'),
es = require('event-stream'),
connect = require('connect'),
serveStatic = require('serve-static'),
serveIndex = require('serve-index');
var lrport = 35900,
port = 9002,
environment = './';
var gulpSrcJs = function (opts) {
var paths = es.through();
var files = es.through();
paths.pipe(es.writeArray(function (err, srcs) {
gulp.src(srcs, opts)
.pipe(uglify())
.pipe(files);
}));
return es.duplex(paths, files);
};
var jsBuild = es.pipeline(
concat('stats.js'),
gulp.dest('./dist')
);
gulp.task('clean', function (cb) {
rimraf('dist', cb);
});
gulp.task('scripts', function () {
gulp.src(['./index.html'])
.pipe(htmlbuild({
// build js with preprocessor
js: htmlbuild.preprocess.js(function (block) {
block.pipe(gulpSrcJs())
.pipe(jsBuild);
block.end('stats.js');
})
}))
.pipe(gulp.dest('./dist'));
});
gulp.task('connect', function () {
console.log('Development environment');
var app = connect()
.use(clivereload({ port: lrport }))
.use(serveStatic(environment))
.use(serveIndex('./'));
http.createServer(app)
.listen(port)
.on('listening', function() {
console.log('Started connect web server on http://localhost:' + port);
});
});
gulp.task('serve', ['connect'], function () {
livereload.listen(lrport);
opn('http://localhost:' + port);
gulp.watch([
'./*.html',
'./**/*.js',
]).on('change', livereload.changed);
});
gulp.task('build', ['scripts']);
gulp.task('default', ['clean'], function () {
//gulp.start('build');
});