-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgulpfile.js
101 lines (82 loc) · 2.59 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
90
91
92
93
94
95
96
97
98
99
100
101
/* hepl-dw/vitfoud-client
*
* /gulpfile.js - Gulp tasks
*
* coded by leny@flatLand!
* started at 22/04/2017
*/
var gulp = require( "gulp" ),
gutil = require( "gulp-util" ),
pug = require( "gulp-pug" ),
sass = require( "gulp-sass" ),
autoprefixer = require( "gulp-autoprefixer" ),
csso = require( "gulp-csso" ),
browserify = require( "browserify" ),
source = require( "vinyl-source-stream" ),
uglify = require( "gulp-uglify" ),
buffer = require( "vinyl-buffer" ),
babelify = require( "babelify" ),
watchify = require( "watchify" );
var aLibs = Object.keys( require( "./package.json" ).dependencies );
// --- Task for pug
gulp.task( "html", function() {
gulp.src( "src/pug/**/*.pug" )
.pipe( pug( {} ) )
.pipe( gulp.dest( "." ) );
} );
// --- Task for styles
gulp.task( "css", function() {
gulp.src( "src/sass/**/*.scss" )
.pipe( sass().on( "error", sass.logError ) )
.pipe( autoprefixer() )
.pipe( csso() )
.pipe( gulp.dest( "assets/css" ) );
} );
// --- Tasks for js
gulp.task( "js-libs", function() {
// process.env.NODE_ENV = "production";
browserify()
.require( aLibs )
.bundle()
.pipe( source( "libs.min.js" ) )
.pipe( buffer() )
.pipe( uglify() )
.pipe( gulp.dest( "assets/js" ) );
} );
gulp.task( "js-app", function() {
browserify( "src/js/main.js" )
.transform( babelify )
.external( aLibs )
.bundle()
.on( "error", gutil.log.bind( gutil, "Browserify Error" ) )
.pipe( source( "app.min.js" ) )
.pipe( buffer() )
.pipe( uglify() )
.pipe( gulp.dest( "assets/js" ) );
} );
gulp.task( "js-watch", function() {
watchify.args.debug = true;
var bundler = watchify( browserify( "src/js/main.js" ), watchify.args );
bundler.transform( babelify );
function rebundle() {
return bundler
.bundle()
.on( "error", gutil.log.bind( gutil, "Browserify Error" ) )
.pipe( source( "app.min.js" ) )
.pipe( buffer() )
.pipe( uglify() )
.pipe( gulp.dest( "assets/js" ) );
}
bundler.on( "update", rebundle );
bundler.on( "log", gutil.log.bind( gutil ) );
return rebundle();
} );
gulp.task( "js", [ "js-libs", "js-app" ] );
// --- Watch tasks
gulp.task( "watch", [ "js-watch" ], function() {
gulp.watch( "src/pug/**/*.pug", [ "html" ] );
gulp.watch( "src/sass/**/*.scss", [ "css" ] );
} );
// --- Aliases
gulp.task( "default", [ "html", "css", "js" ] );
gulp.task( "work", [ "default", "watch" ] );