-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
118 lines (104 loc) · 3.85 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
// =============================================
// BASIC GULPFILE
// - - - - - - - - - - - - - - - - - - - - - - -
// This file processes all of the assets in the "src" folder
// and outputs the finished files in the "dist" folder.
// You can also optimize images.
// Delpoy your Website via Sublime Text SFTP!
// =============================================
// =============================================
// 1. LIBRARIES
// =============================================
var gulp = require('gulp'),
browserSync = require('browser-sync').create(),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
tinypng = require('gulp-tinypng-compress'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
plumber = require('gulp-plumber'),
jshint = require('gulp-jshint'),
del = require('del'),
notify = require('gulp-notify');
// =============================================
// 2. SETTINGS VARIABLES & OPTIONS
// =============================================
// Path for JS concat & minify
var config = {
scripts: [
// jQuery
'bower_components/jquery/dist/jquery.min.js',
// Bootstrap
'bower_components/bootstrap/js/dist/dropdown.js',
'bower_components/bootstrap/js/dist/collapse.js',
// Swiper
'bower_components/Swiper/dist/swiper.min.js',
// Lightgallery
'bower_components/lightgallery/dist/js/lightgallery.min.js',
// Default scripts
'src/js/**/*.js'
]
};
// =============================================
// 3. TASKS
// =============================================
// Cleans the dist directory & removes useless files
gulp.task('clean', function() {
del('dist/');
});
// SASS / CSS
gulp.task('sass', function() {
gulp.src('src/scss/master.scss') // file to handle
.pipe(plumber({ errorHandler: notify.onError('<%= error.message %>') })) // error notification to desktop
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError)) // error text in terminal
.pipe(autoprefixer({browsers: ['last 3 versions'], cascade: false }))
.pipe(gulp.dest('dist/css')) // output folder
.pipe(browserSync.stream()); // reload browse
});
// JS
gulp.task('js', function () {
gulp.src(config.scripts)
.pipe(plumber({ errorHandler: notify.onError('<%= error.message %>') }))
// Info: jshint deaktiviert, da error
// Info: jshint deaktiviert, da error
// Info: jshint deaktiviert, da error
//.pipe(jshint('.jshintrc'))
//.pipe(jshint.reporter('jshint-stylish'))
.pipe(uglify())
.pipe(concat('master.js'))
.pipe(gulp.dest('dist/js'))
.pipe(browserSync.stream());
});
// Images optimizing
gulp.task('tinypng', function () {
gulp.src('src/img/**/*.{png,jpg,jpeg}')
.pipe(tinypng({
key: 'WZc_k-S27nIN0pus-IW3jxFqSaQXENjR',
sigFile: 'src/img/.tinypng-sigs',
log: true
}))
.pipe(gulp.dest('dist/img'));
});
// Livereload
gulp.task('livereload', function() {
browserSync.init({
server: {
baseDir: './',
directory: true
}
});
});
// =============================================
// 4. SET THE DEV & PROD TASKS
// =============================================
// Run "gulp" for default Task
// Run "gulp img" for image optimizing
// Default
gulp.task('default', ['livereload', 'sass', 'js'], function () {
gulp.watch('src/scss/**/*.scss', ['sass']);
gulp.watch('src/js/**/*.js', ['js']);
gulp.watch('**/*.html').on('change', browserSync.reload);
});
// Optimizing Images
// tinypng.com - max 500 images per month for free
gulp.task('img', ['tinypng']);