-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
129 lines (111 loc) · 4.23 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
var gulp = require('gulp');
var changed = require('gulp-changed');
var nodemon = require('gulp-nodemon');
var less = require('gulp-less');
var browserSync = require('browser-sync').create();
var header = require('gulp-header');
var cleanCSS = require('gulp-clean-css');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var pkg = require('./package.json');
// Set the banner content
var banner = ['/*!\n',
' * <%= pkg.title %> v<%= pkg.version %> (<%= pkg.homepage %>)\n',
' * Copyright ' + (new Date()).getFullYear(), ' <%= pkg.author %>\n',
' * Licensed under <%= pkg.license %>\n',
' */\n',
''
].join('');
// Reload function for browserSync
function reloadBrowser(done) {
browserSync.reload();
done();
}
// Minify compiled CSS
gulp.task('minify-css', function() {
return gulp.src('css/style.css')
.pipe(cleanCSS({ compatibility: 'ie8' }))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('css'))
.pipe(browserSync.reload({
stream: true
}))
});
// Compile LESS files from /less into /css
gulp.task('less', gulp.series(function() {
return gulp.src('less/style.less')
.pipe(less().on('error', function(e) { console.log(e); this.emit('end'); }))
.pipe(header(banner, { pkg: pkg }))
.pipe(gulp.dest('css'))
.pipe(browserSync.reload({
stream: true
}))
}, 'minify-css'));
// Minify JS
gulp.task('minify-js', function() {
return gulp.src(['js/**/*.js', '!**/*.min.js'])
.pipe(uglify().on('error', function(e) { console.log(e); this.emit('end'); }))
.pipe(header(banner, { pkg: pkg }))
.pipe(rename({ suffix: '.min' }))
.pipe(changed('js'))
.pipe(gulp.dest('js'))
.pipe(browserSync.reload({
stream: true
}))
});
// Copy vendor libraries from /node_modules into /vendor
gulp.task('copy', function() {
gulp.src(['node_modules/bootstrap/dist/**/*', '!**/npm.js', '!**/bootstrap-theme.*', '!**/*.map'])
.pipe(gulp.dest('ext/bootstrap'))
gulp.src(['node_modules/tether/dist/**'])
.pipe(gulp.dest('ext/tether'))
gulp.src(['node_modules/jquery/dist/jquery.js', 'node_modules/jquery/dist/jquery.min.js'])
.pipe(gulp.dest('ext/jquery'))
gulp.src(['node_modules/requirejs/require.js'])
.pipe(gulp.dest('ext/requirejs'))
.pipe(uglify().on('error', function(e) { console.log(e); this.emit('end'); }))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('ext/requirejs'))
gulp.src(['node_modules/promise-polyfill/dist/polyfill.js', 'node_modules/promise-polyfill/dist/polyfill.min.js'])
.pipe(gulp.dest('ext/polyfill'))
gulp.src([
'node_modules/@fortawesome/fontawesome-free-webfonts/**',
'!node_modules/@fortawesome/fontawesome-free-webfonts/css',
'!node_modules/@fortawesome/fontawesome-free-webfonts/**/*.map',
'!node_modules/@fortawesome/fontawesome-free-webfonts/.npmignore',
'!node_modules/@fortawesome/fontawesome-free-webfonts/*.txt',
'!node_modules/@fortawesome/fontawesome-free-webfonts/*.md',
'!node_modules/@fortawesome/fontawesome-free-webfonts/*.json'
]).pipe(gulp.dest('ext/font-awesome'))
gulp.src(['node_modules/@fortawesome/fontawesome-free-webfonts/css/*',])
.pipe(cleanCSS({ compatibility: 'ie8' }))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('ext/font-awesome/css'))
gulp.src(['node_modules/node-forge/dist/forge.min.js', 'node_modules/node-forge/dist/forge.all.min.js'])
.pipe(gulp.dest('ext/forge'))
});
// Configure browserWatch task
gulp.task('watch', function() {
gulp.watch('less/*.less', gulp.series('less'));
gulp.watch(['js/**/*.js', '!js/**/*.min.js'], gulp.series('minify-js'));
// Reloads the browser whenever HTML or JS files change
gulp.watch(['views/**/*.ejs', '*.js', 'js/**/*.js', '!js/**/*.min.js'], reloadBrowser);
});
// Node monitor
gulp.task('nodemon', function(done) {
var callbackCalled = false;
return nodemon({ script: 'server.js', watch: ['server.js', 'helper.js', '**/*.md'] }).on('start', function() {
if(!callbackCalled) {
callbackCalled = true;
done();
}
}).on('restart', browserSync.reload);
});
// Browser Sync
gulp.task('browser-sync', gulp.series('nodemon', function() {
browserSync.init({
proxy: 'http://localhost:5000', // port of node server
});
}));
// Dev tasks (connect with browser sync.)
gulp.task('dev', gulp.series('minify-css', 'minify-js', gulp.parallel('browser-sync', 'watch')));