-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
160 lines (135 loc) · 5.42 KB
/
index.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
var gulp = require('gulp');
var notify = require('gulp-notify');
var sass = require('gulp-sass');
var rename = require('gulp-rename');
var autoprefixer = require('gulp-autoprefixer');
var uglifycss = require('gulp-clean-css');
var imagemin = require('gulp-imagemin');
var changed = require('gulp-changed');
var gcmq = require('gulp-group-css-media-queries');
var clean = require('gulp-clean');
var sourcemaps = require('gulp-sourcemaps');
var base64 = require('gulp-base64-inline');
///////////////////////////////////////////////////////
// PATHS
///////////////////////////////////////////////////////
var srcBaseUrl = __dirname + '/src';
var destBaseUrl = './build-css-customer';
// the source paths
var sourcePaths = {
styles: srcBaseUrl + '/scss/**/*',
scss: srcBaseUrl + '/scss/app.scss',
fonts: srcBaseUrl + '/fonts/**/*',
images: srcBaseUrl + '/imgs/**/*.*',
js: srcBaseUrl + '/js/**/*.js',
};
// the destination paths
var destPaths = {
css: destBaseUrl + '/css/',
fonts: destBaseUrl + '/fonts/',
images: destBaseUrl + '/imgs/',
js: destBaseUrl + '/js/',
root: destBaseUrl,
};
module.exports = function(gulp) {
var runSequence = require('run-sequence').use(gulp);
///////////////////////////////////////////////////////
// COMPILATION TASKS
///////////////////////////////////////////////////////
function onError(err) {
console.log(err);
notify("error: "+ err);
this.emit('end');
}
gulp.task('css-client:compile-style', ['css-client:compile-images'], function() {
return gulp.src(sourcePaths.scss)
.pipe(sourcemaps.init().on('error', onError))
.pipe(changed(destPaths.css).on('error', onError))
.pipe(sass({outputStyle: 'expanded'}).on('error', onError))
.pipe(gulp.dest(destPaths.css))
.pipe(notify("style compiled : <%= file.relative %>!"))
.pipe(base64())
.pipe(autoprefixer({browsers: ['> 1%','last 2 versions','ie > 8'],cascade:false}).on('error', onError))
.pipe(gcmq().on('error', onError))
.pipe(uglifycss().on('error', onError))
.pipe(rename({ extname: '.min.css' }).on('error', onError))
.pipe(sourcemaps.write('./map').on('error', onError))
.pipe(gulp.dest(destPaths.css).on('error', onError))
.pipe(notify("style minifyed and autoprefixed : <%= file.relative %>!"));
});
gulp.task('css-client:compile-fonts', function() {
return gulp.src(sourcePaths.fonts)
.pipe(gulp.dest(destPaths.fonts))
});
gulp.task('css-client:compile-images', function() {
return gulp.src(sourcePaths.images)
.pipe(changed(destPaths.images).on('error', onError))
.pipe(imagemin({svgoPlugins: [
{ removeViewBox: false },
{ removeEmptyAttrs: true },
{ removeDoctype: true },
{ convertStyleToAttrs: true}
]}))
.pipe(gulp.dest(destPaths.images));
});
gulp.task('css-client:compile-js', function() {
return gulp.src(sourcePaths.js)
.pipe(changed(destPaths.js).on('error', onError))
.pipe(gulp.dest(destPaths.js));
});
gulp.task('css-client:compile-all', [
'css-client:compile-style',
'css-client:compile-images',
'css-client:compile-fonts',
'css-client:compile-js'
]);
// compile everything after cleaning the build
gulp.task('css-client:compile', [
'css-client:build-clean',
'css-client:compile-all'
]);
///////////////////////////////////////////////////////
// CLEAN TASKS
///////////////////////////////////////////////////////
gulp.task('css-client:clean-styles', function() {
return gulp.src(destPaths.css, {read: false})
.pipe(clean({force: true}).on('error', onError));
});
gulp.task('css-client:clean-images', function() {
return gulp.src(destPaths.images, {read: false})
.pipe(clean({force: true}).on('error', onError));
});
gulp.task('css-client:clean-fonts', function() {
return gulp.src(destPaths.fonts, {read: false})
.pipe(clean({force: true}).on('error', onError));
});
gulp.task('css-client:clean-scripts', function() {
return gulp.src(destPaths.js, {read: false})
.pipe(clean({force: true}).on('error', onError));
});
gulp.task('css-client:build-clean', [
'css-client:clean-styles',
'css-client:clean-images',
'css-client:clean-fonts',
'css-client:clean-scripts',
]);
///////////////////////////////////////////////////////
// WATCH TASKS
///////////////////////////////////////////////////////
gulp.task('css-client:watch-style', function(){
return gulp.watch(sourcePaths.styles, ['css-client:compile-style']);
});
gulp.task('css-client:watch-js', function(){
return gulp.watch(sourcePaths.js, ['css-client:compile-js']);
});
gulp.task('css-client:watch-images', function(){
return gulp.watch(sourcePaths.images, ['css-client:compile-images']);
});
gulp.task('css-client:watch', function() {
runSequence([
'css-client:watch-style',
'css-client:watch-js',
'css-client:watch-images',
]);
});
};