-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
79 lines (70 loc) · 2.02 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
import gulp from 'gulp';
import sass from 'gulp-dart-sass';
import autoprefixer from 'gulp-autoprefixer';
import browserSync from 'browser-sync';
import webpack from 'webpack-stream';
import webpackConfig from './webpack.config.js';
import htmlmin from 'gulp-htmlmin';
import imagemin from 'gulp-imagemin';
import changed from 'gulp-changed';
import fetch from 'node-fetch';
// Webpack task
gulp.task('webpack', () =>
gulp.src('src/js/*.js')
.pipe(webpack(webpackConfig))
.pipe(gulp.dest('dist/js'))
.pipe(browserSync.stream())
);
// Sass task
gulp.task('sass', () =>
gulp.src('src/scss/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer())
.pipe(gulp.dest('dist/css'))
.pipe(browserSync.stream())
);
// Html task
gulp.task('html', () =>
gulp.src('src/html/*.html')
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(gulp.dest('dist'))
.pipe(browserSync.stream())
);
// Images task
gulp.task('images', () =>
gulp.src('src/img/**/*.{jpg,jpeg,png,gif,svg}')
.pipe(changed('dist/img'))
.pipe(imagemin())
.pipe(gulp.dest('dist/img'))
.pipe(browserSync.stream())
);
// Watch task
gulp.task('watch', () => {
browserSync.init({
server: {
baseDir: './dist',
index: 'index.html',
middleware: [
function(req, res, next) {
if (/\.js$/.test(req.url)) {
res.setHeader('Content-Type', 'application/javascript');
} else if (/\.css$/.test(req.url)) {
res.setHeader('Content-Type', 'text/css');
}
next();
}
],
open: false
}
});
gulp.watch('src/scss/*.scss', gulp.series('sass'));
gulp.watch('src/js/*.js', gulp.series('webpack'));
gulp.watch('src/html/*.html', gulp.series('html'));
gulp.watch('.env', gulp.series('webpack'));
});
// Dev task
gulp.task('dev', gulp.series('sass', 'webpack', 'html', 'images', 'watch'));
// Build task
gulp.task('build', gulp.series('sass', 'webpack', 'html', 'images'));
// Default task
gulp.task('default', gulp.series('dev'));