-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
51 lines (44 loc) · 1.21 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
var gulp = require('gulp');
var rename = require('gulp-rename');
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
var source = require("vinyl-source-stream");
var express = require('express');
var livereload = require('gulp-livereload');
var config = {
name: 'test',
listen: 3000,
dist: './dist/',
entry: 'src/index.js',
files: {
src: 'src/**/*.js',
static: 'pub/**/*.html'
}
}
gulp.task('build', ['build-src', 'build-static']);
gulp.task('build-src', function () {
browserify()
.add('src/index.js', {entry: true})
.bundle()
.pipe(source('index.js'))
.pipe(rename(config.name + '.js'))
.pipe(buffer())
.pipe(gulp.dest(config.dist + 'scripts/'))
});
gulp.task('build-static', function () {
gulp.src(config.files.static)
.pipe(gulp.dest(config.dist));
});
gulp.task('serve', ['watch'], function () {
express()
.use(express.static(config.dist))
.listen(config.listen, '0.0.0.0');
});
gulp.task('watch', function () {
for (var type in config.files) {
gulp.watch(config.files[type], ['build-' + type]);
}
livereload.listen();
gulp.watch(config.dist + '**').on('change', livereload.changed);
});
gulp.task('default', ['build', 'serve']);