forked from overtrue/share.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
127 lines (109 loc) · 3.3 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
var basePaths = {
src: 'src/',
dest: 'dist/',
bower: 'bower_components/'
};
var paths = {
scripts: {
src: basePaths.src + 'js/',
dest: basePaths.dest + 'js/'
},
styles: {
src: basePaths.src + 'css/',
dest: basePaths.dest + 'css/'
},
fonts: {
src: basePaths.src + 'fonts/',
dest: basePaths.dest + 'fonts/'
}
};
var appFiles = {
styles: [paths.styles.src + '**/*.scss'],
jqueryShare: [paths.scripts.src + 'jquery.qrcode.min.js', paths.scripts.src + 'jquery.share.js'],
socialShare: [paths.scripts.src + 'qrcode.js', paths.scripts.src + 'social-share.js'],
fonts: [paths.fonts.src + '**/*']
};
var vendorFiles = {
styles: [],
scripts: [],
fonts: []
};
/*
Let the magic begin
*/
var gulp = require('gulp');
var es = require('event-stream');
var gutil = require('gulp-util');
var concat = require('gulp-concat');
var del = require('del');
var plugins = require("gulp-load-plugins")({
pattern: ['gulp-*', 'gulp.*'],
replaceString: /\bgulp[\-.]/
});
// Allows gulp --dev to be run for a more verbose output
var isProduction = true;
var sassStyle = 'compressed';
var sourceMap = false;
if(gutil.env.dev === true) {
sassStyle = 'expanded';
sourceMap = true;
isProduction = false;
}
var changeEvent = function(evt) {
gutil.log('File', gutil.colors.cyan(evt.path.replace(new RegExp('/.*(?=/' + basePaths.src + ')/'), '')), 'was', gutil.colors.magenta(evt.type));
};
var clean = function(path, cb) {
// You can use multiple globbing patterns as you would with `gulp.src`
del([path], {force:true}, cb);
};
gulp.task('css', function(cb){
// app css
plugins.sass(vendorFiles.styles.concat(appFiles.styles), {
outputStyle: sassStyle, sourcemap: sourceMap, precision: 2
})
// .pipe(plugins.concat('style.min.css'))
.pipe(plugins.autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
// .pipe(isProduction ? plugins.cssmin() : gutil.noop())
.pipe(plugins.size())
.on('error', function(err){
new gutil.PluginError('CSS', err, {showStack: true});
})
.pipe(plugins.notify())
.pipe(plugins.rename({suffix: '.min'}))
.pipe(gulp.dest(paths.styles.dest));
cb()
});
gulp.task('jquery.share.js', function () {
return gulp.src(appFiles.jqueryShare)
.pipe(concat('jquery.share.js'))
.pipe(isProduction ? plugins.uglify() : gutil.noop())
.pipe(plugins.size())
.pipe(plugins.notify())
.pipe(plugins.rename({suffix: '.min'}))
.pipe(gulp.dest(paths.scripts.dest));
});
gulp.task('share.js', function () {
return gulp.src(appFiles.socialShare)
.pipe(concat('social-share.js'))
.pipe(isProduction ? plugins.uglify() : gutil.noop())
.pipe(plugins.size())
.pipe(plugins.notify())
.pipe(plugins.rename({suffix: '.min'}))
.pipe(gulp.dest(paths.scripts.dest));
});
gulp.task('fonts', function(){
return gulp.src(appFiles.fonts)
.pipe(gulp.dest(paths.fonts.dest));
});
gulp.task('watch', gulp.parallel('css', 'jquery.share.js', 'share.js', 'fonts'), function () {
gulp.watch(appFiles.styles, ['css']).on('change', function (evt) {
changeEvent(evt);
});
gulp.watch(paths.scripts.src + '*.js', ['jquery.share.js', 'share.js']).on('change', function (evt) {
changeEvent(evt);
});
});
gulp.task('default', gulp.parallel( 'css', 'jquery.share.js', 'share.js', 'fonts' ));