-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
141 lines (115 loc) · 4.14 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
'use strict';
/* GULP PLUGINS
========================================================================== */
var gulp = require('gulp'),
sass = require('gulp-sass'),
prefix = require('gulp-autoprefixer'),
rename = require('gulp-rename'),
livereload = require('gulp-livereload'),
postcss = require('gulp-postcss'),
cleanCSS = require('gulp-clean-css'),
changed = require('gulp-changed'),
sourcemaps = require('gulp-sourcemaps'),
shell = require('gulp-shell'),
clean = require('gulp-clean'),
webp = require('gulp-webp'),
imagemin = require('gulp-imagemin'),
gulpCopy = require('gulp-copy'),
requirejsOptimize = require('gulp-requirejs-optimize'),
rev = require('gulp-rev'),
revDel = require('rev-del'),
uncss = require('gulp-uncss'),
override = require('gulp-rev-css-url'),
runSequence = require('run-sequence');
/* CONFS
========================================================================== */
livereload({ start: true });
/* JEKYLL
========================================================================== */
//Start a jekyll server
gulp.task('jekyllStart', shell.task([
'jekyll serve --no-watch --limit_posts 1'
]));
//Build and compile Jekyll partials for development
gulp.task('jekyllBuild', shell.task([
'jekyll build --incremental'
]));
//Build the website for production
gulp.task('jekyllProd', shell.task([
'jekyll build --config _prod_config.yml'
]));
/* DEV TASKS
========================================================================== */
//Compile the Sass css, prefix the styles and create the sourceMap for the dev CSS
gulp.task('css', function() {
return gulp.src('_site/sass/main-sass.scss')
.pipe(sourcemaps.init())
.pipe(sass({ errLogToConsole:true }))
.pipe(prefix('last 15 version'))
.pipe(rename('main.css'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('_site/css'));
});
/* PROD TASKS
========================================================================== */
//Minify the dev CSS for production
gulp.task('minifyCSS', function () {
return gulp.src('_site/sass/main-sass.scss')
.pipe(sass({ errLogToConsole:true }))
.pipe(prefix('last 15 version'))
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(rename('main.css'))
.pipe(gulp.dest('build/css'));
});
//Use RequireJS to concatenate the js assets for production
gulp.task('scripts', function () {
return gulp.src('dev/js/main.js')
.pipe(requirejsOptimize(function(file) {
return {
name: 'main',
mainConfigFile: 'dev/js/main.js',
optimize: 'uglify2',
useStrict: true,
baseUrl: 'dev/js',
//include: ['lib/require.js'] /* If the site uses requireJS external links manager */
include: ['lib/almond.js'] /* If the site don't use any external links manager, we use almond.js for building */
};
}))
.pipe(gulp.dest('assets/js'));
});
//Minify the images
gulp.task('imageMin', function () {
return gulp.src('_site/img/**/*')
.pipe(changed('dev/img-min'))
.pipe(imagemin({
optimizationLevel : 7
// use: [pngcrush()]
}))
.pipe(gulp.dest('build/img-min'));
});
//Clean the assets folder which will receive the rev'ed assets
gulp.task('clean', function () {
return gulp.src('assets', {read: false})
.pipe(clean());
});
/* DEV TASKS
========================================================================== */
//Creates a livereload Server and build static assets on the fly.
gulp.task('default', function() {
//Star the liveReload Server
livereload({ start: true });
//Start the jekyllServer
gulp.start('jekyllStart');
//When a HTML Jekyll partial change, build the templates again
gulp.watch(['**/*.html', '!_site/**/*.html'], ['jekyllBuild']);
//When a SASS file change, build the CSS
gulp.watch('_site/sass/**/*.*', ['css']);
//When any CSS, HMTL, or JS files change, reload the browser
gulp.watch(['_site/css/main.css', '_site/**/*.html', '_site/js/**/*.js']).on('change', function(file) {
livereload.changed(file.path);
});
});
//Build the complete site inside the "build" folder
gulp.task('build', function() {
runSequence('minifyCSS', 'imageMin', 'jekyllProd');
});