forked from mizner/mizner-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·104 lines (88 loc) · 2.7 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
const path = require("path");
const config = require("./config.json");
const project = config.Project;
const testSite = "http://" + config.DevSite;
const src = path.resolve("src");
const dist = path.resolve("content/themes/" + project + "/dist/");
const jsFiles = config.Files.map((file) => {
return path.join(src, "/scripts/") + file;
});
const gulp = require("gulp"),
bs = require("browser-sync").create(),
autoprefixer = require("gulp-autoprefixer"),
cssnano = require("gulp-cssnano"),
uglify = require("gulp-uglify"),
rename = require("gulp-rename"),
concat = require("gulp-concat"),
sass = require("gulp-sass"),
sourcemaps = require("gulp-sourcemaps"),
babel = require("gulp-babel"),
plumber = require("gulp-plumber"),
del = require('del');
const cssTask = (folder) => {
gulp.task("sass", () => {
gulp.src(path.join(src, folder) + "/main.scss")
.pipe(sourcemaps.init())
.pipe(sass().on("error", sass.logError))
.pipe(autoprefixer())
.pipe(sourcemaps.write())
.pipe(cssnano({zindex: false}))
.pipe(rename(project + ".min.css"))
.pipe(gulp.dest(dist))
.pipe(bs.stream())
});
}
gulp.task("js", () => {
gulp.src(jsFiles)
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(concat("output.js")) // concat pulls all our files together before minifying them
.pipe(sourcemaps.write())
.pipe(babel({
presets: ["es2015"]
}))
.pipe(uglify())
.pipe(rename(project + ".min.js"))
.pipe(gulp.dest(dist))
});
gulp.task("browser-sync", () => {
bs.init(["*"], {
proxy: testSite,
root: path.resolve(),
open: {
file: "index.php"
}
});
});
gulp.task("clean:dist", () => {
return del([
path.join(dist, "**/*") // here we use a globbing pattern to match everything inside the `dist` folder
]);
});
gulp.task("watch", ["browser-sync"], () => {
gulp.watch(path.join(src, "/styles/**/*.scss"), ["sass"]);
gulp.watch(path.join(src, "/scripts/**/*.js"), ["js"]);
gulp.watch("**/*.php", bs.reload);
gulp.watch("gulpfile.js").on("change", () => {
process.exit(0)
})
});
gulp.task("w", ["browser-sync"], () => {
gulp.watch(path.join(src, "/public/**/**"), cssTask('public'));
// gulp.watch(path.join(src, "/scripts/**/*.js"), ["js"]);
gulp.watch("**/*.php", bs.reload);
gulp.watch("gulpfile.js").on("change", () => {
process.exit(0)
})
});
gulp.task("production", [
"clean:dist",
"production-sass",
"js"
]);
gulp.task("default", [
"clean:dist",
"sass",
"js"
]
);