-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
76 lines (65 loc) · 2.51 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
var gulp = require('gulp'),
sass = require('gulp-sass'),
args = require('yargs').argv,
shell = require('gulp-shell'),
size = require('gulp-size'),
gulpif = require('gulp-if'),
sourcemaps = require('gulp-sourcemaps'),
uncss = require('gulp-uncss'),
cssnano = require('gulp-cssnano'),
browserSync = require('browser-sync').create(),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
rimraf = require('rimraf');
var DIR = {},
env = args.prod ? 'prod' : 'dev';
DIR.src = 'source';
DIR.dest = 'public_'+env;
DIR.fontsSrc = DIR.src+'/fonts';
DIR.fontsDest = DIR.dest+'/fonts';
DIR.sassSrc = DIR.src+'/_sass/';
DIR.cssDest = DIR.dest+'/css';
DIR.jsSrc = DIR.src+'/js';
DIR.jsDest = DIR.dest+'/js';
gulp.task('default', ['build', 'watch']);
gulp.task('build', ['build-page', 'build-css', 'build-fonts'], function () {
process.exit(0);
});
gulp.task('clean', function (cb) {
rimraf('public_dev', cb);
});
gulp.task('watch', function () {
browserSync.init({server: {baseDir: 'public_'+env}});
gulp.watch(DIR.sassSrc+'/**/*.scss', ['build-css']);
gulp.watch(DIR.imgSrc+'/**/*.{jpg,jpeg,png,gif,svg}', ['build-img']);
gulp.watch([DIR.src+'/**/*.{html,html.twig,md}', DIR.fontsSrc+'/*', DIR.imgSrc+'/**'], ['watch-page']);
});
// This task is required as a hack to reload the browser AFTER Sculpin is finished building the page
gulp.task('watch-page', ['build-page'], browserSync.reload);
// Compiles SCSS into CSS, minifies it and moves it into correct directory.
gulp.task('build-css', function () {
return gulp
.src(DIR.sassSrc+'/**/*.scss')
.pipe(gulpif(env === 'dev', sourcemaps.init()))
.pipe(sass())
.pipe(gulpif(env === 'prod', uncss({
html: [DIR.dest+'/**/*.html'],
ignore: [/\hljs-[A-Za-z0-9-]+/, '.hljs']
})))
.pipe(gulpif(env === 'prod', cssnano()))
.pipe(gulpif(env === 'dev', sourcemaps.write()))
.pipe(gulp.dest(DIR.cssDest))
.pipe(browserSync.stream())
.pipe(size({title: 'CSS'}));
});
gulp.task('build-fonts', function () {
return gulp
.src(DIR.fontsSrc+'/**/*.{eot,svg,ttf,woff,woff2}')
.pipe(gulp.dest(DIR.fontsDest))
.pipe(size({title: 'Fonts'}));
});
// Runs Sculpin to build the page
gulp.task('build-page', function () {
return gulp.src('')
.pipe(shell(['./vendor/bin/sculpin generate --env='+env], {quiet: true}));
});