-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
135 lines (120 loc) · 2.91 KB
/
gulpfile.babel.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
/*
* Gulp 4 boilerplate to use in any project
* this project is setup to use SASS(scss)
*/
import gulp from 'gulp';
import sass from 'gulp-sass';
import babel from 'gulp-babel';
import concat from 'gulp-concat';
import uglify from 'gulp-uglify';
import rename from 'gulp-rename';
import cleanCSS from 'gulp-clean-css';
import htmlmin from 'gulp-htmlmin';
import imagemin from 'gulp-imagemin';
import imageminMozjpeg from 'imagemin-mozjpeg';
import newer from 'gulp-newer';
import del from 'del';
import browserSync from 'browser-sync';
const server = browserSync.create();
const paths = {
styles: {
src: 'src/styles/**/*.scss',
dest: 'dist/styles/'
},
scripts: {
src: 'src/scripts/**/*.js',
dest: 'dist/scripts/'
},
pages: {
src: 'src/**/*.html',
dest: 'dist/'
},
imgs: {
src: 'src/img/*',
dest: 'dist/img/'
}
};
/*
* For small tasks you can export arrow functions
*/
export const clean = () => del([ 'dist' ]);
/*
* You can also declare named functions and export them as tasks
*/
export function styles() {
return gulp.src(paths.styles.src)
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(cleanCSS())
// pass in options to the stream
.pipe(rename({
basename: 'main',
suffix: '.min'
}))
.pipe(gulp.dest(paths.styles.dest))
.pipe(browserSync.stream());
}
export function scripts() {
return gulp.src(paths.scripts.src, { sourcemaps: true })
.pipe(babel())
.pipe(uglify())
.pipe(concat('main.min.js'))
.pipe(gulp.dest(paths.scripts.dest));
}
export function htmls(){
return gulp.src(paths.pages.src)
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest(paths.pages.dest))
}
export function minifyImgs() {
return gulp.src(paths.imgs.src)
.pipe(newer(paths.imgs.src))
.pipe(imagemin([
imageminMozjpeg({
quality: 60,
progressive: true
})
]))
.pipe(gulp.dest(paths.imgs.dest))
}
/*
* Set up reload
*/
export function reload(done) {
server.reload();
done();
};
/*
* Set up serve to init the page
*/
export function serve(done) {
server.init({
server: {
baseDir: './dist'
}
});
done();
};
/*
* You could even use `export as` to rename exported tasks
*/
function watchFiles() {
gulp.watch(paths.scripts.src, gulp.series(scripts, reload));
gulp.watch(paths.styles.src, gulp.series(styles, reload));
gulp.watch(paths.pages.src, gulp.series(htmls, reload));
}
export { watchFiles as watch };
/*
* You can still use `gulp.task` create the build task that can be called alone
* for example to set task names that would otherwise be invalid
*/
const build = gulp.series(clean, gulp.parallel(styles, scripts, minifyImgs, htmls));
gulp.task('build', build);
/*
*
* Here we set up the default process to fire up the server and watch
*/
const dev = gulp.series(clean, build, serve, watchFiles)
/*
* Export a default task
*/
export default dev;