-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.esm.js
119 lines (108 loc) · 2.38 KB
/
gulpfile.esm.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import autoprefixer from "gulp-autoprefixer";
import babelify from "babelify";
import browserify from "browserify";
import browserSync from "browser-sync";
import buffer from "vinyl-buffer";
import cleanCSS from "gulp-clean-css";
import del from "del";
import gulp from "gulp";
import rename from "gulp-rename";
import sass from "gulp-sass";
import sourcemaps from "gulp-sourcemaps";
import source from "vinyl-source-stream";
/**
* Paths object
*/
const paths = {
styles: {
main: "src/scss/style.scss",
src: "src/scss/**/*.scss",
dest: "dist/",
},
scripts: {
main: "src/js/LibName.js",
src: "src/js/**/*.js",
dest: "dist/",
},
markup: {
src: "**/*.html",
},
includes: {
node_modules: ["./node_modules"],
},
};
/**
* browserSync create
*/
const server = browserSync.create();
/**
* Clean dist task
*/
export const clean = () => del(["dist"]);
/**
* Watch SCSS task
*/
export function watchStyles() {
return gulp.src(paths.styles.src)
.pipe(sourcemaps.init())
.pipe(sass({includePaths: paths.includes.node_modules}))
.pipe(sass().on("error", sass.logError))
.pipe(autoprefixer())
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest(paths.styles.dest))
.pipe(server.stream());
}
/**
* Build SCSS task
*/
export function buildStyles() {
return gulp.src(paths.styles.src)
.pipe(sass({includePaths: paths.includes.node_modules}))
.pipe(sass().on("error", sass.logError))
.pipe(autoprefixer())
.pipe(cleanCSS({level: {1: {specialComments: 0}}}))
.pipe(rename({
basename: "style",
}))
.pipe(gulp.dest(paths.styles.dest));
}
/**
* Reload task
*/
export function reload(done) {
server.reload();
done();
}
/**
* Server init task
*/
export function serve(done) {
server.init({
server: {
baseDir: "./"
},
notify: false,
port: 8080,
injectChanges: true
});
done();
}
/**
* File watcher
*/
export function watchFiles() {
gulp.watch(paths.styles.src, gulp.series(watchStyles));
gulp.watch(paths.markup.src, reload);
}
/**
* Watch task
*/
const watch = gulp.series(clean, watchStyles, serve, watchFiles);
/**
* Build task
*/
export const build = gulp.series(clean, buildStyles);
/**
* Default task
*/
export default watch;