-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
107 lines (97 loc) · 3.56 KB
/
gulpfile.js
File metadata and controls
107 lines (97 loc) · 3.56 KB
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
const gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
connect = require('gulp-connect'),
connectRewrite = require('connect-modrewrite'),
autoprefixer = require('gulp-autoprefixer'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
del = require('del'),
gutil = require('gulp-util'),
rename = require('gulp-rename'),
minifycss = require('gulp-minify-css'),
runSequence = require('run-sequence'),
browserSync = require('browser-sync').create();
const config = {
srcPath:'source/',
sassPath:'_sass/',
mainPath: './',
libPath: 'lib/',
assetPath: 'assets/',
cssPath: 'css/',
jsPath: 'js/',
imgPath: 'img/'
};
gulp.task('styles.clean', function (callback) {
return del(config.mainPath + config.assetPath + config.cssPath + '*.*', callback);
});
gulp.task('styles.scss', function () {
return sass(config.srcPath + config.sassPath + 'main.scss')
.on('error', function (error) {
const lineNumber = (error.lineNumber) ? 'LINE ' + error.lineNumber + ' -- ' : '';
notify({
title: 'Task Failed [' + error.plugin + ']',
message: lineNumber + 'See console.',
sound: 'Sosumi'
}).write(error);
gutil.beep();
let report = '';
const chalk = gutil.colors.white.bgRed;
report += chalk('TASK:') + ' [' + error.plugin + ']\n';
report += chalk('PROB:') + ' ' + error.message + '\n';
if (error.lineNumber) {
report += chalk('LINE:') + ' ' + error.lineNumber + '\n';
}
if (error.fileName) {
report += chalk('FILE:') + ' ' + error.fileName + '\n';
}
console.error(report);
this.emit('end');
})
.pipe(autoprefixer('last 2 versions', 'safari 5', 'ie 8', 'ie 9'))
.pipe(gulp.dest(config.mainPath + config.assetPath + config.cssPath))
.pipe(browserSync.stream());
});
gulp.task('styles.plaincss', function () {
return gulp.src([config.bowerPath + 'normalize-css/*.css',
config.bowerPath + 'animate.css/animate.min.css', 'src/assets/css/*.css'])
.pipe(gulp.dest(config.mainPath + config.assetPath + config.cssPath));
});
gulp.task('styles.minifycss', function () {
return gulp.src([config.mainPath + config.assetPath + config.cssPath + 'normalize.css', config.mainPath + config.assetPath + config.cssPath + 'animate.min.css' , config.mainPath + config.assetPath + config.cssPath + 'main.css'])
.pipe(concat('style.css'))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.pipe(gulp.dest(config.mainPath + config.assetPath + config.cssPath))
});
gulp.task('styles', function (callback) {
runSequence(
'styles.clean',
'styles.scss',
'styles.plaincss',
'styles.minifycss',
callback);
});
gulp.task('compress', function () {
return gulp.src('*')
.pipe(zip('archive.zip'))
.pipe(gulp.dest('dist'));
});
gulp.task("connect", function () {
connect.server();
});
gulp.task("watch", function () {
browserSync.init(null, {
server: {
baseDir: ["./"],
middleware: [connectRewrite(["^.([^\\.]+)$ /$1.html [L]"])],
},
});
gulp.watch(config.srcPath + config.sassPath + "**/*.scss", ["styles"]);
gulp.watch("*.html").on("change", browserSync.reload);
});
gulp.task('default', function (callback) {
runSequence('styles',
'watch',
'connect',
callback);
});