-
Notifications
You must be signed in to change notification settings - Fork 7
/
gulpfile.js
85 lines (73 loc) · 2.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
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
/**
* This file is dependent on gulp which automate tasks.
*
* /
/**
* Including necesaary libraries for gulp to run.
* Note: These libraries can be installed via node package manager.
*/
var gulp = require('gulp'),
cleanCSS = require('gulp-clean-css'),
mocha = require('gulp-mocha'),
nodemon = require('gulp-nodemon'),
sass = require('gulp-sass'),
bower = require('gulp-bower'),
bundle = require('gulp-bundle-assets'),
livereload = require('gulp-livereload');
// makes browser do a full-page refresh when change is made on static files (.js,.scss,.html)
var browserSync = require("browser-sync").create();
gulp.task("default", [ 'start' ,'sass','css' , 'bundle', 'watch','bower']);
// monitors files for changes and reloads web browser
gulp.task('css', function() {
gulp.src('public/css/*.css')
.pipe(cleanCSS())
.pipe(gulp.dest('css'))
.pipe(livereload("./public/views"));
});
gulp.task('watch', function(){
gulp.watch('public/css/common.scss', ['sass']);
gulp.watch('public/css/**', browserSync.reload);
gulp.watch('public/css/*.css', ['css']);
gulp.watch('public/views/**', browserSync.reload);
gulp.watch('app/views/**', browserSync.reload);
gulp.watch(['public/js/**', 'app/**/*.js'], browserSync.reload);
livereload.listen();
});
gulp.task('sass', function () {
gulp.src('public/css/common.scss')
.pipe(sass())
.pipe(gulp.dest('./public/css/'))
});
// bower task
gulp.task('bower', function(){
bower()
.pipe(gulp.dest('./public/lib/'))
});
// mocha test
gulp.task('mocha', function () {
gulp.src(['./test/**/*.js'], { read: false })
.pipe(mocha({ reporter: 'spec' }))
.once('error', () => {
process.exit();
})
.once('end', () => {
process.exit();
})
})
gulp.task('start', function () {
nodemon({
script: 'server.js'
, ext: 'js html'
, env: { 'NODE_ENV': 'development' }
})
})
gulp.task('bundle', function () {
return gulp.src('./bundle.config.js')
.pipe(bundle())
.pipe(bundle.results('./')) // param is destination of bundle.result.json
.pipe(gulp.dest('./public/bundle'))
})
// install task
gulp.task('install', ['sass', 'css', 'bundle', 'bower']);
// test task
gulp.task('test', ['mocha']);