-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathgulpfile.js
133 lines (114 loc) · 3.39 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
var gulp = require('gulp'),
browserSync = require('browser-sync').create(),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
sass = require('gulp-sass'),
plumber = require('gulp-plumber'),
cleanCSS = require('gulp-clean-css'),
imagemin = require('gulp-imagemin'),
htmlmin = require('gulp-htmlmin'),
fs = require('fs'); // Node module for file system
// browserSync Server
gulp.task('serve', function() {
browserSync.init({
server: "./"
});
});
//Styles
gulp.task('styles', function() {
gulp.src('scss/*.scss')
.pipe(plumber())
.pipe(sass({ outputStyle: 'expanded' }))
.pipe(gulp.dest('css/'))
.pipe(cleanCSS({ compatibility: 'ie8' }))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('css/'))
.pipe(browserSync.stream());
});
//Script
gulp.task('script', function() {
gulp.src(['js/*.js', '!js/*.min.js'])
.pipe(plumber())
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('js/'));
});
//Images
gulp.task('image', () =>
gulp.src('img/*')
.pipe(imagemin())
.pipe(gulp.dest('img/'))
);
//Watch Task
gulp.task('watch', function() {
gulp.watch("scss/**/*.scss", ['styles']);
gulp.watch(['js/*.js', '!js/*.min.js'], ['script']);
gulp.watch("css/*.min.css").on('change', browserSync.reload);
gulp.watch("*.html").on('change', browserSync.reload);
gulp.watch("js/*min.js").on('change', browserSync.reload);
})
gulp.task('copy', function() {
if (fs.existsSync('./src')) {
// Do Nothing if src directory available
} else {
// If src directory not available run the task
// Copy Bootstrap
gulp.src(['node_modules/bootstrap/dist/**/*', '!**/npm.js', '!**/bootstrap-theme.*', '!**/*.map'])
.pipe(gulp.dest('src/bootstrap'));
// Copy Font-awesome
gulp.src([
'node_modules/font-awesome/**/*',
'!node_modules/font-awesome/less{,/**}',
'!node_modules/font-awesome/scss{,/**}',
'!node_modules/font-awesome/**/*.map',
'!node_modules/font-awesome/.npmignore',
'!node_modules/font-awesome/*.txt',
'!node_modules/font-awesome/*.md',
'!node_modules/font-awesome/*.json'
])
.pipe(gulp.dest('src/font-awesome'));
}
});
// Default Task
gulp.task('default', ['styles', 'script', 'copy', 'serve', 'watch']);
//////////////////////////////////////////////////////////
/// Build Task ///
//////////////////////////////////////////////////////////
// Build Server
gulp.task('build-serve', function() {
browserSync.init({
server: "./demo"
});
});
//CSS
gulp.task('css', function() {
gulp.src('css/*.css')
.pipe(gulp.dest('demo/css'));
});
//Html
gulp.task('html', function () {
gulp.src('*.html')
.pipe(htmlmin({
collapseWhitespace: true,
removeComments: true
}))
.pipe(gulp.dest('demo/'));
});
//Images
gulp.task('image', () =>
gulp.src('img/*')
.pipe(imagemin())
.pipe(gulp.dest('demo/img'))
);
//Uglify
gulp.task('js', function () {
gulp.src('js/*.js')
.pipe(gulp.dest('demo/js'));
});
//Uglify
gulp.task('src', function () {
gulp.src('src/**')
.pipe(gulp.dest('demo/src'));
});
//Build Task
gulp.task('build', ['css', 'html', 'js', 'image', 'src', 'build-serve']);