-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
150 lines (132 loc) · 3.61 KB
/
gulpfile.babel.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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 dartSass from "sass";
import gulpSass from "gulp-sass";
import sourcemaps from "gulp-sourcemaps";
import source from "vinyl-source-stream";
import uglify from "gulp-uglify";
import {gulpConfig} from "./config";
/**
* Set default Sass compiler
*/
const sass = gulpSass(dartSass);
/**
* browserSync create
*/
const server = browserSync.create();
/**
* Clean dist task
*/
export const clean = () => del(gulpConfig.paths.cleanPatterns.patterns);
/**
* Watch SCSS task
*/
export function watchStyles() {
return gulp.src(gulpConfig.paths.styles.src)
.pipe(sourcemaps.init())
.pipe(sass({includePaths: gulpConfig.paths.includes.node_modules}))
.pipe(sass().on("error", sass.logError))
.pipe(autoprefixer())
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest(gulpConfig.paths.styles.dest))
.pipe(server.stream());
}
/**
* Build SCSS task
*/
export function buildStyles() {
return gulp.src(gulpConfig.paths.styles.src)
.pipe(sass({includePaths: gulpConfig.paths.includes.node_modules}))
.pipe(sass().on("error", sass.logError))
.pipe(autoprefixer())
.pipe(cleanCSS({level: {1: {specialComments: 0}}}))
.pipe(gulp.dest(gulpConfig.paths.styles.dest));
}
/**
* Watch JS task
*/
export function watchScripts() {
return browserify(gulpConfig.paths.scripts.main)
.transform("babelify", {
global: true,
presets: ["@babel/preset-env"],
plugins: [
"@babel/plugin-syntax-dynamic-import",
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread"],
})
.bundle()
.pipe(source("bundle.js"))
.pipe(buffer())
.pipe(sourcemaps.init({"loadMaps": true}))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(gulpConfig.paths.scripts.dest))
.pipe(server.stream());
}
/**
* Build JS task
*/
export function buildScripts() {
return browserify(gulpConfig.paths.scripts.main)
.transform("babelify", {
global: true,
presets: ["@babel/preset-env"],
plugins: [
"@babel/plugin-syntax-dynamic-import",
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread"],
})
.bundle()
.pipe(source("bundle.js"))
.pipe(buffer())
.pipe(uglify({
compress: {
pure_funcs: ["console.log"],
},
}))
.pipe(gulp.dest(gulpConfig.paths.scripts.dest));
}
/**
* Reload task
*/
export function reload(done) {
server.reload();
done();
}
/**
* Server init task
*/
export function serve(done) {
server.init({
proxy: gulpConfig.proxy,
port: gulpConfig.port,
host: gulpConfig.host,
});
done();
}
/**
* File watcher
*/
export function watchFiles() {
gulp.watch(gulpConfig.paths.styles.src, gulp.series(watchStyles));
gulp.watch(gulpConfig.paths.scripts.src, gulp.series(watchScripts, reload));
gulp.watch(gulpConfig.paths.markup.src, reload);
}
/**
* Watch task
*/
const watch = gulp.series(clean, gulp.parallel(watchStyles, watchScripts), serve, watchFiles);
/**
* Build task
*/
export const build = gulp.series(clean, gulp.parallel(buildStyles, buildScripts));
/**
* Default task
*/
export default watch;