-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathgulpfile.js
79 lines (70 loc) · 2.01 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
var gulp = require('gulp');
var sass = require('gulp-sass');
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
var svgstore = require('gulp-svgstore');
var svgmin = require('gulp-svgmin');
var cheerio = require('gulp-cheerio');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var fileinclude = require('gulp-file-include');
var browserSync = require('browser-sync').create();
var sourcemaps = require('gulp-sourcemaps');
gulp.task('css', function () {
gulp.src('./scss/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(sourcemaps.init())
.pipe(postcss([ autoprefixer({ browsers: ['last 2 versions'] }) ]))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist/css'))
.pipe(browserSync.stream({match: '**/*.css'}));
});
gulp.task('compress', function() {
return gulp.src('js/*.js')
.pipe(uglify())
.pipe(gulp.dest('js/min'));
});
gulp.task('concat', function() {
return gulp.src([
// Specifying each one so it happens in order
'js/min/jquery.js',
'js/min/global.js'
])
.pipe(concat('global.js'))
.pipe(gulp.dest('dist/js'));
});
gulp.task('move', function() {
return gulp.src([
'js/min/service-worker.js'
])
.pipe(gulp.dest('dist'));
});
gulp.task('svgstore', function () {
return gulp
.src('images/svg/*.svg')
.pipe(svgmin())
.pipe(svgstore())
.pipe(cheerio(function ($) {
$('svg').attr('display', 'none');
}))
.pipe(gulp.dest('images/svg-sprite/'));
});
gulp.task('fileinclude', function() {
gulp.src(['index.html'])
.pipe(fileinclude({
prefix: '@@',
basepath: ''
}))
.pipe(gulp.dest('dist'));
});
gulp.task('default', function () {
gulp.watch('./scss/*.scss', ['css']);
gulp.watch('./js/*.js', ['compress', 'concat', 'move']);
gulp.watch('./images/svg/*.svg', ['svgstore', 'fileinclude']);
gulp.watch('./index.html', ['fileinclude', browserSync.reload]);
browserSync.init({
server: {
baseDir: './dist/'
}
});
});