-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
99 lines (88 loc) · 2.41 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
const { watch, src, dest, series, parallel } = require('gulp');
const browserSync = require('browser-sync').create();
const babel = require('gulp-babel');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const del = require('./node_modules/del');
const postcss = require('gulp-postcss');
const sass = require('gulp-sass');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const config = {
app: {
js: [
'./src/js/**/*.js',
],
scss: './src/scss/**/*.scss',
fonts: './src/fonts/*',
images: './src/images/*.*',
html: './src/*.html'
},
dist: {
base: './dist/',
fonts: './dist/fonts',
images: './dist/images'
},
extraBundles: [
'./dist/main.js',
'./dist/main.css'
]
}
function jsTask(done) {
src(config.app.js)
.pipe(babel({
presets: ['@babel/preset-env']
}))
.pipe(concat('main.bundle.js'))
.pipe(uglify())
.pipe(dest(config.dist.base))
done();
}
function cssTask(done) {
src(config.app.scss)
.pipe(sass({ outputStyle: 'expanded' }))
.pipe(rename({ suffix: '.bundle' }))
.pipe(postcss([autoprefixer(), cssnano()]))
.pipe(dest(config.dist.base))
done();
}
function fontTask(done) {
src(config.app.fonts)
.pipe(dest(config.dist.fonts))
done();
}
function imagesTask(done) {
src(config.app.images)
.pipe(dest(config.dist.images))
done();
}
function templateTask(done) {
src(config.app.html)
.pipe(dest(config.dist.base))
done();
}
function watchFiles() {
watch(config.app.js, series(jsTask, reload));
watch(config.app.scss, series(cssTask, reload));
watch(config.app.fonts, series(fontTask, reload));
watch(config.app.images, series(imagesTask, reload));
watch(config.app.html, series(templateTask, reload));
}
function liveReload(done) {
browserSync.init({
server: {
baseDir: config.dist.base
},
});
done();
}
function reload (done) {
browserSync.reload();
done();
}
function cleanUp() {
return del([config.dist.base]);
}
exports.dev = parallel(jsTask, cssTask, fontTask, imagesTask, templateTask, watchFiles, liveReload);
exports.build = series(cleanUp, parallel(jsTask, cssTask, fontTask, imagesTask, templateTask));