-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
148 lines (136 loc) · 4.35 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
147
148
const gulp = require("gulp");
const npmDist = require("gulp-npm-dist");
const rename = require("gulp-rename");
const sass = require("gulp-sass");
const sourcemaps = require("gulp-sourcemaps");
const bourbon = require("bourbon").includePaths;
const autoprefixer = require("gulp-autoprefixer");
const del = require("del");
const uglify = require("gulp-uglify");
const cleanCss = require("gulp-clean-css");
const babel = require("gulp-babel");
const browserSync = require("browser-sync").create();
// strongly recommended that you set this explicitly for
// forwards-compatibility in case the default ever changes.
sass.compiler = require("node-sass");
// Task to copy vendor libraries
gulp.task("copy-libs", async function () {
gulp
.src(
npmDist({
excludes: ["sandbox/**/*"],
}),
{ base: "./node_modules/" }
)
.pipe(
rename(function (path) {
path.dirname = path.dirname.replace(/\/dist/, "").replace(/\\dist/, "");
})
)
.pipe(gulp.dest("celery_project/static/vendors"));
});
// Task to delete target: contents of the vendor lib folder
gulp.task("clean", function () {
return del([
"celery_project/static/vendors/**",
"!celery_project/static/vendors",
"!celery_project/static/vendors/.gitignore",
]);
});
gulp.task("sass", function () {
return gulp
.src("celery_project/static/scss/**/*.scss") // Gets all files ending with .scss in static/scss and children dirs
.pipe(sourcemaps.init())
.pipe(
sass({
includePaths: [bourbon],
}).on("error", sass.logError)
)
.pipe(
autoprefixer({
// browsers: ["cover 99.5%"], not recommended to do this
cascade: false,
})
)
.pipe(sourcemaps.write("./maps"))
.pipe(gulp.dest("celery_project/static/css"))
.pipe(browserSync.stream());
});
gulp.task("lint-css", function lintCssTask() {
const gulpStylelint = require("gulp-stylelint");
return gulp
.src("celery_project/static/scss/**/*.scss")
.pipe(
gulpStylelint({
reporters: [{ formatter: "verbose", console: true }],
debug: true,
fix: true,
})
)
.pipe(gulp.dest("celery_project/static/scss"));
});
// Transpile ES6 code into ES5 code using babel
// then Uglify Javascript
gulp.task("uglify", async function () {
return gulp
.src("celery_project/static/js/!(*.min).js") // see https://stackoverflow.com/a/58470327
.pipe(babel({ presets: ["@babel/preset-env"] }))
.pipe(uglify())
.pipe(rename({ suffix: ".min" }))
.pipe(gulp.dest("celery_project/static/js"));
});
// Minify CSS
gulp.task("minify", function () {
return gulp
.src("celery_project/static/css/!(*.min).css") // grab everything that doesn't end with *.min.css
.pipe(cleanCss({ compatibility: "ie9" }))
.pipe(rename({ suffix: ".min" }))
.pipe(gulp.dest("celery_project/static/css"));
});
// A simple task to reload the page
gulp.task("reload", function (done) {
browserSync.reload();
done();
});
// browserSync init
gulp.task("bs_init", function (done) {
browserSync.init({
proxy: "http://127.0.0.1:8000",
files: [
"celery_project/static/scss/**/*.scss",
"celery_project/static/js/**/*.*",
"celery_project/static/css/**/*.*",
"celery_project/**/*.html",
"celery_project/**/*.py",
"config/**/*.py",
],
port: 3000,
localOnly: true,
// Wait for 0.3 seconds before any browsers should try to inject/reload a file
reloadDelay: 300,
// Wait 0.5 seconds after a reload event before allowing more
reloadDebounce: 500,
});
// simple static server (from current dir)
// browserSync.init(null, {
// server: {
// baseDir: "./",
// },
// online: true,
// });
done();
});
// Watch SCSS, CSS, JS, HTML & .py files for changes
gulp.task("watch", function () {
gulp.watch("celery_project/static/scss/**/*.scss", gulp.series("sass"));
gulp.watch("celery_project/static/css/!(*.min).css", gulp.series("minify", "reload"));
gulp.watch("celery_project/static/js/!(*.min).js", gulp.series("uglify", "reload"));
gulp.watch("celery_project/**/*.html", gulp.series("reload"));
gulp.watch("celery_project/**/*.py", gulp.series("reload"));
});
gulp.task("cp", gulp.series("clean", "copy-libs"));
gulp.task("min", gulp.series("sass", "minify", "uglify"));
gulp.task(
"default",
gulp.series("sass", "minify", "uglify", "bs_init", "watch")
);