forked from wp-statistics/wp-statistics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
110 lines (98 loc) · 3.47 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
var gulp = require('gulp'),
cleanCSS = require('gulp-clean-css'),
rename = require('gulp-rename'),
concat = require('gulp-concat'),
insert = require('gulp-insert'),
babel = require('gulp-babel'),
uglify = require('gulp-uglify'),
replace = require('gulp-replace'),
pipeline = require('readable-stream').pipeline;
const sass = require('gulp-sass')(require('sass'));
// Now you can use gulpSass in your gulp tasks
function buildStyles(done) {
return gulp.src([
'./assets/dev/sass/admin.scss',
'./assets/dev/sass/jquery-datepicker/datepicker.scss',
'./assets/dev/sass/rtl.scss',
'./assets/dev/sass/frontend.scss',
])
.pipe(sass({outputStyle: 'compressed'}))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('./assets/css/'));
};
function buildScripts(done) {
gulp.src([
'./assets/dev/javascript/plugin/*.js',
'./assets/dev/javascript/config.js',
'./assets/dev/javascript/ajax.js',
'./assets/dev/javascript/placeholder.js',
'./assets/dev/javascript/helper.js',
'./assets/dev/javascript/meta-box.js',
'./assets/dev/javascript/meta-box/*.js',
'./assets/dev/javascript/pages/*.js',
'./assets/dev/javascript/run.js',
])
.pipe(concat('admin.min.js'))
.pipe(insert.prepend('jQuery(document).ready(function ($) {'))
.pipe(insert.append('});'))
.pipe(gulp.dest('./assets/js/'))
.pipe(babel({presets: ['@babel/env']}))
.pipe(replace("\\n", ''))
.pipe(replace("\\t", ''))
.pipe(replace(" ", ''))
.pipe(uglify())
.pipe(gulp.dest('./assets/js/'));
done()
}
// Gulp TinyMce Script
function tineMCE(done) {
gulp.src(['./assets/dev/javascript/Tinymce/*.js'])
.pipe(concat('tinymce.min.js'))
.pipe(gulp.dest('./assets/js/')).pipe(babel({presets: ['@babel/env']})).pipe(replace("\\n", '')).pipe(replace("\\t", '')).pipe(replace(" ", '')).pipe(uglify()).pipe(gulp.dest('./assets/js/'));
done()
}
// Gulp Frontend Script
function frontScripts(done) {
gulp.src(['./assets/dev/javascript/tracker.js'])
.pipe(gulp.dest('./assets/js/')).pipe(babel({presets: ['@babel/env']})).pipe(replace("\\n", '')).pipe(replace("\\t", '')).pipe(replace(" ", '')).pipe(uglify()).pipe(gulp.dest('./assets/js/'));
done()
}
// Gulp Script Minify
function concatScripts(done) {
gulp.src(['./assets/js/*.js', '!./assets/js/*.min.js'])
.pipe(babel({presets: ['@babel/env']}))
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(function (file) {
return file.base;
}));
done()
}
// Gulp Css Minify
function minifyCss(done) {
gulp.src(['./assets/css/*.css', '!./assets/css/*.min.css'])
.pipe(cleanCSS({
keepSpecialComments: 1,
level: 2
}))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(function (file) {
return file.base;
}));
done()
}
// Gulp Watch
function watch() {
gulp.watch('assets/dev/javascript/**/*.js', gulp.series(buildScripts));
gulp.watch('assets/dev/sass/**/*.scss', gulp.series(buildStyles));
console.log(" - Development is ready...")
}
// global Task
exports.compileSass = buildStyles;
exports.script = buildScripts;
exports.mce = tineMCE;
exports.frontScript = frontScripts;
exports.concatScripts = concatScripts;
exports.minifyCss = minifyCss;
exports.watch = watch;
exports.default = gulp.series(watch);