-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
107 lines (95 loc) · 3.18 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
"use strict";
const gulp = require('gulp'),
gulpsync = require('gulp-sync')(gulp),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
concat = require('gulp-concat'),
webpack = require('webpack-stream'),
webpack2 = require('webpack'),
uglify = require('gulp-uglify'),
babel = require('gulp-babel'),
imagemin = require('gulp-imagemin'),
argv = require('yargs').argv,
del = require('del'),
gulpif = require('gulp-if'),
replace = require('gulp-replace');
let src = './assets',
dist = './target/classes/static',
vendorFiles = [src + '/js/third-party/tether.js',
src + '/js/third-party/bootstrap.js',
src + '/js/third-party/selectize.js',
src + '/js/app.js'];
//You will need this in webpack-config, too.
var isProduction = argv.production;
global.IsProduction = isProduction;
// Optimize the imgs, cache stuff that already ran through imagemin
gulp.task('images', function() {
return gulp.src(src + '/img/**/*')
.pipe(
imagemin([
imagemin.gifsicle(),
imagemin.jpegtran({progressive: true}),
imagemin.optipng(),
imagemin.svgo()
]))
.pipe(gulp.dest(dist + '/img'))
});
// Clean the dist folder
gulp.task('clean', function() {
return del(dist).then(paths => {
console.log('Deleted '+ dist +' files and folders:\n', paths.join('\n'));
});
});
// Compile the SCSS files, run autoprefixer and compress the resulted CSS's
gulp.task('css', function() {
var replaceStr = 'url(/assets/';
if (argv.buildno)
{
replaceStr = 'url(/' + argv.buildno + '/assets/';
console.log('Current buildno is : ' + argv.buildno);
}
return gulp.src(src + '/scss/**/*.scss')
.pipe(replace('url(/assets/', replaceStr))
.pipe(
sass({
includePaths: [src + '/scss'],
outputStyle: 'compressed',
errLogToConsole: true
}))
.pipe(
autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(gulp.dest(dist + '/css/'))
});
/*
Concatenate vendors JS's and app.js.
Use specific order to avoid missing dependencies.
Dependencies tasks are called synchronous.
*/
gulp.task('js-concatenate', function() {
//gulp.start('js', function() {
//});
return gulp.src(vendorFiles)
.pipe(concat('app.js'))
.pipe(uglify({preserveComments: 'license'}))
.pipe(gulp.dest(dist + '/js/'));
});
// Uglify the JS's
gulp.task('js', function () {
var toReturn = gulp.src([ src + '/js/**/*.js',
'!' + src + '/js/third-party/**/*.js']);
return JSTask(toReturn, dist + '/js/');
});
function JSTask(aGulpSRC, aDestinationFolder) {
return aGulpSRC.pipe(babel({
presets: ['es2015']
}))
.pipe(uglify({preserveComments: 'license'}).on('error', function (e) {
console.log(e);
}))
.pipe(gulp.dest(aDestinationFolder));
}
gulp.task('default', ['css', 'js-concatenate', 'images']);
//gulp.task('default', ['clean']);