-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
80 lines (65 loc) · 1.92 KB
/
Copy pathgulpfile.js
File metadata and controls
80 lines (65 loc) · 1.92 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
var gulp = require('gulp');
var sass = require('gulp-sass');
var slm = require('gulp-slm');
var notify = require("gulp-notify");
var browserSync = require('browser-sync').create();
gulp.task('default', [
'browser-sync',
'html-watch-reload',
'js-watch-reload',
'sass-watch',
'sass-compile-reload',
'slm-watch',
'slm-to-html'
]);
//gulp.task('build', function() {
// console.log(new Date(), 'Build project...');
//});
gulp.task('browser-sync', function() {
browserSync.init({
startPath: "/index.html",
server: {
baseDir: "./",
}
});
});
gulp.task('html-watch-reload', function() {
gulp.watch('./*.html').on('change', function() {
console.log(new Date(), 'HTML was changed');
browserSync.reload();
});
});
gulp.task('js-watch-reload', function() {
gulp.watch('./scripts/*.js').on('change', function() {
console.log(new Date(), 'JS was changed');
browserSync.reload();
});
});
gulp.task('sass-watch', function () {
gulp.watch('./styles/styles.sass', ['sass-compile-reload']);
});
gulp.task('sass-compile-reload', function () {
console.log(new Date(), 'Recompile styles...')
gulp.src('./styles/styles.sass')
.pipe(sass({outputStyle: 'compressed'}).on('error', notify.onError(function (error) {
return error.message;
})))
.pipe(gulp.dest('./styles/'))
.pipe(browserSync.stream());
});
gulp.task('slm-watch', function() {
gulp.watch('./markup/**/*.slm', ['slm-to-html']);
});
gulp.task('slm-to-html', function() {
console.log(new Date, 'Recompile slm template...');
return gulp.src('./markup/*.slm')
.pipe(slm({useCache: false}).on('error', notify.onError(function (error) {
var message = 'Slm template error\n' + error.message;
if (error.message.indexOf('Line') == -1 && error.message.indexOf('Column') == -1) {
var errorPosition = error.stack.match(/:(\d+):(\d+)/);
message += `\nAt line ${errorPosition[1]}, column ${errorPosition[2]}`;
}
return message;
})))
.pipe(gulp.dest('./'));
});