-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
89 lines (72 loc) · 2.35 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
const gulp = require('gulp');
const gulpsync = require('gulp-sync')(gulp);
const gulpif = require('gulp-if');
const minCss = require('gulp-cssmin');
const minJs = require('gulp-uglifyjs');
const minHtml = require('gulp-htmlmin');
const minImages = require('gulp-imagemin');
const browserSync = require('browser-sync').create();
const fs = require('fs');
const path = require('path');
const env = process.env;
const IS_PROD = env.NODE_ENV === 'prod' || env.NODE_ENV === 'production';
gulp.task('css', () => {
gulp.src('./src/css/*.css')
.pipe(gulpif(IS_PROD, minCss()))
.pipe(gulp.dest('./dist/css'));
});
gulp.task('js', () => {
gulp.src(['./src/js/*.js', '!./src/js/*.min.js'])
.pipe(gulpif(IS_PROD, minJs()))
.pipe(gulp.dest('./dist/js'));
gulp.src(['./src/js/*.min.js'])
.pipe(gulp.dest('./dist/js'));
});
gulp.task('html', () => {
gulp.src('./src/*.html')
.pipe(gulpif(IS_PROD, minHtml({
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true
})))
.pipe(gulp.dest('./dist'));
});
gulp.task('images', () => {
gulp.src('./src/images/**/*.*')
.pipe(gulpif(IS_PROD, minImages()))
.pipe(gulp.dest('./dist/images'));
});
gulp.task('fonts', () => {
gulp.src('./src/fonts/**/*.*')
.pipe(gulp.dest('./dist/fonts'))
});
gulp.task('php', () => {
gulp.src('./src/bat/**/*.*')
.pipe(gulp.dest('./dist/bat'))
});
gulp.task('copy', () => {
gulp.src('./src/robots.txt')
.pipe(gulp.dest('./dist'))
});
gulp.task('server', () => {
browserSync.init({
server: {
baseDir: "./dist",
index: "index.html",
},
browser: "google chrome"
});
});
gulp.task('reload', () => {
browserSync.reload();
});
gulp.task('watch', () => {
gulp.watch('./src/bat/*.*', gulpsync.sync(['php', 'reload']));
gulp.watch('./src/css/*.css', gulpsync.sync(['css', 'reload']));
gulp.watch('./src/js/*.js', gulpsync.sync(['js', 'reload']));
gulp.watch('./src/*.html', gulpsync.sync(['html', 'reload']));
gulp.watch('./src/images/**/*.*', gulpsync.sync(['images', 'reload']));
gulp.watch('./src/fonts/**/*.*', gulpsync.sync(['fonts', 'reload']));
});
gulp.task('build', ['css', 'js', 'html', 'php', 'copy', 'images', 'fonts']);
gulp.task('dev', gulpsync.sync(['build', 'server', 'watch']));