-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
71 lines (63 loc) · 2.08 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
const gulp = require("gulp");
const sourcemaps = require("gulp-sourcemaps");
const uglify = require("gulp-uglify");
const less = require("gulp-less");
const cleanCSS = require("gulp-clean-css");
const concat = require('gulp-concat');
const source = require("vinyl-source-stream");
const buffer = require("vinyl-buffer");
const browserify = require("browserify");
const babel = require("babelify");
const paths = {
less: {
watchFiles: "public/styles/*.less",
source: [
"public/styles/mainStyle.less",
"public/styles/mainStyle2.less"
],
destMapFolder: "./maps"
},
js: {
watchFiles: "public/js/*.js",
source: [
"node_modules/@babel/polyfill/dist/polyfill.min.js",
"public/js/main.js",
"public/js/main2.js"
],
destMapFolder: "./maps"
},
build: {
destBuildFolder: "dist",
destMinCSSFileName: "bundle.min.css",
destMinJSFileName: "bundle.min.js"
}
}
gulp.task("less", (done) => {
gulp.src(paths.less.source)
.pipe(buffer())
.pipe(sourcemaps.init())
.pipe(less({ strictMath: true })) // .pipe(gulp.dest(paths.less.destCSSFolder)) // if for some reason css is needed, then uncomment this
.pipe(cleanCSS({ debug: true }))
.pipe(concat(paths.build.destMinCSSFileName))
.pipe(sourcemaps.write(paths.less.destMapFolder))
.pipe(gulp.dest(paths.build.destBuildFolder));
done();
});
gulp.task("js", (done) => {
const bundler = browserify({ entries: paths.js.source }, { debug: true }).transform(babel);
bundler.bundle()
.on("error", function (err) { console.error(err); this.emit("end"); })
.pipe(source(paths.build.destMinJSFileName))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify())
.pipe(sourcemaps.write(paths.js.destMapFolder))
.pipe(gulp.dest(paths.build.destBuildFolder));
done();
});
function watchFiles() {
gulp.watch(paths.js.watchFiles, gulp.series("js"));
gulp.watch(paths.less.watchFiles, gulp.series("less"));
}
gulp.task("watch", gulp.series(watchFiles), (done) => done());
gulp.task("default", gulp.series("less", "js"), (done) => done());