-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
105 lines (89 loc) · 2.29 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
import gulp from 'gulp'
import babel from 'gulp-babel'
import concat from 'gulp-concat'
import del from 'del'
import sass from 'gulp-sass'
import uglify from 'gulp-uglify'
import rename from 'gulp-rename'
import imageMin from 'gulp-imagemin'
const paths = {
scripts: {
src: 'src/js/*.js',
dest: 'dist/js/'
},
html: {
src: 'src/**/*.html',
dest: 'dist/',
},
scss: {
src: 'src/scss/*.scss',
dest: 'dist/css/',
},
images: {
src: 'src/img/**/*',
dest: 'dist/img/',
},
};
// Task to clean /dist/ folder
const clean = () => del(['dist']);
function scripts() {
return gulp.src(paths.scripts.src, { sourcemaps: true })
.pipe(babel())
.pipe(concat('scripts.js'))
.pipe(gulp.dest(paths.scripts.dest))
.pipe(uglify())
.pipe(rename('scripts.min.js'))
.pipe(gulp.dest(paths.scripts.dest))
}
function scss() {
return gulp.src(paths.scss.src, { sourcemaps: true })
.pipe(sass())
.pipe(gulp.dest(paths.scss.dest))
}
function html() {
return gulp.src(paths.html.src, { sourcemaps: true })
.pipe(gulp.dest(paths.html.dest))
}
function images() {
return gulp.src(paths.images.src)
.pipe(imageMin())
.pipe(gulp.dest(paths.images.dest))
}
function copyCNAME() {
return gulp.src('./src/CNAME')
.pipe(gulp.dest('./dist/'));
}
const compile = gulp.parallel(scripts, scss, html, images, copyCNAME);
// Setup the BrowserSync server
import browserSync from 'browser-sync';
const server = browserSync.create();
function reload(done) {
server.reload();
done();
}
function serve(done) {
server.init({
server: {
baseDir: './dist/',
},
});
done();
}
// Define watchers for each build component, and cumulative watcher
const watchScripts = () => gulp.watch(paths.scripts.src, gulp.series(scripts, reload))
const watchStyles = () => gulp.watch(paths.scss.src, gulp.series(scss, reload))
const watchHtml = () => gulp.watch(paths.html.src, gulp.series(html, reload))
const watchImages = () => gulp.watch(paths.images.src, gulp.series(images, reload));
const watch = gulp.parallel(watchScripts, watchStyles, watchHtml, watchImages);
// Default Task
const defaultTasks = gulp.series(clean, compile, serve, watch);
// Export named tasks
export {
clean,
scripts,
scss,
html,
copyCNAME,
compile,
}
export default defaultTasks