-
Notifications
You must be signed in to change notification settings - Fork 42
/
gulpfile.js
139 lines (117 loc) · 3.16 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
127
128
129
130
131
132
133
134
135
136
137
138
139
var gulp = require('gulp');
var sass = require('gulp-sass')(require('sass'));
var cleanCSS = require('gulp-clean-css');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var header = require('gulp-header');
var fileHeader = '/*! svgMap | https://github.com/StephanWagner/svgMap | MIT License | Copyright Stephan Wagner | https://stephanwagner.me */' + "\n";
// CSS
var styles = [{
name: 'svgMap',
src: ['./src/scss/main.scss'],
srcWatch: ['./src/scss/**/*.scss'],
dest: './dist/'
}];
// JavaScript
var scripts = [{
name: 'svgMap',
src: [
'./src/js/svgMap.js',
'./src/js/umd.js'
],
dest: './dist/'
}];
// Config tasks
let defaultTasks = [];
let buildTasks = [];
let watchTasks = [];
// Config CSS tasks
for (const item of styles) {
// Concat CSS
const cssConcat = function () {
return gulp
.src(item.src)
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'expanded'
}).on('error', sass.logError))
.pipe(concat(item.name + '.css'))
.pipe(header(fileHeader))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(item.dest));
};
// Store as a task
gulp.task('cssConcat-' + item.name, cssConcat);
// Add to default tasks
defaultTasks.push('cssConcat-' + item.name);
// Add to watch tasks
watchTasks.push({
src: item.srcWatch ? item.srcWatch : item.src,
task: cssConcat
});
// Build CSS
const cssBuild = function () {
return gulp
.src(item.dest + item.name + '.css')
.pipe(rename(item.name + '.min.css'))
.pipe(cleanCSS({
level: {
1: {
specialComments: 0
}
}
}))
.pipe(header(fileHeader))
.pipe(gulp.dest(item.dest));
};
// Store as a task
gulp.task('cssBuild-' + item.name, cssBuild);
// Add to build tasks
buildTasks.push('cssBuild-' + item.name);
}
// Config JavaScript tasks
for (let item of scripts) {
// Concat JavaScript
const jsConcat = function () {
return gulp
.src(item.src)
.pipe(sourcemaps.init())
.pipe(concat(item.name + '.js'))
.pipe(header(fileHeader))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(item.dest));
};
// Store as a task
gulp.task('jsConcat-' + item.name, jsConcat);
// Add to default tasks
defaultTasks.push('jsConcat-' + item.name);
// Add to watch tasks
watchTasks.push({
src: item.srcWatch ? item.srcWatch : item.src,
task: jsConcat
});
// Build JavaScript
const jsBuild = function () {
return gulp
.src(item.dest + item.name + '.js')
.pipe(rename(item.name + '.min.js'))
.pipe(uglify())
.pipe(header(fileHeader))
.pipe(gulp.dest(item.dest));
};
// Store as a task
gulp.task('jsBuild-' + item.name, jsBuild);
// Add to build tasks
buildTasks.push('jsBuild-' + item.name);
}
// Watch tasks
function watch() {
for (const watchTask of watchTasks) {
gulp.watch(watchTask.src, watchTask.task);
}
}
exports.default = gulp.series(defaultTasks);
exports.watch = gulp.series(defaultTasks, watch);
exports.build = gulp.series(defaultTasks, buildTasks);