-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
110 lines (82 loc) · 2.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'),
vinyl = require('vinyl-source-stream'),
browserify = require('browserify'),
babelify = require('babelify'),
babel = require('gulp-babel'),
sourceMaps = require('gulp-sourcemaps'),
nodemon = require('nodemon');
bSync = require('browser-sync').create();
var serverRunning = false;
//Source paths
var src = {
client: {
scripts: {
entry: 'app/client/scripts/app.js',
all: 'app/client/scripts/**/*.js'
},
html: "app/client/**/*.html"
},
server: {
scripts: 'app/server/**/*.js'
}
}
//Distirbution paths
var dist = {
client: {
root: 'dist/client',
scripts: 'dist/client/scripts'
},
server: {
root: 'dist/server',
app: 'dist/server/server.js'
}
}
//Convert Code to ES5 and transform JSX
gulp.task('client-scripts', function() {
browserify({
entries: src.client.scripts.entry,
debug: true
})
.transform(babelify)
.bundle()
.pipe(vinyl('bundle.js'))
.pipe(gulp.dest(dist.client.scripts))
.pipe(bSync.stream());
});
gulp.task('server-scripts', function() {
gulp.src(src.server.scripts)
.pipe(sourceMaps.init())
.pipe(babel())
// .pipe(sourceMaps.write('.', {sourceRoot: dist.server}))
.pipe(gulp.dest(dist.server.root));
})
//Pass over html files
gulp.task('html', function() {
return gulp.src(src.client.html)
.pipe(gulp.dest(dist.client.root))
.pipe(bSync.stream());
})
//Basic build
gulp.task('default', ['server-scripts', 'client-scripts', 'html'], function() {});
//Watch and build
gulp.task('start', ['default', 'nodemon'], function() {
bSync.init({
proxy: "http://localhost:9000", // wrap the express server
browser: "google chrome",
port: 7000
});
gulp.watch(src.client.scripts.all, ['client-scripts'], bSync.reload());
gulp.watch(src.client.html, ['html'], bSync.reload());
gulp.watch(src.server.scripts, ['server-scripts']);
})
//Run the server
gulp.task('nodemon', function (cb) {
return nodemon({
script: dist.server.app
}).on('start', function () {
if (!serverRunning) {
serverRunning = true;
cb();
}
});
});