-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
executable file
·112 lines (97 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
// Grab packages
var gulp = require('gulp'),
gutil = require('gulp-util'),
sass = require('gulp-sass'),
sourcemaps = require('gulp-sourcemaps'),
rename = require('gulp-rename'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
autoprefixer = require('gulp-autoprefixer'),
watch = require('gulp-watch'),
notify = require('gulp-notify'),
plumber = require('gulp-plumber'),
cleanCSS = require('gulp-clean-css');
// Create build css task
gulp.task('build-css', function() {
gutil.log('Generate css files ...');
var onError = function(err) {
notify.onError({
title: 'Gulp',
subtitle: 'Failure!',
message: 'Error: <%= error.message %>',
sound: 'Beep'
})(err);
this.emit('end');
};
gulp.src('Resources/Private/Assets/Styles/main.scss')
.pipe(plumber({errorHandler: onError}))
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(gulp.dest('Resources/Public/Styles'))
.pipe(rename('main.min.css'))
.pipe(cleanCSS())
.pipe(autoprefixer({
browsers: ['last 4 versions'],
cascade: false
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('Resources/Public/Styles'))
.pipe(notify({
'title': 'Gulp',
'message': 'CSS files were generated'
}));
});
// Create build js task
gulp.task('build-js', function() {
gutil.log('Generate js files ...');
var onError = function(err) {
notify.onError({
title: 'Gulp',
subtitle: 'Failure!',
message: 'Error: <%= error.message %>',
sound: 'Beep'
})(err);
this.emit('end');
};
// Website js files
gulp.src([
'Resources/Private/Assets/JavaScript/**/!(main)*.js',
'!' + 'Resources/Private/Assets/JavaScript/backend.js',
'Resources/Private/Assets/JavaScript/main.js'
])
.pipe(plumber({errorHandler: onError}))
.pipe(sourcemaps.init())
.pipe(concat('main.js'))
.pipe(gulp.dest('Resources/Public/JavaScript'))
.pipe(rename('main.min.js'))
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest('Resources/Public/JavaScript'));
// Backend js files
gulp.src([
'Resources/Private/Assets/JavaScript/backend.js'
])
.pipe(plumber({errorHandler: onError}))
.pipe(sourcemaps.init())
.pipe(concat('backend.js'))
.pipe(gulp.dest('Resources/Public/JavaScript'))
.pipe(rename('backend.min.js'))
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest('Resources/Public/JavaScript'));
});
// Create default task
gulp.task('default', function() {
gulp.src('Resources/Private/Assets/Styles/**/*.scss', {read: false})
.pipe(watch('Resources/Private/Assets/Styles/**/*.scss', function() {
gulp.start('build-css');
}));
gulp.src('Resources/Private/Assets/JavaScript/**/*.js', {read: false})
.pipe(watch('Resources/Private/Assets/JavaScript/**/*.js', function() {
gulp.start('build-js');
}))
.pipe(notify({
'title': 'Gulp',
'message': 'JavaScript files were generated'
}));
});