-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.babel.js
executable file
·65 lines (56 loc) · 1.54 KB
/
gulpfile.babel.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
/**
* Created by es on 10.02.2016.
*/
'use strict';
const { src, dest, series} = require('gulp');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const stripComment = require('gulp-strip-comments');
const stripDebug = require('gulp-strip-debug');
const express = require('express');
const open = require('open');
const babel = require('gulp-babel');
function compileJS(done) {
return src('src/localconnection.js')
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(dest('test/'))
.pipe(stripDebug())
.pipe(stripComment())
.pipe(uglify())
.pipe(rename('localconnection.min.js'))
.pipe(dest('dist/'))
.on("finish",done);
}
function js(cb){
compileJS(cb);
}
function serve(cb) {
const options = {
dotfiles: 'ignore',
etag: false,
extensions: ['htm', 'html', 'js', 'css'],
index: ['index.html'],
maxAge: '1d',
redirect: false,
setHeaders: function (res, pathname, stat) {
res.set('x-timestamp', Date.now())
}
}
const guest = express();
const host = express();
guest.use(express.static('test/guest'));
guest.use(express.static('dist', options));
host.use(express.static('test/host', options));
host.use(express.static('dist', options));
guest.listen(3200);
host.listen(3000);
compileJS(() => {
open('http://127.0.0.1:3000');
});
cb();
}
exports.js=compileJS;
exports.serve=series(js,serve);
exports.default=compileJS;