This repository has been archived by the owner on Jul 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathGulpfile.js
100 lines (81 loc) · 2.48 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
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 header = require('gulp-header');
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 input = ['./src/**/*.scss'];
var output = './dist';
var pkg = require('./package.json');
var banner = ['/*!',
' * <%= pkg.name %> v<%= pkg.version %>',
' * @author : Irfan Maulana',
' * https://github.com/mazipan/bem-kit',
' */',
''
].join('\n');
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', ['simple-sass'], function() {
browserSync.init({
port: 3000,
server: "./demo"
});
gulp.watch(input, ['simple-sass']);
gulp.watch("./demo/*.html").on('change', browserSync.reload);
});
gulp.task('simple-sass', function() {
return gulp
.src(input)
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(autoprefixer(autoprefixerOptions))
.pipe(gulp.dest('./demo/dist'))
.pipe(browserSync.stream());
});
gulp.task('sass', ['clean'], function() {
return gulp
.src(input)
.pipe(sass(sassOptions))
.pipe(autoprefixer(autoprefixerOptions))
.pipe(header(banner, { pkg: pkg }))
.pipe(gulp.dest(output));
});
gulp.task('uglify-js', ['clean'], function(cb) {
var uglifyOptions = {
mangle: true,
preserveComments: 'license'
};
pump([
gulp.src('./src/*.js'),
uglify(),
gulp.dest(output)
], cb);
});
gulp.task('rename', ['sass', 'uglify-js'], function() {
return gulp.src(["./dist/*.css", "./dist/*.js"])
.pipe(rename(function(path) {
path.basename += ".min";
}))
.pipe(gulp.dest(output));
});
gulp.task('minify-css', ['rename'], function() {
return gulp.src('./dist/*.min.css')
.pipe(cleanCSS({ compatibility: 'ie8' }))
.pipe(gulp.dest(output));
});
gulp.task('build:prod', ['clean', 'sass', 'uglify-js', 'rename', 'minify-css']);
gulp.task('build:dev', ['clean', 'sass', 'serve']);
gulp.task('default', ['build:dev']);