Skip to content

Commit 45f351b

Browse files
authored
Create gulpfile.js
1 parent 78a53ca commit 45f351b

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

src/gulpfile.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Load Gulp and required plugins
2+
const { src, dest, watch, series, parallel } = require('gulp');
3+
const sass = require('gulp-sass')(require('sass'));
4+
const concat = require('gulp-concat');
5+
const uglify = require('gulp-uglify');
6+
const cleanCSS = require('gulp-clean-css');
7+
const browserSync = require('browser-sync').create();
8+
9+
// Paths for files
10+
const paths = {
11+
html: './src/*.html',
12+
css: './src/*.css',
13+
js: './src/*.js',
14+
};
15+
16+
// Copy HTML to dist
17+
function copyHtml() {
18+
return src(paths.html)
19+
.pipe(dest(paths.dist))
20+
.pipe(browserSync.stream());
21+
}
22+
23+
// Minify CSS
24+
function minifyCss() {
25+
return src(paths.css)
26+
.pipe(concat('style.min.css'))
27+
.pipe(cleanCSS())
28+
.pipe(dest(`${paths.dist}/css`))
29+
.pipe(browserSync.stream());
30+
}
31+
32+
// Minify and bundle JS
33+
function minifyJs() {
34+
return src(paths.js)
35+
.pipe(concat('script.min.js'))
36+
.pipe(uglify())
37+
.pipe(dest(`${paths.dist}/js`))
38+
.pipe(browserSync.stream());
39+
}
40+
41+
// Live server
42+
function serve() {
43+
browserSync.init({
44+
server: {
45+
baseDir: paths.dist,
46+
},
47+
});
48+
49+
watch(paths.html, copyHtml);
50+
watch(paths.css, minifyCss);
51+
watch(paths.js, minifyJs);
52+
}
53+
54+
// Default task
55+
exports.default = series(
56+
parallel(copyHtml, minifyCss, minifyJs),
57+
serve
58+
);

0 commit comments

Comments
 (0)