-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
92 lines (80 loc) · 2.74 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
/// <binding BeforeBuild='css-clean, sass-to-css, clean-bundle, bundle-min, cache-burst-ts, copy-system-cache-buster' ProjectOpened='sass-to-css:watch' />
"use strict";
var gulp = require("gulp"),
concat = require("gulp-concat"),
cssmin = require("gulp-cssmin"),
sass = require("gulp-sass"),
sourcemap = require("gulp-sourcemaps"),
uglify = require("gulp-uglify"),
merge = require("merge-stream"),
del = require("del"),
cleanCSS = require("gulp-clean-css"),
clean = require("gulp-clean"),
replace = require('gulp-replace'),
gutil = require('gulp-util'),
bundleconfig = require("./bundleconfig.json");
module.exports = gulp;
var window = {};
var fs = require('fs');
var elasticlunr = require('elasticlunr');
var beautify = require('json-beautify');
var regex = {
css: /\.css$/,
html: /\.(html|htm)$/,
js: /\.js$/
};
/* Gulp to convert all Scss to css while saving */
gulp.task('sass-to-css', function () {
return gulp.src(['./wwwroot/css/**/*.scss',
, '!./wwwroot/css/Common/*.scss'])
.pipe(sass.sync().on('error', sass.logError))
.pipe(gulp.dest('./wwwroot/dist/css'));
});
gulp.task('sass-to-css:watch', function () {
gulp.watch('./wwwroot/css/**/*.scss', ['sass-to-css']);
});
gulp.task('css-clean', function () {
return gulp.src(['./wwwroot/dist/**/*.css',
'./wwwroot/dist/**/*.js',])
.pipe(clean());
});
/*Minifying using Bundle*/
gulp.task("bundle-min", ["min:js", "min:css"]);
gulp.task("min:js", function () {
var tasks = getBundles(regex.js).map(function (bundle) {
return gulp.src(bundle.inputFiles, { base: "." })
.pipe(concat(bundle.outputFileName))
.pipe(uglify())
.on('error', function (err) { gutil.log(gutil.colors.red('[Error]'), err.toString()); })
.pipe(gulp.dest("."));
});
return merge(tasks);
});
gulp.task("min:css", function () {
var tasks = getBundles(regex.css).map(function (bundle) {
return gulp.src(bundle.inputFiles, { base: "." })
.pipe(concat(bundle.outputFileName))
.pipe(cssmin())
.pipe(gulp.dest("."));
});
return merge(tasks);
});
gulp.task("clean-bundle", function () {
var files = bundleconfig.map(function (bundle) {
return bundle.outputFileName;
});
return del(files);
});
gulp.task("bundle-watch", function () {
getBundles(regex.js).forEach(function (bundle) {
gulp.watch(bundle.inputFiles, ["min:js"]);
});
getBundles(regex.css).forEach(function (bundle) {
gulp.watch(bundle.inputFiles, ["min:css"]);
});
});
function getBundles(regexPattern) {
return bundleconfig.filter(function (bundle) {
return regexPattern.test(bundle.outputFileName);
});
}