-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
123 lines (106 loc) · 2.67 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
'use strict';
var exec = require('child_process').exec;
var gulp = require('gulp');
var merge = require('merge-stream');
var minify = require('gulp-minify');
var htmlmin = require('gulp-htmlmin');
var minifyCSS = require('gulp-minify-css');
var flatten = require('gulp-flatten');
var plugins = require('gulp-load-plugins')({
lazy: false
});
var connect = require('gulp-connect');
var replace = require('gulp-replace');
var version = require('./package.json').version;
// Remove files and folders
gulp.task('clean', function() {
return gulp.src([
'./dist'
], {
read: false
})
.pipe(plugins.rimraf());
});
// Copy the static files
gulp.task('copy', function() {
var images = gulp.src([
'./src/**/*.{svg,png,jpg,gif}'
])
.pipe(flatten())
.pipe(gulp.dest('./dist/img'));
var fonts = gulp.src([
'./src/font/*'
])
.pipe(gulp.dest('./dist/font'));
var favicon = gulp.src('./src/favicon.ico')
.pipe(gulp.dest('./dist'));
return merge(images, fonts, favicon);
});
// Replaces the usemin blocks by concatenation files
gulp.task('usemin', function() {
return gulp.src('./src/en.html')
.pipe(plugins.usemin())
.pipe(gulp.dest('./dist'));
});
// minify/uglify js, html and css files
gulp.task('uglify', ['usemin'], function() {
var js = gulp.src('./dist/script.js')
.pipe(minify({
ext: {
src: '-debug.js',
min: '.js'
},
ignoreFiles: ['.min.js']
}))
.pipe(gulp.dest('./dist'));
var html = gulp.src('./dist/index.html')
.pipe(htmlmin({
removeComments: true,
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true
}))
.pipe(gulp.dest('./dist'));
var css = gulp.src('./dist/app.css')
.pipe(minifyCSS())
.pipe(gulp.dest('./dist'));
return merge(js, html, css);
});
// Get a clean dist folder
gulp.task('build', ['uglify', 'copy'], function() {
return gulp.src([
'./dist/app-debug.js'
], {
read: false
})
.pipe(plugins.rimraf());
});
// Watch for changes in order to re-run the build
gulp.task('watch', function() {
gulp.watch(['./src/**/*'], ['build']);
});
// Serve the built project in a web server
gulp.task('connect', function() {
connect.server({
root: 'dist',
port: 14613,
livereload: false,
https: true
});
});
gulp.task('serve', [
'build',
'connect',
'watch'
]);
gulp.task('default', ['serve'], function() {
console.log('Go to https://localhost:14613 to view your app !');
});
gulp.task('deploy', ['build'], function(cb) {
var cmd = 'scp -r dist/* galionwebsite:/data/www/galion-landing/';
exec(cmd, function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});