This repository has been archived by the owner on Nov 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
gulpfile.js
91 lines (83 loc) · 2.53 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
var args = require('yargs').argv;
var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync').create();
var bump = require('gulp-bump');
var cssnano = require('gulp-cssnano');
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var moduleImporter = require('sass-module-importer');
var pump = require('pump');
var rename = require('gulp-rename');
var sass = require('gulp-sass');
var uglify = require('gulp-uglify');
var yaml = require('yamljs');
var config = yaml.load('config.yml');
gulp.task('bump', function(cb) {
var type = 'patch';
['prerelease','patch','minor','major'].some(function(arg) {
if(!args[arg])return;
type = arg;
return true;
});
pump([
gulp.src(config.bump, {base: '.'}),
bump({type: type, keys: ['version','ver=']}),
gulp.dest('.'),
], cb);
});
gulp.task('css', function(cb) {
pump([
gulp.src(config.watch.css),
cssnano({
minifyFontValues: false,
zindex: false,
}),
rename({suffix: '.min'}),
gulp.dest(config.dest),
], cb);
});
gulp.task('js', function(cb) {
pump([
gulp.src(config.watch.js),
uglify({
mangle: {properties: {regex: /_$/}},
output: {comments: 'some'},
}),
rename({suffix: '.min'}),
gulp.dest(config.dest),
browserSync.stream(),
], cb);
});
gulp.task('jshint', function(cb) {
pump([
gulp.src(config.watch.js),
jshint(),
jshint.reporter('jshint-stylish'),
jshint.reporter('fail'),
], cb);
});
gulp.task('scss', function(cb) {
pump([
gulp.src(config.watch.scss, {base: '.'}),
sass({
importer: moduleImporter(),
outputStyle: 'expanded',
}).on('error', sass.logError),
autoprefixer(),
rename(function(path) {
path.dirname = path.dirname.replace('src','dist');
path.dirname = path.dirname.replace('scss','css');
}),
gulp.dest('.'),
browserSync.stream(),
], cb);
});
gulp.task('watch', function() {
browserSync.init({
server: {baseDir: '.'},
});
gulp.watch(config.watch.js, gulp.parallel('jshint','js'));
gulp.watch(config.watch.scss, gulp.series('scss'));
gulp.watch(config.watch.html).on('change', browserSync.reload);
});
gulp.task('default', gulp.parallel(gulp.series('scss','css'),'jshint','js'));