forked from selbekk/smashnorge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
113 lines (95 loc) · 2.88 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
var gulp = require('gulp');
// Now the rest of the dependencies
var uglify = require('gulp-uglify');
var minifyCss = require('gulp-minify-css');
var del = require('del');
var concat = require('gulp-concat');
var jshint = require('gulp-jshint');
var plumber = require('gulp-plumber');
var cssPrefixed = require('gulp-autoprefixer');
var server = require('gulp-server-livereload');
var wiredep = require('wiredep').stream;
var changed = require('gulp-changed');
var fs = require('fs');
// Clean build folder
gulp.task('clean:img', function (cb) {
del(['dist/img/content/*', 'dist/img/*'], cb);
});
gulp.task('clean:html', function (cb) {
del(['dist/*.html'], cb);
});
gulp.task('clean:js', function (cb) {
del(['dist/*.js'], cb);
});
gulp.task('clean:css', function (cb) {
del(['dist/*.css'], cb);
});
// Handle frontend JS build
gulp.task('script', function () {
return gulp.src('js/*.js')
.pipe(plumber())
.pipe(jshint())
.pipe(uglify())
.pipe(concat('scripts.min.js'))
.pipe(gulp.dest('dist/assets/'));
});
// Handle CSS build
gulp.task('style', function () {
return gulp.src('css/*.css')
.pipe(plumber())
.pipe(cssPrefixed({browsers: ['last 2 versions'], cascade: false}))
.pipe(minifyCss())
.pipe(concat('styles.min.css'))
.pipe(gulp.dest('dist/assets/'));
});
// Wire in bower dependencies
gulp.task('bower:wire', function () {
gulp.src('*.html')
.pipe(wiredep({
// todo: prepend a / to path
}))
.pipe(gulp.dest('dist'));
});
gulp.task('bower:copy', function () {
gulp.src('bower_components/**')
.pipe(changed('dist/bower_components'))
.pipe(gulp.dest('dist/bower_components'));
});
gulp.task('images', function () {
gulp.src('img/**')
.pipe(changed('dist/img'))
.pipe(gulp.dest('dist/img'));
});
// Development server @ localhost:8000
gulp.task('server', function () {
gulp.src('dist')
.pipe(server({
livereload: false,
open: true,
log: 'debug'
}));
});
// Prompt
gulp.task('prompt', function () {
return fs.readFile('prompt.txt', 'utf8', function (err, data) {
if (err) {
throw err;
}
console.log(data);
});
});
// Watch for updates in files to recompile assets
gulp.task('watch', function () {
gulp.watch('js/*.js', ['script']);
gulp.watch('css/*.css', ['style']);
gulp.watch('bower.json', ['bower']);
gulp.watch('*.html', ['bower:wire']);
gulp.watch('bower.json', ['bower:copy']);
});
gulp.task('bower', ['bower:wire', 'bower:copy']);
gulp.task('clean', ['clean:html', 'clean:js', 'clean:css']);
gulp.task('build', ['clean', 'script', 'style', 'bower', 'images']);
gulp.task('serve', ['build', 'watch', 'server']);
gulp.task('default', ['build']);
/* 5up3r s3cr37 34573r366 */
gulp.task('smash', ['prompt', 'serve']);