-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
116 lines (101 loc) · 3.41 KB
/
gulpfile.js
File metadata and controls
116 lines (101 loc) · 3.41 KB
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
106
107
108
109
110
111
112
113
114
115
116
'use strict';
var gulp = require('gulp'),
util = require('gulp-util'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
maps = require('gulp-sourcemaps'),
del = require('del'),
plumber = require('gulp-plumber'),
imagemin = require('gulp-imagemin'),
spritesmith = require('gulp-spritesmith'),
csso = require('gulp-csso'),
buffer = require('vinyl-buffer'),
merge = require('merge-stream'),
sync = require('browser-sync').create(),
reload = sync.reload;
gulp.task("log", function(){
util.log('');
});
gulp.task("concatScripts", function(){
return gulp.src('js/main.js')
.pipe(maps.init())
.pipe(concat('app.js'))
.pipe(uglify())
.pipe(maps.write('./'))
.pipe(sync.reload({stream:true}))
.pipe(gulp.dest('js'));
});
gulp.task("minifyScripts", ['concatScripts'], function(){
return gulp.src("js/app.js")
.pipe(uglify())
.pipe(rename('app-min.js'))
.pipe(gulp.dest('dist/js'));
});
gulp.task("compressImgs", function(){
return gulp.src('img/*')
.pipe(imagemin())
.pipe(gulp.dest('dist/img'));
});
gulp.task("sprite", function(){
// Generate our spritesheet. add images to imgsprite folder the task will build the spritesheet
var spriteData = gulp.src('imgspritesrc/*.png') //TODO: FIX OUTPUT LOCATION
.pipe(spritesmith({
imgName: 'sprite.png',
cssName: 'sprite.css'
}));
//Pipe image stream through image optimizer and onto disk
var imgStream = spriteData.img
//DEV: We must buffer our stream into a buffer for 'imagemin'
.pipe(buffer())
.pipe(imagemin())
.pipe(gulp.dest('dist/img'));
//Pipe CSS Stream through CSS optimizer and onto disk
var cssStream = spriteData.css
.pipe(csso())
.pipe(gulp.dest('dist/css'));
//Return a merged stream to handle both 'end' events
return merge(imgStream, cssStream);
});
gulp.task("complieSass", function(){
return gulp.src("scss/style.scss")
.pipe(plumber())
.pipe(maps.init())
.pipe(sass({
"outputStyle": "compressed",
"includePaths": ["scss"],
"onError": sync.notify
}))
.pipe(autoprefixer({
browsers: ['last 3 versions'],
cascade: false
}))
.pipe(maps.write('./'))
.pipe(sync.reload({stream:true}))
.pipe(gulp.dest('css'));
});
gulp.task("browserSync", function(){
sync.init({
server: {
baseDir: './'
}
});
});
gulp.task("clean", function(){
del(['dist', 'css/style.css*', 'js/app*.js*']);
});
gulp.task("watchFiles", function(){
gulp.watch('scss/**/*.scss', ['complieSass']);
gulp.watch('js/*.js', ['concatScripts']);
gulp.watch('img/*', ['compressImgs']);
gulp.watch('./*.html', sync.reload);
});
gulp.task("build", ['concatScripts', 'minifyScripts', 'complieSass', 'watchFiles', 'browserSync'], function(){
return gulp.src(['css/style.css','js/app.min.js', '*.html', 'img/**', 'fonts/**'], {base: './'})
.pipe(gulp.dest('dist'));
});
gulp.task("default", ['clean'], function() {
gulp.start("build");
});