-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
105 lines (86 loc) · 2.48 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
102
103
104
105
var gulp = require( 'gulp' ),
path = require( 'path' ),
lr = require( 'tiny-lr' ),
livereload = require( 'gulp-livereload' ),
server = lr(),
connect = require( 'connect' ),
sass = require( 'gulp-sass' ),
prefix = require( 'gulp-autoprefixer' ),
imagemin = require( 'gulp-imagemin' ),
inlineCss = require( 'gulp-inline-css' ),
clean = require( 'gulp-clean' );
// source and distribution folders
var src = 'src/';
var dist = path.resolve( 'dist/' );
// localhost port
var LocalPort = 4000;
// start local server
gulp.task( 'server', function() {
connect.createServer(
connect.static( dist )
).listen( LocalPort );
console.log( "\nlocal server running at http://localhost:" + LocalPort + "/\n" );
});
// copy html
gulp.task( 'html', function() {
gulp.src( src + 'index.html' )
.pipe( gulp.dest ( dist ) )
.pipe( livereload( server ) );
});
// complie sass & add vendor prefixes
gulp.task( 'css', function() {
gulp.src( src + 'sass/*.scss' )
.pipe( sass({
outputStyle: [ 'expanded' ],
errLogToConsole: true
}))
.pipe( prefix() )
.pipe( gulp.dest( src ) )
.pipe( gulp.dest( dist ) )
.pipe( livereload( server ) );
});
// minify raster images
gulp.task( 'imgs', function() {
gulp.src( [ src + 'img/*.png', src + 'img/*.gif', src + 'img/*.jpg' ] )
.pipe( imagemin() )
.pipe( gulp.dest( dist + '/img' ) )
.pipe( livereload( server ) );
});
// inline css
gulp.task( 'inliner', function() {
return gulp.src( src + 'index.html' )
.pipe( inlineCss() )
.pipe( gulp.dest ( dist ) );
});
// delete dist styles.css
gulp.task( 'deleteCss', function() {
gulp.src( 'styles.css', { read: false })
.pipe( clean() );
});
// watch & liveReload
gulp.task( 'watch', function() {
server.listen( 35729, function ( err ) {
if ( err ) return console.log( err );
gulp.watch( src + 'index.html', function() {
gulp.run( 'html' );
});
gulp.watch( src + 'sass/*.scss', function() {
gulp.run( 'css' );
});
gulp.watch( [ src + 'img/*.png', src + 'img/*.gif', src + 'img/*.jpg' ], function() {
gulp.run( 'imgs' );
});
});
});
// build assets - only needed once
gulp.task( 'build', function() {
gulp.run( 'html', 'css', 'imgs' );
});
// production task - run when your ready to deploy
gulp.task( 'prod', function() {
gulp.run( 'inliner', 'deleteCss' );
});
// development task
gulp.task( 'default', function(callback){
gulp.run( 'server', 'watch' );
});