This repository has been archived by the owner on Jul 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
140 lines (125 loc) · 3.28 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
'use strict';
var gulp = require('gulp'),
connect = require('gulp-connect'),
open = require('gulp-open'),
webpack = require('webpack-stream'),
source = require('vinyl-source-stream'),
concat = require('gulp-concat'),
csslint = require('gulp-csslint'),
lint = require('gulp-eslint'),
nodemon = require('gulp-nodemon'),
livereload = require('gulp-livereload');
var config = {
watch: {
html: [
'./src/public/**/*.html',
'./src/views/**/*.html'
],
css: [
'./src/public/**/*.css'
],
js: [
'./src/js/**/*.js'
],
images: [
'./src/public/images/*'
],
dist: './dist',
main: './src/js/server/main.js'
}
};
// Open the project in the default browser
gulp.task('open', ['start'], function(){
gulp.src('dist/index.html')
.pipe(open({ uri: config.devBaseUrl + ':' + config.port + '/'}));
});
// Start local dev server
gulp.task('start', function () {
nodemon({
exec: 'node',
script: 'server.js',
ext: 'js html',
ignore: ['.git/*', 'node_modules/*'],
env: { 'NODE_ENV': 'development' },
livereload: true,
stdout: false
}).on('readable', function() {
this.stdout.on('data', function(chunk) {
if (/^Listening/.test(chunk)) {
livereload.reload();
}
process.stdout.write(chunk);
});
this.stderr.pipe(process.stderr);
});
});
// Start local dev server and node-inspector
gulp.task('debug', ['inspect'], function(){
nodemon({
exec: 'node-inspector & node --debug',
script: 'server.js',
ext: 'js html',
ignore: ['.git/*', 'node_modules/*'],
env: { 'NODE_ENV': 'development' },
stdout: false
}).on('restart', function () {
this.stdout.on('data', function(chunk) {
if (/^listening/.test(chunk)) {
livereload.reload();
}
process.stdout.write(chunk);
});
this.stderr.pipe(process.stderr);
});
});
// Start node-inspector
gulp.task('inspect', function(){
gulp.src([]).pipe(nodeInspector({ // You'll need to tweak these settings per your setup
debugPort: 5859,
webHost: '0.0.0.0',
webPort: '8085',
preload: false
}));
});
// Lint javascript
gulp.task('jslint', function(){
return gulp.src(config.watch.js)
.pipe(lint({config: '.eslintrc'}))
.pipe(lint.format());
});
// Lint css
gulp.task('csslint', function(){
gulp.src('src/public/*.css')
.pipe(csslint())
.pipe(csslint.reporter());
});
// Lint tasks
gulp.task('lint', ['jslint','csslint']);
// Pack javascript
gulp.task('js', function(){
return gulp.src('./src/js/client/main.jsx')
.pipe(webpack(require('./webpack.config.js')))
.pipe(gulp.dest('./dist'))
.pipe(connect.reload());
});
// Pack css
gulp.task('css', function(){
return gulp.src(config.watch.css)
.pipe(concat('bundle.css'))
.pipe(gulp.dest(config.watch.dist + '/css'))
.pipe(connect.reload());
});
gulp.task('html', function(){
return gulp.src(config.watch.html)
.pipe(connect.reload());
});
// Build tasks
gulp.task('build', ['lint','js','css']);
// Watch files for changes
gulp.task('watch', function(){
livereload.listen();
gulp.watch(config.watch.html, ['html']);
gulp.watch(config.watch.js, ['js', 'lint']);
});
// Default task
gulp.task('default', ['css','js','lint','open','watch']);