gulpfile.js
1.9 KB
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
const gulp = require('gulp');
const nodemon = require('gulp-nodemon');
const del = require('del');
const plumber = require('gulp-plumber');
const livereload = require('gulp-livereload');
const runSequence = require('run-sequence');
const sass = require('gulp-sass');
const autoprefixr = require('gulp-autoprefixer');
const buffer = require('vinyl-buffer');
const uglify = require('gulp-uglify');
const babelify = require('babelify');
const browserify = require('browserify');
const concat = require('gulp-concat');
const tap = require('gulp-tap');
gulp.task('sass', function () {
gulp.src('./assets/styles/*.scss')
.pipe(plumber())
.pipe(sass())
.pipe(gulp.dest('./public/css'))
.pipe(livereload());
});
gulp.task('scripts', function () {
const scripts = [
'./assets/scripts/*.js'
];
return gulp.src(scripts, { read: false }) // no need of reading file because browserify does.
// transform file objects using gulp-tap plugin
.pipe(tap(function (file) {
// replace file contents with browserify's bundle stream
file.contents = browserify({
entries: file.path,
transform: [babelify],
paths: [
'./node_modules/',
'./assets/scripts/'
]
}).bundle();
}))
// transform streaming contents into buffer contents
.pipe(buffer())
// .pipe(uglify())
.pipe(gulp.dest('public/js'));
});
gulp.task('watch', function() {
gulp.watch('./assets/styles/*.scss', ['sass']);
});
gulp.task('develop', function () {
livereload.listen();
nodemon({
script: 'app.js',
ext: 'js nunjucks',
stdout: false
}).on('readable', function () {
this.stdout.on('data', function (chunk) {
if(/^Express server listening on port/.test(chunk)){
livereload.changed(__dirname);
}
});
this.stdout.pipe(process.stdout);
this.stderr.pipe(process.stderr);
});
});
gulp.task('default', [
'sass',
'develop',
'watch'
]);