forked from sanographix/rin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
80 lines (66 loc) · 2.1 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
var gulp = require('gulp');
var sass = require('gulp-sass');
var pleeease = require('gulp-pleeease');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var ejs = require("gulp-ejs");
var plumber = require("gulp-plumber");
// Sass
gulp.task('sass', function () {
gulp.src('sass/**/*.scss')
.pipe(sass({errLogToConsole: true})) // Keep running gulp even though occurred compile error
.pipe(pleeease({
autoprefixer: {
browsers: ['last 2 versions']
}
}))
.pipe(gulp.dest('build/css'))
.pipe(reload({stream:true}));
});
// Js-concat-uglify
gulp.task('js', function() {
gulp.src(['js/*.js'])
.pipe(concat('scripts.js'))
.pipe(uglify({preserveComments: 'some'})) // Keep some comments
.pipe(gulp.dest('build/js'))
.pipe(reload({stream:true}));
});
// Imagemin
gulp.task('imagemin', function() {
gulp.src(['images/**/*.{png,jpg,gif,svg}'])
.pipe(imagemin({optimizationLevel: 7}))
.pipe(gulp.dest('build/images'));
});
// ejs
var fs = require('fs');
var json = JSON.parse(fs.readFileSync("site.json")); // parse json
gulp.task("ejs", function() {
gulp.src(['templates/*.ejs','!' + 'templates/_*.ejs']) // Don't build html which starts from underline
.pipe(plumber())
.pipe(ejs(json))
.pipe(gulp.dest('./'))
});
// Static server
gulp.task('browser-sync', function() {
browserSync({
server: {
baseDir: "./", // Target directory
index : "index.html" // index file
}
});
});
// Reload all browsers
gulp.task('bs-reload', function () {
browserSync.reload();
});
// Task for `gulp` command
gulp.task('default',['browser-sync'], function() {
gulp.watch('sass/**/*.scss',['sass']);
gulp.watch('js/*.js',['js']);
gulp.watch('images/**/*.{png,jpg,gif,svg}',['imagemin']);
gulp.watch("./*.html", ['bs-reload']);
gulp.watch(['templates/*.ejs', 'site.json'], ['ejs']);
});