-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
126 lines (103 loc) · 2.71 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
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
// Include the required tools used on tasks
var gulp = require('gulp'),
jshint = require('gulp-jshint'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify'),
saveLicense = require('uglify-save-license'),
babel = require("gulp-babel"),
postcss = require('gulp-postcss'),
cleanCSS = require('gulp-clean-css'),
cssbeautify = require('gulp-cssbeautify'),
autoprefixer = require('autoprefixer'),
del = require('del');
var Server = require('karma').Server;
var browserSync = require('browser-sync').create();
// Specify the Source files
var SRC_JS = 'src/js/*.js';
var SRC_CSS = 'src/css/*.css';
// Specify the Destination folders
var DEST_JS = 'dist/js';
var DEST_CSS = 'dist/css';
// Example pages
var EXAMPLE_HTML = 'examples/*.html';
// BUILD JS
function build_js(cb) {
gulp.src(SRC_JS)
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(gulp.dest(DEST_JS))
.pipe(uglify({
output: {
comments: saveLicense
}
}))
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(DEST_JS));
cb();
}
// BUILD CSS
function build_css(cb) {
gulp.src(SRC_CSS)
.pipe(postcss( [autoprefixer()] ))
.pipe(cssbeautify({ autosemicolon: true }))
.pipe(gulp.dest(DEST_CSS))
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(DEST_CSS));
cb();
}
// LINT
function lint_js(cb) {
gulp.src(SRC_JS)
.pipe(jshint({ "esversion": 8 }))
.pipe(jshint.reporter('default'));
cb();
}
// CLEAN
function clean_js(cb) {
del.sync([DEST_JS]);
cb();
}
function clean_css(cb) {
del.sync([DEST_CSS]);
cb();
}
// WATCH
function watch(cb) {
gulp.watch(SRC_JS, build_js);
gulp.watch(SRC_CSS, build_css);
cb();
}
// SERVE
function serve(cb) {
// Serve files from the root of this project
browserSync.init({
server: {
baseDir: ["examples", "dist"],
index: "index.html"
}
});
gulp.watch(SRC_JS, build_js);
gulp.watch(SRC_CSS, build_css);
gulp.watch([DEST_JS, DEST_CSS, EXAMPLE_HTML]).on("change", browserSync.reload);
cb();
}
// TEST
function test(cb) {
new Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done).start();
cb();
}
// EXPORT methods
exports.clean = gulp.parallel(clean_js, clean_css);
exports.build = gulp.parallel(gulp.series(clean_js, lint_js, build_js), gulp.series(clean_css, build_css));
exports.lint = lint_js;
exports.watch = watch;
exports.test = test;
exports.serve = serve;
exports.default = serve;