-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
62 lines (54 loc) · 1.64 KB
/
Copy pathgulpfile.js
File metadata and controls
62 lines (54 loc) · 1.64 KB
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
const { src, dest, series, parallel, watch } = require('gulp');
const htmlmin = require('gulp-htmlmin');
const sass = require('gulp-sass');
const cleanCSS = require('gulp-clean-css');
const concat = require('gulp-concat');
const browserSync = require('browser-sync').create();
const srcPath = './src';
const destPath = './docs';
const scssPath = `${srcPath}/scss`;
const jsPath = `${srcPath}/js`;
const jsLibs = [
`${jsPath}/libs/jquery*.js`,
`${jsPath}/libs/handlebars*.js`
];
const jsScripts = [
`${jsPath}/details.js`,
`${jsPath}/logic.js`
];
function styles() {
return src(`${scssPath}/styles.scss`, { sourcemaps: true })
.pipe(sass({ outputStyle: 'expanded' }).on('error', sass.logError))
.pipe(cleanCSS())
.pipe(dest(destPath, { sourcemaps: true }));
}
function scripts() {
const outputFile = 'scripts.js';
return src([ ...jsLibs, ...jsScripts ], { sourcemaps: true })
.pipe(concat(outputFile))
.pipe(dest(destPath, { sourcemaps: true }));
}
function pages() {
return src(`${srcPath}/index.html`)
.pipe(htmlmin({
collapseWhitespace: true,
removeComments: true
}))
.pipe(dest(destPath));
}
function watchFiles() {
browserSync.init({
server: {
baseDir: destPath,
index: '/index.html'
}
});
watch(`${scssPath}/**/*.scss`, styles).on('change', browserSync.reload);
watch(`${jsPath}/**/*.js`, scripts).on('change', browserSync.reload);
watch(`${srcPath}/index.html`, pages).on('change', browserSync.reload);
}
exports.build = parallel(pages, styles, scripts);
exports.default = series(
parallel(pages, styles, scripts),
watchFiles
);