-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
87 lines (75 loc) · 1.96 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
/*--- Gulp 4 ----------*/
const { src, dest , watch, series, parallel } = require('gulp');
const babel = require("gulp-babel");
const sourcemaps = require("gulp-sourcemaps");
const sass = require('gulp-sass')(require('sass'));
const concat = require("gulp-concat");
const uglify = require("gulp-uglify");
const postcss = require("gulp-postcss");
const autoprefixer = require("autoprefixer");
const cssnano = require("cssnano");
const notify = require("gulp-notify");
const browserSync = require("browser-sync").create();
const reload = browserSync.reload;
// files
const files = {
cssPath: "src/**/*.scss",
jsPath: "src/**/*.js",
};
// CSS
function styles() {
return src(files.cssPath)
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(postcss([autoprefixer, cssnano]))
.pipe(sourcemaps.write("."))
.pipe(dest("dist"))
.pipe(notify("Done!"));
}
// JS
function scripts() {
return src([files.jsPath])
.pipe(
babel({
presets: ["@babel/preset-env"],
})
)
.pipe(concat("app.js"))
.pipe(uglify())
.pipe(dest("dist"))
.pipe(notify("Done!"));
}
// Images
function images() {
return src('img/*.{jpg,gif,png}')
.pipe(dest('dist/img/'));
}
// BrowserSync & Watch
function tasks() {
watch(
[files.cssPath, files.jsPath],
series(parallel(styles, scripts, images))
).on("change", reload);
browserSync.init({
server: {
baseDir: './'
},
notify: false,
// proxy: "yourlocal.dev"
// open: false,
// online: false, // Work Offline Without Internet Connection
// tunnel: true, tunnel: "projectname", // Demonstration page: http://projectname.localtunnel.me
})
}
// Exports
exports.default = series(
parallel(
styles,
scripts,
images
),
tasks
);
exports.styles = styles;
exports.scripts = scripts;
exports.images = images;