-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
105 lines (95 loc) · 2.19 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 postcss from 'gulp-postcss';
import precss from 'precss';
import autoprefixer from 'autoprefixer';
import cssnano from 'cssnano';
// import sourcemaps from 'gulp-sourcemaps';
import postcssImport from 'postcss-import';
import rename from 'gulp-rename';
import babel from 'gulp-babel';
import concat from 'gulp-concat';
import uglify from 'gulp-uglify';
import rigger from 'gulp-rigger';
import connect from 'gulp-connect';
import del from 'del';
const path = {
dist: {
html: 'dist/',
js: 'dist/js/',
css: 'dist/css/',
img: 'dist/img/',
fonts: 'dist/fonts/',
},
src: {
html: [
'src/**/*.html',
'!src/template/**/*.*',
],
js: 'src/js/**/*.js',
style: 'src/scss/**/*.scss',
img: 'src/img/**/*.*',
fonts: 'src/fonts/**/*.*',
},
clean: './dist/*',
};
const configServer = {
name: 'Front-end server',
root: './dist',
host: 'localhost',
port: 9000,
livereload: true,
};
const serverStart = (cb) => {
connect.server(configServer);
cb();
};
const clean = () => (
del([path.clean])
);
const html = () => (
gulp.src(path.src.html)
.pipe(rigger())
.pipe(gulp.dest(path.dist.html))
.pipe(connect.reload())
);
const css = () => (
gulp.src(path.src.style)
// .pipe(sourcemaps.init())
.pipe(postcss([
postcssImport,
precss,
autoprefixer,
cssnano,
]))
.pipe(rename({ extname: '.css' }))
// .pipe(sourcemaps.write())
.pipe(gulp.dest(path.dist.css))
.pipe(connect.reload())
);
const js = () => (
gulp.src(path.src.js)
// .pipe(sourcemaps.init())
.pipe(babel({
presets: ['@babel/env'],
}))
.pipe(concat('main.js'))
.pipe(uglify())
// .pipe(sourcemaps.write())
.pipe(gulp.dest(path.dist.js))
.pipe(connect.reload())
);
const watchFiles = (cb) => {
gulp.watch(path.src.html, html);
gulp.watch(path.src.style, css);
gulp.watch(path.src.js, js);
cb();
};
const watch = gulp.parallel(watchFiles, serverStart);
const build = gulp.series(clean, gulp.parallel(html, css, js));
exports.start = serverStart;
exports.clean = clean;
exports.html = html;
exports.css = css;
exports.js = js;
exports.watch = watch;
exports.build = build;