-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
128 lines (108 loc) · 3.02 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
var gulp = require('gulp');
var browsersync = require('browser-sync');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var cleancss = require('gulp-clean-css');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var imagemin = require('gulp-imagemin');
var changed = require('gulp-changed');
var htmlmin = require('gulp-htmlmin');
var del = require('del');
var rename = require("gulp-rename");
var sequence = require('run-sequence');
var useref = require('gulp-useref');
var gulpif = require('gulp-if');
var config = {
dist: 'dist/',
src: 'app/',
cssin: 'app/css/*.css',
jsin: 'app/js/*.js',
imgin: 'app/images/**/*.{jpg,jpeg,png,gif}',
htmlin: 'app/*.html',
otherin: 'app/**/*.{json,xml,svg,txt,ico}',
cssout: 'dist/css/',
jsout: 'dist/js/',
imgout: 'dist/images/',
htmlout: 'dist/'
};
/* BROWSER SYNC (dev)
************************************/
gulp.task('reload', function() {
browsersync.reload();
});
/* HTML
************************************/
gulp.task('html', function() {
return gulp.src(config.htmlin)
.pipe(useref())
.pipe(gulpif( '*.css', autoprefixer({ browsers: ['last 4 versions'], grid: true }) ))
.pipe(gulpif( '*.css', cleancss() ))
.pipe(gulpif( '*.js', uglify() ))
.pipe(htmlmin({
sortAttributes: true,
sortClassName: true,
collapseWhitespace: true
}))
.pipe(gulp.dest(config.dist));
});
/* CSS
************************************/
gulp.task('css', function() {
return gulp.src(config.cssin)
// .pipe(sourcemaps.init())
// .pipe(autoprefixer({ browsers: ['last 4 versions'], grid: true }))
// .pipe(concat(config.cssoutname))
// .pipe(cleancss())
// .pipe(sourcemaps.write())
// .pipe(gulp.dest(config.cssout))
.pipe(browsersync.stream());
});
/* JS
************************************/
gulp.task('js', function() {
return gulp.src(config.jsin)
// .pipe(sourcemaps.init())
// .pipe(concat(config.jsoutname))
// .pipe(uglify())
// .pipe(sourcemaps.write())
// .pipe(gulp.dest(config.jsout));
});
/* IMAGES
************************************/
gulp.task('img', function() {
return gulp.src(config.imgin)
.pipe(changed(config.imgout))
.pipe(imagemin())
.pipe(gulp.dest(config.imgout));
});
/* Other
************************************/
gulp.task('other', function() {
return gulp.src(config.otherin)
.pipe(gulp.dest(config.dist));
});
/* PRODUCTION ENVIRONMENT
************************************/
// Clean
gulp.task('clean', function() {
return del([config.dist]);
});
// Start Server
gulp.task('build', function() {
sequence('clean', ['js', 'css', 'img', 'html', 'other']);
browsersync({
server: config.dist
});
});
/* DEVELOPMENT ENVIRONMENT
************************************/
gulp.task('serve', function() {
browsersync({
server: config.src
});
gulp.watch([config.htmlin, config.jsin, config.otherin], ['reload']);
gulp.watch(config.cssin, ['css']);
});
// Start Server
gulp.task('default', ['serve']);