-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
75 lines (65 loc) · 1.88 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
const gulp = require('gulp');
const sass = require('gulp-sass');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const fs = require('fs');
const ROOT = `${__dirname}`;
const outIndex = process.argv.findIndex(elm => {
return elm === '-o';
});
if (outIndex < 0) {
throw new Error('Missing the (-o) output directory as the first argument.');
}
const OUT_DIR = `${ROOT}/${process.argv[outIndex + 1]}`;
if (!fs.existsSync(OUT_DIR)) {
throw new Error(`${OUT_DIR} does not exists.`);
}
const paths = {
styles: {
src: `${ROOT}/scss/**/*.scss`,
dest: `${OUT_DIR}/css`
},
js: {
src: `${ROOT}/js/**/*.js`,
dest: `${OUT_DIR}/js`
},
vendorJs: {
src: [
`${ROOT}/node_modules/jquery/dist/jquery.min.js`
],
dest: `${OUT_DIR}/js`
}
};
// Compile SCSS into CSS and move them to a place where they can be served by the webserver.
let styles = () => {
return gulp
.src(paths.styles.src)
.pipe(sass())
.pipe(gulp.dest(paths.styles.dest));
};
// Move the vendor JavaScript files to a place where they can be served by the webserver.
let vendorJs = () => {
return gulp
.src(paths.vendorJs.src)
.pipe(concat('vendor.js'))
.pipe(gulp.dest(paths.vendorJs.dest));
}
// Move our JavaScript files to a place where they can be served by the webserver.
let js = () => {
return gulp
.src(paths.js.src, { sourcemaps: true })
.pipe(uglify())
.pipe(concat('author.min.js'))
.pipe(gulp.dest(paths.js.dest));
};
// Watching for changes in *.scss & *.js files.
let watch = () => {
gulp.watch([paths.styles.src], styles);
gulp.watch([paths.js.src], js);
gulp.watch([paths.vendorJs.src], vendorJs);
};
let build = gulp.series(vendorJs, gulp.parallel(js, styles));
module.exports = {
default: build,
watch
};