-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.js
More file actions
123 lines (103 loc) · 3 KB
/
gulpfile.js
File metadata and controls
123 lines (103 loc) · 3 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
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
// gulpfile by Joel
const gulp = require('gulp');
const sass = require('gulp-sass');
const rename = require('gulp-rename');
const im = require('gulp-imagemin');
const nm = require('gulp-nodemon');
const bs = require('browser-sync').create();
const bsReload = bs.reload;
function sass2css(done) {
let x = gulp.src(['./public/scss/bootstrap/bootstrap.scss', './public/scss/mdb/mdb.scss'])
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(rename({extname: ".min.css"}))
.pipe(gulp.dest('./public/css/vendor'));
output(x, '\x1b[32mSASS to CSS\x1b[0m');
done();
}
function imgCompress(done) {
let x = gulp.src(['./public/img/**/*.png', './public/img/**/*.jpg', './public/img/**/*.jpeg', './public/img/**/*.gif', './public/img/**/*.svg'])
.pipe(im())
.pipe(gulp.dest('./public/img/'));
output(x, '\x1b[32mImage Compress');
done();
}
function startNodemon(done) {
let flag = false;
const x = nm({
script: 'app.js',
stdout: false,
ext: 'handlebars js css',
ignore: [
'gulpfile.js',
'node_modules/',
'.gitignore',
'README.md',
'public/uploads'
]
});
const onReady = () => {
flag = false;
done();
};
x.on('start', () => {
flag = true;
setTimeout(onReady, 1000);
});
x.on('stdout', (stdout) => {
process.stdout.write(stdout);
if (flag) {
onReady();
}
});
}
function startBrowserSync(done) {
bs.init({
proxy: 'localhost:5000',
port: 5050,
browser: 'chrome',
notify: true
});
done();
}
// For cmd/terminal output
function output(gulpSrc, funcName) {
gulpSrc.on('data', function(chunk) {
let contents = chunk.contents.toString().trim();
let buffLength = process.stdout.columns;
let hr = '\n\n' + Array(buffLength).join("_") + '\n\n';
if (contents.length > 1) {
process.stdout.write(funcName + ': ' + chunk.path + '\n');
}
});
process.stdout.write('\n');
}
exports.scss2css = sass2css;
exports.imgmin = imgCompress;
exports.nodemon = startNodemon;
exports.browsersync = startBrowserSync;
exports.compile = () => {
gulp.watch('./public/scss/**/*', sass2css);
// gulp.watch('./public/img/**/*', imgCompress);
};
exports.default = gulp.series(this.nodemon, this.browsersync, () => {
process.stdout.write('\n');
gulp.watch('./public/scss/**/*', sass2css);
gulp.watch('./public/img/**/*', imgCompress);
process.stdout.write('\n');
gulp.watch([
'./public/css/**/*',
'./public/fonts/**/*',
'./public/img/**/*',
'./public/js/**/*',
'./public/vid/**/*',
'./config/**/*',
'./controllers/**/*',
'./helpers/**/*',
'./middlewares/**/*',
'./models/**/*',
'./routes/**/*',
'./views/**/*',
'./app.js',
'./package.json'
], bsReload);
});