-
Notifications
You must be signed in to change notification settings - Fork 23
/
gulpfile.babel.js
67 lines (58 loc) · 1.71 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
import gulp from 'gulp';
import jshint from 'gulp-jshint';
import stylish from 'jshint-stylish';
import uglify from 'gulp-uglify';
import csso from 'gulp-csso';
import sourcemaps from 'gulp-sourcemaps';
import rev from 'gulp-rev';
import revReplace from 'gulp-rev-replace';
import filter from 'gulp-filter';
import useref from 'gulp-useref';
/* Variables and paths
------------------------------------- */
const paths = {
build: 'public_html/',
index: 'src/index.html',
scripts: 'src/js/*.js',
};
/* Tasks
------------------------------------- */
// 'Lints all javascript files'
export function lint () {
return gulp.src(paths.scripts)
.pipe(jshint())
.pipe(jshint.reporter(stylish))
;
}
// 'Builds the app'
export function build () {
var jsFilter = filter('**/*.js', { restore: true });
var cssFilter = filter('**/*.css', { restore: true });
var notIndexHtmlFilter = filter(['**/*', '!**/index.html'], { restore: true });
return gulp.src(paths.index)
.pipe(useref({ searchPath: '.' }))
.pipe(jsFilter)
.pipe(uglify()) // Minify any javascript sources
.pipe(jsFilter.restore)
.pipe(cssFilter)
.pipe(csso()) // Minify any CSS sources
.pipe(cssFilter.restore)
.pipe(notIndexHtmlFilter)
.pipe(rev()) // Rename the concatenated files (but not index.html)
.pipe(notIndexHtmlFilter.restore)
.pipe(revReplace()) // Substitute in new filenames
.pipe(gulp.dest(paths.build))
;
}
// 'Re-builds the app on changes'
export function watch () {
gulp.watch(
['src/js/**/*.js', 'src/css/**/*.css', 'src/index.html'],
{ ignoreInitial: false },
build
);
}
/*
* Export a default task
*/
export default build;