-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgulpfile.js
146 lines (134 loc) · 4.46 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
140
141
142
143
144
145
146
'use strict';
var gulp = require('gulp'),
sourcemaps = require('gulp-sourcemaps'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
cssmin = require('gulp-cssmin'),
concat = require('gulp-concat'),
babel = require('gulp-babel');
// CSS COMPRESS
gulp.task('compress-css', function () {
return gulp.src('css/src/*.css')
.pipe(cssmin())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('css'));
});
// JS COMPRESS
function compress_all_js() {
return gulp.src([
'js/src/*.js',
'!js/src/apbct-public--*.js',
'!js/src/apbct-public-bundle.js',
'!js/src/cleantalk-admin.js',
'!js/src/apbct-common-functions.js',
'js/src/apbct-public--3--cleantalk-modal.js',
'js/src/apbct-public--7--trp.js',
])
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('js'));
}
function bundle_admin_and_common_js() {
return gulp.src([
'js/src/cleantalk-admin.js',
'js/src/apbct-common-functions.js'
])
.pipe(sourcemaps.init())
.pipe(concat('cleantalk-admin.js'))
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('js'));
}
/**
* Bundle Create
*/
// Bundle without external and internal js
function bundle_src_js() {
return gulp.src([
'js/src/apbct-public--0*.js',
'js/src/apbct-public--1*.js',
'js/src/apbct-public--2*.js',
'js/src/apbct-public--3*.js',
'js/src/apbct-public--7*.js',
'js/src/apbct-common-functions.js',
])
// Unminified bundle
.pipe(concat('apbct-public-bundle.js'))
.pipe(gulp.dest('js/src/'));
}
// Bundle with external js and without internal js
function bundle_src_js_external_protection() {
return gulp.src([
'js/src/apbct-public--0*.js',
'js/src/apbct-public--1*.js',
'js/src/apbct-public--2*.js',
'js/src/apbct-public--3*.js',
'js/src/apbct-public--7*.js',
'js/src/apbct-public--5--external-forms.js',
'js/src/apbct-common-functions.js',
])
// Unminified bundle
.pipe(concat('apbct-public-bundle_ext-protection.js'))
.pipe(gulp.dest('js/src/'));
}
// Bundle with internal js and without external js
function bundle_src_js_internal_protection() {
return gulp.src([
'js/src/apbct-common-functions.js',
'js/src/apbct-public--0*.js',
'js/src/apbct-public--1*.js',
'js/src/apbct-public--2*.js',
'js/src/apbct-public--3*.js',
'js/src/apbct-public--7*.js',
'js/src/apbct-public--6--internal-forms.js',
'js/src/apbct-common-functions.js',
])
// Unminified bundle
.pipe(concat('apbct-public-bundle_int-protection.js'))
.pipe(gulp.dest('js/src/'));
}
// Bundle with external and internal js
function bundle_src_js_ext_int_protection() {
return gulp.src([
'js/src/apbct-common-functions.js',
'js/src/apbct-public--0*.js',
'js/src/apbct-public--1*.js',
'js/src/apbct-public--2*.js',
'js/src/apbct-public--3*.js',
'js/src/apbct-public--7*.js',
'js/src/apbct-public--5--external-forms.js',
'js/src/apbct-public--6--internal-forms.js',
'js/src/apbct-common-functions.js',
])
// Unminified bundle
.pipe(concat('apbct-public-bundle_full-protection.js'))
.pipe(gulp.dest('js/src/'));
}
function bundle_js() {
return gulp.src('js/src/apbct-public-bundle*.js')
.pipe(babel({
presets: [["@babel/preset-env", { targets: { ie: "11" } }]],
plugins: ["@babel/plugin-transform-class-properties"]
}))
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('js'));
}
gulp.task('compress-js', gulp.series(
bundle_src_js,
bundle_src_js_external_protection,
bundle_src_js_internal_protection,
bundle_src_js_ext_int_protection,
bundle_js,
compress_all_js,
bundle_admin_and_common_js
));
gulp.task('compress-css:watch', function () {
gulp.watch('./css/src/*.css', gulp.parallel('compress-css'));
});
gulp.task('compress-js:watch', function () {
gulp.watch('./js/src/*.js', gulp.parallel('compress-js'));
});