-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
74 lines (64 loc) · 1.97 KB
/
gulpfile.js
File metadata and controls
74 lines (64 loc) · 1.97 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
const del = require('del');
const gulp = require('gulp');
const rename = require('gulp-rename');
const runSequence = require('run-sequence');
const sass = require('gulp-sass');
const nunj = require('gulp-nunjucks-render')
const gwatch = require('gulp-watch')
const plumber = require('gulp-plumber')
const browserSync = require('browser-sync').create();
gulp.task('clean', function () {
return del('./build/**/*');
});
/* Compile SCSS to CSS */
gulp.task('scss', function () {
return gulp.src('./src/styles/main.scss')
/* Функція sass() компілює SCSS в CSS */
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./build/css'))
.pipe(browserSync.stream());
});
gulp.task('js', function () {
return gulp.src('./src/js/**/*.js')
.pipe(gulp.dest('./build/js'));
});
gulp.task('assets', function () {
return gulp
.src('./src/assets/**/*')
.pipe(gulp.dest('./build/assets'));
});
gulp.task('nunj', function () {
return gulp
.src('./src/templates/pages/**/*.nunj')
.pipe(plumber({ onError: console.log }))
.pipe(nunj({
path: ['src/templates']
}))
.pipe(rename((file) => file.extname = '.html'))
.pipe(gulp.dest('./build'))
})
/* Build the project */
gulp.task('build', ['clean'], function () {
return runSequence(['js', 'scss', 'nunj', 'assets']);
});
gulp.task('serve', function () {
browserSync.init({
server: {
baseDir: ['./build/']
},
files: ['./build/**/*'],
open: true
});
});
gulp.task('reload', function (done) {
browserSync.reload()
done()
});
const watch = (pattern, tasks) => gwatch(pattern, () => runSequence(...tasks))
/* Default task */
gulp.task('default', ['build', 'serve'], function () {
watch('./src/styles/**/*.scss', ['scss']);
watch('./src/js/**/*.js', ['js']);
watch('./src/assets/**/*', ['assets']);
watch('./src/templates/**/*.nunj', ['nunj']);
});