forked from contao-association/contao.camp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
68 lines (59 loc) · 2.21 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
'use strict';
const browserify = require('browserify');
const gulp = require('gulp');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const gutil = require('gulp-util');
const uglify = require('gulp-uglify');
const sourcemaps = require('gulp-sourcemaps');
const rename = require('gulp-rename');
const sass = require('gulp-sass');
const cleanCSS = require('gulp-clean-css');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const concat = require('gulp-concat');
const svgo = require('gulp-svgo');
const production = !!gutil.env.prod;
// Build app.js
gulp.task('scripts', function () {
return browserify({
entries: 'web/layout/scripts/app.js',
debug: !production
})
.bundle()
.pipe(source('web/layout/scripts/app.js'))
.pipe(buffer())
.pipe(production ? uglify() : gutil.noop())
.pipe(rename('app.js'))
.on('error', gutil.log)
.pipe(production ? sourcemaps.write() : gutil.noop())
.pipe(gulp.dest('web/layout'));
});
// Build bundle.css
gulp.task('styles', function () {
return gulp.src('web/layout/styles/app.scss')
.pipe(production ? sourcemaps.init() : gutil.noop())
.pipe(sass())
.pipe(postcss([autoprefixer({browsers: ['> 5%']})]))
.pipe(production ? sourcemaps.write() : gutil.noop())
.pipe(production ? cleanCSS() : gutil.noop())
.pipe(gulp.dest('web/layout'));
});
// Run SVG optimization
gulp.task('svgo', function () {
return gulp.src('web/layout/images/*')
.pipe(svgo())
.pipe(gulp.dest('web/layout/images'));
});
// Watch task
gulp.task('watch', function () {
gulp.watch(['web/layout/images/*.svg', 'web/layout/images/**/*.svg'], ['svgo']);
gulp.watch(['web/layout/scripts/*.js', 'web/layout/scripts/**/*.js'], ['scripts']);
gulp.watch(['web/layout/styles/*.scss', 'web/layout/styles/**/*.scss'], ['styles']);
});
// Build by default
gulp.task('default', ['build']);
// Build task
gulp.task('build', ['svgo', 'scripts', 'styles']);
// Build and watch task
gulp.task('build:watch', ['build', 'watch']);