This repository has been archived by the owner on May 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gulpfile.js
97 lines (77 loc) · 2.41 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
var gulp = require('gulp');
var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync').create();
var clean = require('gulp-clean');
var cleanCSS = require('gulp-clean-css');
var pump = require('pump');
var rename = require("gulp-rename");
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var gzip = require('gulp-gzip');
var input = ['./scss/**/*.scss'];
var output = './dist';
var autoprefixerOptions = {
browsers: ['last 2 versions', '> 5%', 'Firefox ESR']
};
var sassOptions = {
outputStyle: 'compact'
};
gulp.task('clean', function() {
return gulp.src([output], { read: false })
.pipe(clean({ force: true }));
});
gulp.task('serve', ['sass-dev'], function() {
browserSync.init({
port: 3000,
server: "./"
});
gulp.watch(input, ['sass-dev']);
gulp.watch("./*.html").on('change', browserSync.reload);
});
gulp.task('sass-dev', function() {
return gulp
.src(input)
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(autoprefixer(autoprefixerOptions))
.pipe(gulp.dest(output))
.pipe(browserSync.stream());
});
gulp.task('sass', ['clean'], function() {
return gulp
.src(input)
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(autoprefixer(autoprefixerOptions))
.pipe(gulp.dest(output));
});
gulp.task('uglify-js', ['clean'], function(cb) {
var uglifyOptions = {
mangle: true,
preserveComments: 'license'
};
pump([
gulp.src('./js/*.js'),
uglify(),
gulp.dest(output)
], cb);
});
gulp.task('rename', ['sass', 'uglify-js'], function() {
return gulp.src([output + "/*.css", output + "/*.js"])
.pipe(rename(function(path) {
path.basename += ".min";
}))
.pipe(gulp.dest(output));
});
gulp.task('minify-css', ['rename'], function() {
return gulp.src(output + '/*.min.css')
.pipe(cleanCSS({ compatibility: 'ie8' }))
.pipe(gulp.dest(output));
});
gulp.task('gzip', ['rename'], function() {
return gulp.src([output + "/*.min.css", output + "/*.min.js"])
.pipe(gzip())
.pipe(gulp.dest(output));
});
gulp.task('build:prod', ['clean', 'sass', 'uglify-js', 'rename', 'minify-css', 'gzip']);
gulp.task('build:dev', ['clean', 'sass-dev', 'serve']);
gulp.task('default', ['build:dev']);