-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
142 lines (113 loc) · 3.36 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
134
135
136
137
138
139
140
141
142
//general
var gulp = require('gulp');
var del = require('del');
var copy = require('gulp-copy');
//sass
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var minifyCss = require('gulp-minify-css');
//javascript
var uglify = require('gulp-uglify');
//////////////////////////////////////////////////
// Primary Tasks
//////////////////////////////////////////////////
gulp.task('build', ['build:css', 'build:img', 'build:js']);
gulp.task('deploy', ['clean'], function() { gulp.start('build'); });
gulp.task('build-debug', ['build-debug:css', 'build-debug:img', 'build-debug:js']);
gulp.task('watch', ['build-debug', 'watch:css', 'watch:img', 'watch:js']);
//wipe public directory
gulp.task('clean', ['clean:css', 'clean:img', 'clean:js']);
//////////////////////////////////////////////////
// Config
//////////////////////////////////////////////////
var config = {
cssSrcDir: 'client-src/scss',
cssDestDir: 'public/css',
autoprefixOptions: {
browsers: ['> 1%', 'last 2 versions'],
cascade: true,
remove: true
},
imgSrcDir: 'client-src/img',
imgDestDir: 'public/img',
jsSrcDir: 'client-src/js',
jsDestDir: 'public/js'
};
//////////////////////////////////////////////////
// Task Details
//////////////////////////////////////////////////
//styles
gulp.task('clean:css', function(cb) {
var files = config.cssDestDir + '/**/*.*';
del(files, cb);
});
gulp.task('build:css', function() {
var files = config.cssSrcDir + '/**/*.scss';
gulp.src(files)
.pipe(sass.sync({
outFile: 'maintenance.css',
outputStyle: 'nested'
}).on('error', sass.logError))
.pipe(autoprefixer(config.autoprefixOptions))
.pipe(minifyCss())
.pipe(gulp.dest(config.cssDestDir));
});
gulp.task('build-debug:css', function() {
var files = config.cssSrcDir + '/**/*.scss';
gulp.src(files)
.pipe(sass.sync({
outFile: 'maintenance.css',
outputStyle: 'nested',
sourceComments: true,
sourceMap: true,
souceMapEmbed: true
}).on('error', sass.logError))
.pipe(autoprefixer(config.autoprefixOptions))
.pipe(gulp.dest(config.cssDestDir));
});
gulp.task('watch:css', function() {
var files = config.cssSrcDir + '/**/*.*';
gulp.watch(files, ['build-debug:css']);
});
//images
gulp.task('clean:img', function(cb) {
var files = config.imgDestDir + '/**/*.*';
del(files, cb);
});
gulp.task('build:img', function() {
var files = config.imgSrcDir + '/**/*.{svg,png,jpg,gif}';
gulp.src(files)
.pipe(copy(config.imgDestDir, {prefix: 2}));
});
gulp.task('build-debug:img', function() {
var files = config.imgSrcDir + '/**/*.{svg,png,jpg,gif}';
//copy SVGs/PNGs/JPGs/GIFs (no compression for build-debug)
gulp.src(files)
.pipe(copy(config.imgDestDir, {prefix: 2}));
});
gulp.task('watch:img', function() {
var files = config.imgSrcDir + '/**/*.*';
gulp.watch(files, ['build-debug:img']);
});
//javascript
gulp.task('clean:js', function(cb) {
var files = config.jsDestDir + '/**/*.*';
del(files, cb);
});
gulp.task('build:js', function() {
var files = config.jsSrcDir + '/**/*.js';
//compress JS
gulp.src(files)
.pipe(uglify())
.pipe(gulp.dest(config.jsDestDir));
});
gulp.task('build-debug:js', function() {
var files = config.jsSrcDir + '/**/*.js';
//copy JS
gulp.src(files)
.pipe(copy(config.jsDestDir, {prefix: 2}));
});
gulp.task('watch:js', function() {
var files = config.jsSrcDir + '/**/*.*';
gulp.watch(files, ['build-debug:js']);
});