-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
93 lines (80 loc) · 2.64 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
// FIXME [awe] more dynamic dependencies (Scout JS core, jQuery) -> check bower / npm?
var gulp = require('gulp');
var concat = require('gulp-concat');
var sourcemaps = require('gulp-sourcemaps');
var less = require('gulp-less');
var insert = require('gulp-insert');
var clean = require('gulp-clean');
var browserSync = require('browser-sync').create();
gulp.task('serve', ['build-js', 'concat-css', 'watch'], function () {
browserSync.init({
server: {
baseDir: "./"
}
});
});
gulp.task('reload', function(done) {
browserSync.reload();
});
/**
* Checks for file-changes and then triggers one more tasks. In the end
* we always trigger the reload task so browser sync can reload the browser
* page.
*/
gulp.task('watch', function() {
gulp.watch('*.html', ['reload']);
gulp.watch('src/**/*.less', ['concat-css', 'reload']);
gulp.watch('src/**/*.js', ['build-js', 'reload']);
});
/**
* This is the default task which is run when someone simply types 'gulp'
* in the project directory. Other tasks can be executed directly with
* 'gulp [task-name]'.
*/
gulp.task('default', function() {
gulp.start('serve');
});
// ### JavaScript ### //
gulp.task('build-js', function() {
return gulp.src('src/**/*.js')
.pipe(concat('videogames.js'))
// Add IIFE (Immediately-Invoked Function Expression)
.pipe(insert.wrap('(function(videogames, $, undefined) {\n', '\n}(window.videogames = window.videogames || {}, jQuery));'))
.pipe(gulp.dest('build/js'));
});
gulp.task('minify-js', function() {
// FIXME [awe] check why file gets so huge with sourcemaps
return gulp.src('build/js/videogames.js')
.pipe(rename({suffix: '.min'}))
// .pipe(sourcemaps.init())
.pipe(uglify())
// .pipe(sourcemaps.write())
.pipe(gulp.dest('build/js'));
});
// ### CSS ### //
gulp.task('clean-css', function(done) {
return gulp.src('build/css/**/*.css')
.pipe(clean());
});
// creates a single CSS file for each LESS file
gulp.task('build-less', ['clean-css'], function(done) {
return gulp.src('src/**/*.less')
.pipe(less({
paths: ['src']
}))
.pipe(gulp.dest('build/css'));
});
// takes all the single css files and concats them to a single eclipse-scout.css
gulp.task('concat-css', ['build-less'], function(done) {
return gulp.src('build/**/*.css')
.pipe(concat('videogames.css'))
.pipe(gulp.dest('build/css'));
});
gulp.task('minify-css', ['concat.css'], function(done) {
return gulp.src('build/css/videogames.css')
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.init())
.pipe(cleanCSS())
.pipe(sourcemaps.write())
.pipe(gulp.dest('build/css'));
});