forked from chrisbruford/knights-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
130 lines (118 loc) · 3.71 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
"use strict";
let gulp = require('gulp');
let sass = require('gulp-sass');
let browserSync = require('browser-sync').create();
let useref = require('gulp-useref');
let uglify = require('gulp-uglify');
let gulpIf = require('gulp-if');
let cssnano = require('gulp-cssnano');
let imagemin = require('gulp-imagemin');
let del = require('del');
let cache = require('gulp-cache');
let runSequence = require('run-sequence');
let wiredep = require('wiredep').stream;
let autoprefixer = require('gulp-autoprefixer');
let nodemon = require('gulp-nodemon');
let KarmaServer = require('karma').Server;
//browserify
let browserify = require('browserify');
let source = require('vinyl-source-stream');
let buffer = require('vinyl-buffer');
let gutil = require('gulp-util');
let sourcemaps = require('gulp-sourcemaps');
let babelify = require('babelify');
gulp.task('browserify', function () {
// set up the browserify instance on a task basis
return browserify({
entries: './public/assets/es6/app.js',
debug: true
})
.transform("babelify", { presets: ["es2015"] })
.bundle()
.pipe(source('app.min.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify())
.on('error', gutil.log)
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./public/js'));
});
gulp.task('sass', function () {
return gulp.src('public/assets/scss/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass({
includePaths: [
'node_modules/foundation-sites/scss/',
'node_modules/motion-ui/src'
]
}))
.pipe(autoprefixer({
browsers: ['last 4 versions'],
cascade: false
}))
.pipe(cssnano())
.pipe(gulp.dest('public/css'))
.pipe(browserSync.reload({
stream: true
}));
});
gulp.task('browserSync',['nodemon'], function () {
browserSync.init({
port: 3876,
proxy: {
target: 'localhost:3000',
ws: true
}
})
});
gulp.task('nodemon', function (cb) {
let called = false;
return nodemon({
script: './bin/www',
ext: 'js html',
ignore: [
'gulpfile.js',
'node_modules/'
],
watch: [
"./",
"*.*",
"routes",
"modules"
]
}).on('start', function () {
if (!called) {
called = true;
cb();
}
}).on('restart',evt=>{
console.log('--------------------nodemon restarting--------------------')
});
});
gulp.task('test', function (done) {
new KarmaServer({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done).start();
});
gulp.task('watch', function () {
gulp.watch('./public/assets/scss/**/*.scss', ['sass']);
gulp.watch('./public/assets/es6/**/*.js', ['browserify', browserSync.reload]);
gulp.watch('./public/modules/**/*.js', ['browserify', browserSync.reload]);
gulp.watch('./public/*.html', browserSync.reload);
gulp.watch('./public/routes/*.html', browserSync.reload);
gulp.watch('./public/modules/**/*.html', browserSync.reload);
});
gulp.task('images', function () {
return gulp.src('public/assets/images/**/*.+(jpg|gif|png|svg)')
.pipe(cache(imagemin({
interlaced: true
})))
.pipe(gulp.dest('public/images'));
});
gulp.task('cache:clear', function (callback) {
return cache.clearAll(callback);
});
gulp.task('default', function () {
runSequence(['sass', 'browserify'], 'browserSync', 'watch');
});