-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
89 lines (81 loc) · 2.37 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
var gulp = require( 'gulp' );
var sass = require( 'gulp-sass' );
var minifyCss = require( 'gulp-minify-css' );
var concat = require( 'gulp-concat' );
var babel = require( 'gulp-babel' );
var uglify = require( 'gulp-uglify' );
var rev = require( 'gulp-rev' );
var revReplace = require( 'gulp-rev-replace' );
var del = require( 'del' );
var paths = {
srcScss: ['./_src/scss/**/*.scss'],
srcScssMain: './_src/scss/application.scss',
srcJs: ['./_src/js/**/*.js'],
srcHtml: ['./_src/*.html'],
srcImg: ['./_src/img/**/*'],
disCss: './css/',
disCssManifest: './css/rev-manifest.json',
disJs: './js/',
disJsManifest: './js/rev-manifest.json',
disHtml: './',
disImg: './img/',
disImgManifest: './img/rev-manifest.json'
};
gulp.task( 'default', ['clean', 'scss', 'js', 'img', 'html', 'watch'] );
gulp.task( 'clean', function( done ) {
return del([
paths.disCss,
paths.disJs,
paths.disImg,
"./index.html"
]);
});
gulp.task( 'scss', ['clean'], function( done ) {
gulp.src( paths.srcScssMain )
.pipe( sass() )
.pipe( minifyCss() )
.pipe( rev() )
.pipe( gulp.dest( paths.disCss ) )
.pipe( rev.manifest() )
.pipe( gulp.dest( paths.disCss ) )
.on( 'end', done );
});
gulp.task( 'js', ['clean'], function( done ) {
gulp.src( paths.srcJs )
.pipe( babel( { presets: ['es2015'] } ) )
.pipe( concat( 'application.js' ) )
.pipe( uglify() )
.pipe( rev() )
.pipe( gulp.dest( paths.disJs ) )
.pipe( rev.manifest() )
.pipe( gulp.dest( paths.disJs ) )
.on( 'end', done );
});
gulp.task( 'html', ['clean', 'scss', 'js', 'img'], function( done ) {
gulp.src( paths.srcHtml )
.pipe( revReplace({
manifest: gulp.src( paths.disCssManifest )
}))
.pipe( revReplace({
manifest: gulp.src( paths.disJsManifest )
}))
.pipe( revReplace({
manifest: gulp.src( paths.disImgManifest )
}))
.pipe( gulp.dest( paths.disHtml ) )
.on( 'end', done );
});
gulp.task( 'img', ['clean'], function( done ) {
gulp.src( paths.srcImg )
.pipe( rev() )
.pipe( gulp.dest( paths.disImg ) )
.pipe( rev.manifest() )
.pipe( gulp.dest( paths.disImg ) )
.on( 'end', done );
});
gulp.task( 'watch', function() {
gulp.watch( paths.srcScss, ['scss', 'html'] );
gulp.watch( paths.srcJs, ['js', 'html'] );
gulp.watch( paths.srcImg, ['img', 'html'] );
gulp.watch( paths.srcHtml, ['html'] );
});