forked from Tomotoes/HomePage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
73 lines (64 loc) · 1.96 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
const gulp = require('gulp')
const minifycss = require('gulp-clean-css')
const uglify = require('gulp-uglify')
const htmlmin = require('gulp-htmlmin')
const cssnano = require('gulp-cssnano')
const htmlclean = require('gulp-htmlclean')
const del = require('del')
const babel = require('gulp-babel')
const autoprefixer = require('gulp-autoprefixer')
const connect = require('gulp-connect')
const pug = require('gulp-pug')
const sass = require('gulp-sass')
sass.compiler = require('node-sass')
const config = require('./config.json')
gulp.task('clean', function () {
return del(['./dist/css/', './dist/js/'])
})
gulp.task('css', function () {
return gulp
.src('./src/css/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(minifycss({ compatibility: 'ie8' }))
.pipe(autoprefixer({ browsers: ['last 2 version'] }))
.pipe(cssnano({ reduceIdents: false }))
.pipe(gulp.dest('./dist/css'))
})
gulp.task('html', function () {
return gulp
.src('./dist/index.html')
.pipe(htmlclean())
.pipe(htmlmin())
.pipe(gulp.dest('./dist'))
})
gulp.task('js', function () {
return gulp
.src('./src/js/*.js')
.pipe(babel({ presets: ['@babel/preset-env'] }))
.pipe(uglify())
.pipe(gulp.dest('./dist/js'))
})
gulp.task('pug', function () {
return gulp
.src('./src/index.pug')
.pipe(pug({ data: config }))
.pipe(gulp.dest('./dist'))
})
gulp.task('assets', function () {
return gulp
.src(['./src/assets/**/*'])
.pipe(gulp.dest('./dist/assets'));
})
gulp.task('build', gulp.series('clean', 'assets', 'pug', 'css', 'js', 'html'))
gulp.task('default', gulp.series('build'))
gulp.task('watch', function () {
gulp.watch('./src/components/*.pug', gulp.parallel('pug'))
gulp.watch('./src/index.pug', gulp.parallel('pug'))
gulp.watch('./src/css/**/*.scss', gulp.parallel(['css']))
gulp.watch('./src/js/*.js', gulp.parallel(['js']))
connect.server({
root: 'dist',
livereload: true,
port: 8080
})
})