forked from Taritsyn/JavaScriptEngineSwitcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
135 lines (117 loc) · 3.87 KB
/
gulpfile.js
File metadata and controls
135 lines (117 loc) · 3.87 KB
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
128
129
130
131
132
133
134
135
/*global require */
"use strict";
// include plug-ins
var gulp = require('gulp');
var del = require('del');
var sourcemaps = require('gulp-sourcemaps');
var rename = require('gulp-rename');
var concat = require('gulp-concat');
var less = require('gulp-less');
var autoprefixer = require('gulp-autoprefixer');
var cleanCss = require('gulp-clean-css');
var uglify = require('gulp-uglify');
var webRootPath = "wwwroot";
var bowerDirPath = webRootPath + "/lib";
var styleDirPath = webRootPath + '/styles';
var scriptDirPath = webRootPath + '/scripts';
//#region Clean
//#region Clean builded assets
gulp.task('clean-builded-styles', function () {
del.sync([styleDirPath + '/build/*']);
});
gulp.task('clean-builded-scripts', function () {
del.sync([scriptDirPath + '/build/*']);
});
gulp.task('clean-builded-assets', ['clean-builded-styles', 'clean-builded-scripts'], function () { });
//#endregion
//#endregion
//#region Build assets
//#region Build styles
var autoprefixerOptions = {
browsers: ['> 1%', 'last 3 versions', 'Firefox ESR', 'Opera 12.1'],
cascade: true
};
var cssCleanOptions = { keepSpecialComments: '*' };
var cssRenameOptions = { extname: '.min.css' };
gulp.task('build-common-styles', function () {
return gulp
.src([styleDirPath + '/app.less'])
.pipe(sourcemaps.init())
.pipe(less({
relativeUrls: true,
rootpath: '/styles/'
}))
.pipe(autoprefixer(autoprefixerOptions))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(styleDirPath + '/build'))
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(concat('common-styles.css'))
.pipe(cleanCss(cssCleanOptions))
.pipe(rename(cssRenameOptions))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(styleDirPath + '/build'))
;
});
gulp.task('build-styles', ['build-common-styles'], function () { });
//#endregion
//#region Build scripts
var jsConcatOptions = { newLine: ';' };
var jsUglifyOptions = {
output: { comments: /^!/ }
};
var jsRenameOptions = { extname: '.min.js' };
gulp.task('build-modernizr-scripts', function () {
return gulp
.src([bowerDirPath + '/modernizr/modernizr.js'])
.pipe(sourcemaps.init())
.pipe(uglify(jsUglifyOptions))
.pipe(rename(jsRenameOptions))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(scriptDirPath + '/build'))
;
});
gulp.task('build-common-scripts', function () {
return gulp
.src([scriptDirPath + '/common.js'])
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(rename({ basename: 'common-scripts' }))
.pipe(uglify(jsUglifyOptions))
.pipe(rename(jsRenameOptions))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(scriptDirPath + '/build'))
;
});
gulp.task('build-evaluation-form-scripts', function () {
return gulp
.src([bowerDirPath + '/jquery-validation/dist/jquery.validate.js',
bowerDirPath + '/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js',
bowerDirPath + '/bootstrap/js/button.js',
scriptDirPath + '/evaluation-form.js'])
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(concat('evaluation-form-scripts.js', jsConcatOptions))
.pipe(uglify(jsUglifyOptions))
.pipe(rename(jsRenameOptions))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(scriptDirPath + '/build'))
;
});
gulp.task('build-scripts', ['build-modernizr-scripts', 'build-common-scripts',
'build-evaluation-form-scripts'], function () { });
//#endregion
gulp.task('build-assets', ['build-styles', 'build-scripts'], function () { });
//#endregion
//#region Watch assets
gulp.task('watch-styles', function () {
return gulp.watch([styleDirPath + '/**/*.{less,css}', '!' + styleDirPath + '/build/**/*.*'],
['build-styles']);
});
gulp.task('watch-scripts', function () {
return gulp.watch([scriptDirPath + '/**/*.js', '!' + scriptDirPath + '/build/**/*.*'],
['build-scripts']);
});
gulp.task('watch-assets', ['watch-styles', 'watch-scripts']);
//#endregion
//Set a default tasks
gulp.task('default', ['clean-builded-assets'], function () {
return gulp.start('build-assets');
});