-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
110 lines (91 loc) · 2.75 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
var changed = require('gulp-changed');
var gulp = require('gulp');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var browserSync = require('browser-sync').create();
var notify = require('gulp-notify');
var prefix = require('gulp-autoprefixer');
var minifycss = require('gulp-clean-css');
var uglify = require('gulp-uglify');
var cache = require('gulp-cache');
var concat = require('gulp-concat');
var util = require('gulp-util');
var header = require('gulp-header');
var pixrem = require('gulp-pixrem');
var exec = require('child_process').exec;
// Files
var styles = 'assets/css/src/styles.scss';
var js = 'assets/js/src/*.js';
var php = '**/*.php';
// Errors
var handleError = function(task) {
return function(err) {
notify.onError({
message: task + ' failed, check the logs..'
})(err);
util.log(util.colors.bgRed(task + ' error:'), util.colors.red(err));
};
};
// Sync
gulp.task('browsersync', function() {
var files = [
php,
js
];
browserSync.init(files, {
proxy: "ifup.dev",
browser: "Google Chrome",
notify: true
});
});
// Styles
gulp.task('styles', function() {
gulp.src(styles)
.pipe(sass({
compass: false,
bundleExec: true,
sourcemap: false,
style: 'compressed',
debugInfo: true,
lineNumbers: true,
errLogToConsole: true,
includePaths: [
'node_modules/',
// 'bower_components/',
// require('node-bourbon').includePaths
],
}))
.on('error', handleError('styles'))
.pipe(prefix('last 3 version', 'safari 5', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(pixrem())
.pipe(minifycss({
advanced: true,
keepBreaks: false,
keepSpecialComments: 0,
mediaMerging: true,
sourceMap: true
}))
.pipe(gulp.dest('./assets/css/'))
.pipe(browserSync.stream());
});
// Scripts
var currentDate = util.date(new Date(), 'dd-mm-yyyy HH:ss');
var pkg = require('./package.json');
var banner = '/*! <%= pkg.name %> <%= currentDate %> - <%= pkg.author %> */\n';
gulp.task('js', function() {
gulp.src(
[
'node_modules/jquery/dist/jquery.js',
'assets/js/src/scripts.js'
])
.pipe(concat('global.js'))
.pipe(uglify({preserveComments: false, compress: true, mangle: true}).on('error',function(e){console.log('\x07',e.message);return this.end();}))
.pipe(header(banner, {pkg: pkg, currentDate: currentDate}))
.pipe(gulp.dest('./assets/js/'));
});
// Watch
gulp.task('js-watch', ['js'], browserSync.reload);
gulp.task('watch', ['browsersync'], function() {
gulp.watch(styles, ['styles']);
gulp.watch(js, ['js-watch']);
});