-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
96 lines (81 loc) · 2.82 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
//установка нового: заходим в директорию и npm install
//Сборка проекта: gulp production
//Запуск gulp'а: gulp watch
'use strict';
var gulp = require('gulp'),
stylus = require('gulp-stylus'),
browserSync = require('browser-sync'),
concat = require('gulp-concat'),
uglify = require('gulp-uglifyjs'),
cssnano = require('gulp-cssnano'),
rename = require('gulp-rename'),
imagemin = require('gulp-imagemin'),
pngquant = require('imagemin-pngquant'),
cache = require('gulp-cache'),
autoprefixer = require('gulp-autoprefixer');
//Browser sync
gulp.task('browser-sync', function(){
browserSync({
server: {
baseDir: 'production'
},
notify: false
});
});
//Assembly of pictures
gulp.task('compress', function() {
gulp.src('src/img/*')
.pipe(imagemin())
.pipe(gulp.dest('production/img/'))
});
//compile and assembly stylus
gulp.task('compile_stylus', function() {
gulp.src('src/css/main.styl')
.pipe( stylus() )
.pipe(autoprefixer(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { //Добавление префиксов
cascade: true
}))
.pipe(cssnano())
.pipe( gulp.dest('production/css/') );
});
//compile and assembly twig
gulp.task('compile_twig', function () {
var twig = require('gulp-twig');
return gulp.src('src/html/index.twig')
.pipe(twig({
data: {
title: 'Gulp and Twig',
benefits: [
'Fast',
'Flexible',
'Secure'
]
}
}))
.pipe(gulp.dest('production/'));
});
//Assembly js lib file
gulp.task('compile_lib_js', function () {
gulp.src('src/js/lib/*')
.pipe( gulp.dest('production/js/') );
});
//Assembly my js file
gulp.task('compile_js', function () {
gulp.src('src/js/**/*.js')
.pipe(concat('main.js'))
.pipe( gulp.dest('production/js/') )
});
//function watch
var watch = ['browser-sync', 'compile_stylus', 'compile_twig','compile_lib_js', 'compile_js', 'compress'];
//Main function watch change file
gulp.task('watch', watch, function() {
gulp.watch('src/css/**/*.styl', ['compile_stylus'], browserSync.reload);
gulp.watch('src/html/**/*.twig', ['compile_twig'], browserSync.reload);
gulp.watch('src/js/**/*.js', ['compile_js'], browserSync.reload);
gulp.watch('src/js/lib/*', ['compile_lib_js'], browserSync.reload);
gulp.watch('src/img/*', ['compress'], browserSync.reload);
});
//Assembly project
var complete = ['compile_stylus', 'compile_twig', 'compile_js','compile_lib_js', 'compress' ];
gulp.task('production', complete, function () {
});