forked from henrikhb/bootstrap-4-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
115 lines (96 loc) · 2.72 KB
/
gulpfile.babel.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
import browserSync from 'browser-sync';
import del from 'del';
import gulp from 'gulp';
import babel from 'gulp-babel';
import concat from 'gulp-concat';
import minifyCSS from 'gulp-csso';
import noop from 'gulp-noop';
import rename from 'gulp-rename';
import compileSass from 'gulp-sass';
import uglify from 'gulp-uglify-es';
import {argv} from 'yargs';
/*
* Misc
*/
const prod = Boolean(argv.prod);
const paths = {
html: './**/*.html',
scripts: {
src: {
ours: ['src/scripts/*.js'],
vendors: [
'node_modules/jquery/dist/jquery.min.js',
'node_modules/popper.js/dist/umd/popper.min.js',
'node_modules/bootstrap/dist/js/bootstrap.min.js'
]
},
dest: 'dist/scripts/'
},
styles: {
src: {
main: ['src/styles/main.scss'],
ours: ['src/styles/**/*.scss']
},
dest: 'dist/styles/'
}
};
/*
* Build-related tasks
*/
const clean = () => del(['dist']);
const html = (done) => {
// TODO:
// Allow for partials?
// Also leaving this function here for now to allow for more verbose logging
done();
};
const scripts = () => {
return gulp.src(paths.scripts.src.vendors.concat(paths.scripts.src.ours), {sourcemaps: true})
.pipe(babel())
.pipe(prod ? concat('index.min.js') : concat('index.js'))
.pipe(prod ? uglify() : noop())
.pipe(gulp.dest(paths.scripts.dest));
};
const styles = () => {
return gulp.src(paths.styles.src.main, {sourcemaps: true})
.pipe(compileSass({
outputStyle: 'expanded'
})
.on('error', compileSass.logError))
.pipe(prod ? rename('main.min.css') : rename('main.css'))
.pipe(prod ? minifyCSS() : noop())
.pipe(gulp.dest(paths.styles.dest))
.pipe(prod ? noop() : stream());
};
/*
* Server related
*/
const server = browserSync.create();
const reload = (done) => {
server.reload();
done();
};
const stream = () => server.reload({stream: true});
const serve = (done) => {
server.init({
server: {
baseDir: './'
}
});
done();
};
/*
* Watch tasks
*/
const watchStyles = () => gulp.watch(paths.styles.src.ours, styles);
const watchScripts = () => gulp.watch(paths.scripts.src.ours, gulp.series(scripts, reload));
const watchHTML = () => gulp.watch(paths.html).on('change', gulp.series(html, reload));
/*
* Expose tasks
*/
export const dev = gulp.series(clean, styles, scripts, serve, gulp.parallel(watchStyles, watchScripts, watchHTML));
export const build = gulp.series(clean, styles, scripts);
export default prod ? build : dev;
// TODO:
// 1. Add gulp-sass-lint & gulp-es-lint ?
// 2. Allow for HTML partials ?