forked from Ardakilic/WhatTheTag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
146 lines (130 loc) · 4.09 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
var gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
notify = require('gulp-notify'),
del = require('del'),
uglify = require('gulp-uglify'),
runSequence = require('run-sequence'),
concat = require('gulp-concat'),
minifyCss = require('gulp-minify-css');
var config = {
jsPath : './resources/assets/js',
sassPath : './resources/assets/sass',
nodePath : './node_modules',
tempPath : './temp_dir',
sassCachePath : './.sass-cache',
public: {
fontPath : './public/fonts',
cssPath : './public/css',
jsPath : './public/js'
}
};
var cssFiles = [
'/bootstrap/dist/css/bootstrap.min.css',
'/datatables-bootstrap3-plugin/media/css/datatables-bootstrap3.min.css',
'/font-awesome/css/font-awesome.min.css',
'/bootstrap-social/bootstrap-social.css',
'/bootstrap-tagsinput/dist/bootstrap-tagsinput.css'
];
cssFiles = cssFiles.map(function(el) {
return config.nodePath + el;
});
var javaScripts = [
'/jquery/dist/jquery.min.js',
'/bootstrap/dist/js/bootstrap.min.js',
'/bootstrap-tagsinput/dist/bootstrap-tagsinput.min.js',
'/datatables/media/js/jquery.dataTables.min.js',
'/datatables-bootstrap3-plugin/media/js/datatables-bootstrap3.min.js',
'/social-share-js/dist/jquery.socialshare.min.js'
];
javaScripts = javaScripts.map(function(el) {
return config.nodePath + el;
});
gulp.task('build-fonts', function() {
return gulp.src([config.nodePath + '/font-awesome/fonts/**.*', config.nodePath + '/bootstrap/fonts/**.*'])
.on('error', notify.onError(function(error) {
return 'Error: ' + error.message;
})
)
.pipe(gulp.dest(config.public.fontPath));
});
gulp.task('vendor-js', function() {
return gulp.src(javaScripts)
.on('error', notify.onError(function (error) {
return 'Error: ' + error.message;
})
)
.pipe(concat('vendor.min.js'))
.pipe(gulp.dest(config.tempPath));
});
gulp.task('app-js', function() {
return gulp.src(config.jsPath + '/**/*.js')
.on('error', notify.onError(function (error) {
return 'Error: ' + error.message;
})
)
.pipe(concat('app-specific.min.js'))
.pipe(uglify())
.pipe(gulp.dest(config.tempPath));
});
gulp.task('merge-scripts', function() {
return gulp.src([config.tempPath + '/vendor.min.js', config.tempPath + '/app-specific.min.js']) //To make sure they are set in order we give paths, so not wildcards
.pipe(concat('app.min.js'))
.on('error', notify.onError(function (error) {
return 'Error: ' + error.message;
})
)
.pipe(gulp.dest(config.public.jsPath));
});
gulp.task('build-scripts', function() {
return runSequence('vendor-js', 'app-js', 'merge-scripts');
});
gulp.task('vendor-css', function(){
return gulp.src(cssFiles)
.on('error', notify.onError(function(error) {
return 'Error: ' + error.message;
})
)
.pipe(concat('vendor.min.css'))
.pipe(minifyCss({compatibility: 'ie8'})) //because bootstrap-tagsinput css is not minified
.pipe(gulp.dest(config.tempPath));
});
gulp.task('app-css', function() {
return sass(config.sassPath + '/app.scss', { //We are including other sass files from this CSS
container : config.tempPath,
style : 'compressed',
stopOnError : true
})
.on('error', notify.onError(function(error) {
return 'Error: ' + error.message;
})
)
.pipe(concat('app-specific.min.css'))
.pipe(gulp.dest(config.tempPath));
});
gulp.task('merge-css', function() {
return gulp.src([config.tempPath + '/vendor.min.css', config.tempPath + '/app-specific.min.css'])
.on('error', notify.onError(function(error) {
return 'Error: ' + error.message;
})
)
.pipe(concat('app.min.css'))
.pipe(gulp.dest(config.public.cssPath));
});
gulp.task('build-css', function() {
return runSequence('vendor-css', 'app-css', 'merge-css');
});
gulp.task('watch', function() {
gulp.watch(config.appFiles.sass, ['build-css']);
gulp.watch(config.appFiles.js, ['build-js']);
});
gulp.task('clean', function(cb) {
del([
config.public.cssPath + '/*', config.public.jsPath + '/*',
config.public.fontPath + '/*', config.tempPath + '/',
config.sassCachePath + '/'
], cb
);
});
gulp.task('default', function() {
return runSequence(['clean', 'build-fonts', 'build-css', 'build-scripts']);
});