forked from YuliaSavchuk/learning-path-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
109 lines (95 loc) · 3.2 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
/// <vs SolutionOpened='watch' />
var gulp = require('gulp'),
del = require('del'),
minifyCss = require('gulp-minify-css'),
uglify = require('gulp-uglify'),
useref = require('gulp-useref'),
eventStream = require('event-stream'),
amdOptimize = require('amd-optimize'),
concat = require('gulp-concat'),
gulpif = require('gulp-if'),
output = ".output",
buildVersion = +new Date(),
durandal = require('gulp-durandal'),
$ = require('gulp-load-plugins')({
lazy: true
});
var config = {
less: {
src: ['./css/**/*.less'],
dest: './css',
browsers: ['last 1 Chrome version', 'last 1 Firefox version', 'last 1 Explorer version', 'last 1 Safari version', 'Android > 2.3']
}
};
function addBuildVersion() {
return eventStream.map(function (file, callback) {
var fileContent = String(file.contents);
fileContent = fileContent
.replace(/(\?|\&)v=([0-9]+)/gi, '') // remove build version
.replace(/\.(jpeg|jpg|png|gif|css|js|html|eot|svg|ttf|woff)([?])/gi, '.$1?v=' + buildVersion + '&') // add build version to resource with existing query param
.replace(/\.(jpeg|jpg|png|gif|css|js|html|eot|svg|ttf|woff)([\s\"\'\)])/gi, '.$1?v=' + buildVersion + '$2') // add build version to resource without query param
.replace(/urlArgs: 'v=buildVersion'/gi, 'urlArgs: \'v=' + buildVersion + '\''); // replace build version for require config
file.contents = new Buffer(fileContent);
callback(null, file);
});
};
gulp.task('styles', function () {
return gulp.src(config.less.src)
.pipe($.plumber({
errorHandler: function (error) {
console.log(error);
this.emit('end');
}
}))
.pipe($.less({
strictMath: true,
strictUnits: true
}))
.pipe($.autoprefixer({
browsers: config.less.browsers,
cascade: false
}))
.pipe(gulp.dest(config.less.dest));
});
gulp.task('watch', function () {
gulp.watch('./css/*.less', ['styles']);
});
gulp.task('clean', function (cb) {
del([output], cb);
});
gulp.task('build', ['clean', 'styles'], function () {
var assets = useref.assets();
gulp.src('index.html')
.pipe(assets)
.pipe(gulpif('*.js', uglify()))
.pipe(gulpif('*.css', minifyCss()))
.pipe(assets.restore())
.pipe(useref())
.pipe(addBuildVersion())
.pipe(gulp.dest(output));
durandal(
{
minify: true
})
.pipe(addBuildVersion())
.pipe(gulp.dest(output + '/app'));
gulp.src(['favicon.ico', 'readme.txt'])
.pipe(gulp.dest(output));
gulp.src('css/img/**')
.pipe(gulp.dest(output + '/css/img'));
return gulp.src('css/font/**')
.pipe(gulp.dest(output + '/css/font'));
});
gulp.task('webserver', function () {
gulp.src('.')
.pipe($.webserver({
livereload: {
enable: true,
filter: function (fileName) {
return !fileName.match(/.css/);
}
},
directoryListing: true,
open: "index.html"
}));
});