-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
70 lines (58 loc) · 1.56 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
// Import all modules
const gulp = require("gulp");
const sass = require("gulp-sass")(require("sass"));
const postcss = require("gulp-postcss");
const autoprefixer = require("autoprefixer");
const cssnano = require("cssnano");
const babel = require("gulp-babel");
const terser = require("gulp-terser");
const browsersync = require("browser-sync").create();
// Vars for different paths
scssSrcPath = "app/scss/style.scss";
scssDstPath = "dist/css";
jsSrcPath = "app/js/script.js";
jsDstPath = "dist/js";
allScssFiles = "app/scss/**/*.scss";
allJsFiles = "app/**/*.js";
allHtmlFiles = "*.html";
// Sass Task
function scssTask() {
return gulp
.src(scssSrcPath, { sourcemaps: true })
.pipe(sass())
.pipe(postcss([autoprefixer(), cssnano()]))
.pipe(gulp.dest(scssDstPath, { sourcemaps: "." }));
}
// JS Task
function jsTask() {
return gulp
.src(jsSrcPath, { sourcemaps: true })
.pipe(babel({ presets: ["@babel/preset-env"] }))
.pipe(terser())
.pipe(gulp.dest(jsDstPath, { sourcemaps: "." }));
}
// Browser Sync
function browserSyncLoader(done) {
browsersync.init({
server: {
baseDir: ".",
},
});
done();
}
function browserSyncReload(done) {
browsersync.reload();
done();
}
// Watch Task
function watchTask() {
gulp.watch(allHtmlFiles, browserSyncReload);
gulp.watch(
[allScssFiles, allJsFiles],
gulp.series(scssTask, jsTask, browserSyncReload)
);
}
// Default Gulp Task
exports.default = gulp.series(scssTask, jsTask, browserSyncLoader, watchTask);
// Build Gulp Task
exports.build = gulp.series(scssTask, jsTask);