This repository has been archived by the owner on Feb 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
101 lines (90 loc) · 2.76 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
import runSequence from 'run-sequence';
import obt from 'origami-build-tools';
import gulp from 'gulp';
import del from 'del';
const $ = require('auto-plug')('gulp');
// compresses images (client => dist)
gulp.task('images', () => {
return gulp.src('client/**/*.{jpg,png,gif,svg}')
.pipe($.imagemin({
progressive: true,
interlaced: true,
}))
.pipe(gulp.dest('public'));
});
// copies over miscellaneous files (client => dist)
gulp.task('copy', () => {
return gulp.src([
'client/**/*',
'!client/styles/**',
'!client/**/*.{scss,js,jpg,png,gif,svg}', // all handled by other tasks
], {dot: true})
.pipe(gulp.dest('public'));
});
gulp.task('clean', del.bind(null, ['public/*', '!public/.git'], {dot: true}));
// builds scripts with browserify
gulp.task('scripts', () => {
return obt.build.js(gulp, {
buildFolder: 'public',
js: './client/scripts/main.js',
buildJs: 'scripts/main.js',
env: process.env.NODE_ENV
// transforms: [require('hbsfy')],
}).on('error', function (error) {
console.error(error);
this.emit('end');
});
});
// builds stylesheets with sass/autoprefixer
gulp.task('styles', () => {
return obt.build.sass(gulp, {
buildFolder: 'public',
sass: ['./client/styles/main.scss'],
buildCss: {dirname: 'styles'},
env: process.env.NODE_ENV
}).on('error', function (error) {
console.error(error);
this.emit('end');
});
});
gulp.task('rev', () => {
return gulp.src([
'public/styles/**/*.css',
'public/scripts/**/*.js',
'public/images/**/*.{png,svg,gif,jpg}'
], {base: 'assets'})
.pipe(gulp.dest('public')) // copy original assets to build dir
.pipe($.rev())
.pipe($.revReplace({replaceInExtensions: ['.css']}))
.pipe($.revNapkin({verbose:false}))
.pipe(gulp.dest('public')) // write rev'd assets to build dir
.pipe($.rev.manifest())
.pipe(gulp.dest('public')); // write manifest to build dir
});
// // lints SCSS files
// gulp.task('scsslint', () => {
// return obt.verify.scssLint(gulp, {
// sass: './client/styles/*.scss',
// }).on('error', function (error) {
// console.error('\n', error, '\n');
// this.emit('end');
// });
// });
// sets up watch-and-rebuild for JS and CSS
gulp.task('watch', done => {
runSequence(['scripts', 'styles', 'images'], () => {
gulp.watch('./client/**/*.scss', ['styles'/*, 'scsslint'*/]);
gulp.watch('./client/**/*.js', ['scripts'/*, 'js lint'*/]);
gulp.watch('./client/**/*.{jpg,png,gif,svg}', ['images']);
done();
});
});
// makes a production build (client => dist)
gulp.task('default', done => {
runSequence(
['clean'/*, 'scsslint', 'js lint'*/],
['scripts', 'styles', 'copy'],
['images'],
['rev'],
done);
});