This repository has been archived by the owner on Sep 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·150 lines (139 loc) · 3.7 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
143
144
145
146
147
148
149
150
var gulp = require('gulp');
var sass = require('gulp-sass');
var cmq = require('gulp-combine-mq');
var rename = require('gulp-rename');
var cssmin = require('gulp-cssmin');
var postcss = require('gulp-postcss');
var imageMin = require('gulp-imagemin');
var autoprefixer = require('autoprefixer');
var del = require('del');
var ts = require('gulp-typescript');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var notify = require("gulp-notify");
var runSequece = require('run-sequence');
var watch = require('gulp-watch');
var path = require("path");
var tsProject = ts.createProject("tsconfig.json");
gulp.task('images', function () {
return gulp.src(['assets/images/!*', '!assets/images/!*.md'])
.pipe(imageMin())
.pipe(gulp.dest(function (file) {
return file.base;
}));
});
gulp.task('typescript', function () {
return tsProject.src()
.pipe(tsProject())
.pipe(gulp.dest(function(file){
return file.base;
}));
});
gulp.task('scripts', ['typescript'], function(){
return gulp.src(['assets/scripts/*.js', '!assets/scripts/*.min.js'])
.pipe(uglify({
mangle: true,
compress: {
sequences: true,
dead_code: true,
conditionals: true,
booleans: true,
unused: true,
if_return: true,
join_vars: true
},
preserveComments: function(){return false;}
})).on('error', notify.onError(function(e) {
var fullPath = e.fileName;
var path = fullPath.replace(__dirname, '');
return {
title: path,
message: e.message,
wait: true
};
}))
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(function(file){
return file.base;
}));
});
gulp.task('fonts', function(){
return gulp.src('assets/fonts/fonts.scss')
.pipe(sass({
outputStyle: 'compressed'
}).on('error', notify.onError(function(e) {
return {
title: e.relativePath,
message: e.formatted,
wait: true
};
})))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('assets/fonts'));
});
gulp.task('sass', function(){
return gulp.src(['assets/scss/*.scss', 'assets/scss/**/*.scss'])
.pipe(sass({
outputStyle: 'compact'
}).on('error', notify.onError(function(e) {
return {
title: e.relativePath,
message: e.formatted,
wait: true
};
})))
.pipe(gulp.dest('assets/styles'));
});
gulp.task('styles', ['combine'], function(){
return gulp.src('assets/styles/*.tmp.css')
.pipe(cssmin({
showLog:false
}))
.pipe(rename(function(path){
var name = path.basename;
path.basename = name.replace('.tmp', '.min');
}))
.pipe(postcss([ autoprefixer({ browsers: ['last 3 versions'] })]))
.pipe(gulp.dest(function(file) {
return file.base;
}));
});
gulp.task('combine', ['sass'], function() {
return gulp.src(['assets/styles/*.css', '!assets/styles/*.tmp.css', '!assets/styles/*.min.css'])
.pipe(cmq({
beautify: false
}))
.pipe(rename({suffix: '.tmp'}))
.pipe(gulp.dest('assets/styles'));
});
gulp.task('styles:remove:temp', ['styles'], function(){
del(['assets/styles/*.tmp.css']);
});
gulp.task('watch', function() {
return watch([
'assets/scss/*.scss',
'assets/scss/**/*.scss',
'assets/fonts/*.scss',
//'assets/scripts/*.js',
'assets/scripts/*.ts',
'assets/images/**/*',
'!assets/images/*.md'
], function(){
runSequece(
['styles', 'fonts'],
'scripts',
'styles:remove:temp',
'images'
);
});
});
gulp.task('default', function(cb) {
runSequece(
['styles', 'fonts'],
'scripts',
'styles:remove:temp',
'images',
cb
);
});