-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
128 lines (100 loc) · 2.92 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
const gulp = require('gulp'),
browserSync = require('browser-sync'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
sourcemap = require('gulp-sourcemaps'),
babel = require('gulp-babel'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify');
const paths = {
srcIndex:'./src/index.html',
srcStyles:'./src/sass/**/*.scss',
srcScript: './src/js/**/*.js',
srcImages:'./src/img/**/*.+(png|jpg|jpg|jpeg|gif|svg)',
buildRoot: './docs',
buildStyle: './docs/css',
buildScript: './docs/js',
buildImages: './docs/img',
prodRoot: './prod',
prodStyle: './docs/css',
prodMaps: './maps',
prodScript: './prod/js',
prodImages: './prod/img'
};
//Production
gulp.task('htmlProd', htmlProd);
function htmlProd (){
return gulp.src(paths.srcIndex)
.pipe(gulp.dest(paths.prodRoot))
.pipe(browserSync.stream());
}
gulp.task('sassProd', sassProd);
function sassProd(){
return gulp.src(paths.srcStyles)
.pipe(sourcemap.init())
.pipe(sass().on('error', sass.logError))
.pipe(sourcemap.write(paths.prodMaps))
.pipe(gulp.dest(paths.prodStyle))
.pipe(browserSync.stream());
}
gulp.task('jsProd', jsProd);
function jsProd(){
return gulp.src(paths.srcScript)
.pipe(sourcemap.init())
.pipe(babel())
.pipe(sourcemap.write('maps'))
.pipe(gulp.dest(paths.prodScript))
.pipe(browserSync.stream());
}
gulp.task('imagesProd', imagesProd);
function imagesProd(){
return gulp.src(paths.srcImages)
.pipe(gulp.dest(paths.prodImages))
.pipe(browserSync.stream());
}
gulp.task('prod', gulp.parallel('htmlProd', 'sassProd', 'jsProd', 'imagesProd'));
gulp.task('serve', () => {
browserSync.init({
server:{
baseDir:"docs"
}
});
gulp.watch(paths.srcIndex, htmlProd );
gulp.watch(paths.srcStyles, sassProd);
gulp.watch(paths.srcScript, jsProd);
gulp.watch(paths.srcImages, imagesProd );
});
//build
gulp.task('htmlBuild', htmlBuild);
function htmlBuild (){
return gulp.src(paths.srcIndex)
.pipe(gulp.dest(paths.buildRoot));
}
gulp.task('sassBuild', sassBuild);
function sassBuild (){
return gulp.src(paths.srcStyles)
.pipe(sass({
errLogToConsole: true,
outputStyle:'compressed'
})
.on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 2 versions', 'Firefox ESR', '> 0.5%', 'not dead']
}))
.pipe(gulp.dest(paths.buildStyle));
}
gulp.task('jsBuild', jsBuild);
function jsBuild() {
return gulp.src(paths.srcScript)
.pipe(babel())
.pipe(concat("app.js"))
.pipe(uglify())
.pipe(gulp.dest(paths.buildScript));
}
gulp.task('imagesBuild', imagesBuild);
function imagesBuild(){
return gulp.src(paths.srcImages)
.pipe(gulp.dest(paths.buildImages))
.pipe(browserSync.stream());
}
gulp.task('build', gulp.parallel('htmlBuild', 'sassBuild', 'jsBuild', 'imagesBuild'));