This repository has been archived by the owner on Feb 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
62 lines (54 loc) · 2.02 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
const { src, dest, parallel } = require("gulp");
const { phpMinify } = require("@cedx/gulp-php-minify");
const gulpClean = require("gulp-clean");
const sass = require("gulp-sass");
const uglify = require("gulp-uglify-es").default;
const htmlmin = require("gulp-htmlmin");
const rename = require("gulp-rename");
const gulpCopy = require("gulp-copy");
const inject = require("gulp-inject-string");
const browserify = require("gulp-browserify");
const fs = require("fs")
let pkg = JSON.parse(fs.readFileSync("./package.json"));
function clean() {
if (fs.existsSync("./dist")) {
return src("dist", { read: false })
.pipe(gulpClean({ force: true }));
}
return src("dist", { read: false });
}
function copy() {
src(["src/**/.*", "src/**/*.min.*", "src/**/*.ttf", "src/**/*.jpg", "src/**/*.png", "src/**/*.db", "src/**/*.json"])
.pipe(gulpCopy("dist", { prefix: 1 }))
.pipe(inject.replace("<%PKG.VERSION%>", pkg.version));
return src(["vendor/**/*", "vendor/**/*.php"])
.pipe(gulpCopy("dist/internal"));
}
function css() {
return src("src/**/*.scss")
.pipe(sass({ outputStyle: "compressed", sourceMap: true }))
.pipe(inject.replace("<%PKG.VERSION%>", pkg.version))
.pipe(rename({ suffix: ".min" }))
.pipe(dest("dist"))
}
function js() {
return src(["src/**/_*.js", "src/**/*.js", "!src/**/*.min.js"], { sourcemaps: true })
.pipe(inject.replace("<%PKG.VERSION%>", pkg.version))
.pipe(browserify({ insertGlobals: false }))
.pipe(uglify())
.pipe(rename({ suffix: ".min" }))
.pipe(dest("dist", { sourcemaps: true }));
}
function php() {
return src(["src/**/*.php", "src/**/*.phtml"], { read: false })
.pipe(phpMinify())
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(inject.replace("<%PKG.VERSION%>", pkg.version))
.pipe(dest("dist"));
}
exports.copy = copy;
exports.clean = clean;
exports.js = js;
exports.css = css;
exports.php = php;
exports.default = parallel(copy, php, css, js);