-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
135 lines (117 loc) · 3.55 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
130
131
132
133
134
135
let gulp = require('gulp'),
gutil = require('gulp-util'),
sass = require('gulp-sass'),
browserSync = require('browser-sync'),
concat = require('gulp-concat'),
sourcemaps = require('gulp-sourcemaps'),
uglify = require('gulp-uglify'),
cleanCSS = require('gulp-clean-css'),
rename = require('gulp-rename'),
del = require('del'),
imagemin = require('gulp-imagemin'),
cache = require('gulp-cache'),
autoprefixer = require('gulp-autoprefixer'),
bourbon = require('node-bourbon'),
ftp = require('vinyl-ftp'),
notify = require('gulp-notify'),
nunjucksRender = require('gulp-nunjucks-render'),
babel = require('gulp-babel'),
axios = require('axios');
// Скрипты проекта
gulp.task('scripts', () => {
return gulp.src([
'app/js/jsEs5.js',
])
.pipe(concat('scripts.min.js'))
.pipe(uglify())
.pipe(gulp.dest('app/js'))
.pipe(browserSync.reload({stream: true}));
});
gulp.task('babel', () => {
return gulp.src('app/js/main.js')
.pipe(babel({presets: ['env']}))
.pipe(concat('jsEs5.js'))
.pipe(gulp.dest('app/js'))
});
gulp.task('buildJs', ['babel'], () => {
gulp.start('scripts');
});
gulp.task('nunjucks', function () {
return gulp.src('app/pages/**/*.+(html|nunjucks)')
.pipe(nunjucksRender({
path: ['app/templates']
}))
.pipe(gulp.dest('app'))
});
gulp.task('browser-sync', () => {
browserSync({
server: {
baseDir: 'app'
},
https: true,
notify: false,
ghostMode: false
});
});
gulp.task('sass', () => {
return gulp.src('app/sass/**/*.sass')
.pipe(sourcemaps.init())
.pipe(sass({
includePaths: bourbon.includePaths
}).on("error", notify.onError()))
.pipe(rename({suffix: '.min', prefix: ''}))
.pipe(autoprefixer(['last 15 versions']))
.pipe(cleanCSS())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('app/css'))
.pipe(browserSync.reload({stream: true}));
});
gulp.task('watch', ['nunjucks', 'nunjucks', 'sass', 'buildJs', 'browser-sync'], () => {
gulp.watch('app/templates/**/*.+(html|nunjucks)', ['nunjucks']);
gulp.watch('app/pages/**/*.+(html|nunjucks)', ['nunjucks']);
gulp.watch('app/sass/**/*.sass', ['sass']);
gulp.watch('app/js/main.js', ['buildJs']);
gulp.watch('app/*.html', browserSync.reload);
});
gulp.task('imagemin', () => {
return gulp.src('app/img/**/*')
.pipe(cache(imagemin()))
.pipe(gulp.dest('dist/img'));
});
gulp.task('build', ['removedist', 'imagemin', 'sass', 'babel', 'scripts'], () => {
var buildFiles = gulp.src([
'app/*.html',
'app/.htaccess'
]).pipe(gulp.dest('dist'));
var buildCss = gulp.src([
'app/*.css'
]).pipe(gulp.dest('dist/css'));
var buildJs = gulp.src([
'app/js/scripts.min.js'
]).pipe(gulp.dest('dist/js'));
var buildFonts = gulp.src([
'app/fonts/**/*']
).pipe(gulp.dest('dist/fonts'));
});
gulp.task('deploy', () => {
var conn = ftp.create({
host: 'hostname.com',
user: 'username',
password: 'userpassword',
parallel: 10,
log: gutil.log
});
var globs = [
'dist/**',
'dist/.htaccess',
];
return gulp.src(globs, {buffer: false})
.pipe(conn.dest('/path/to/folder/on/server'));
});
gulp.task('removedist', () => {
return del.sync('dist')
});
gulp.task('clearcache', () => {
return cache.clearAll()
});
gulp.task('default', ['watch']);