-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
87 lines (75 loc) · 2.24 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
/* jshint strict: false */
'use strict';
var args = require('yargs').argv;
var del = require('del');
var gulp = require('gulp');
var browserSync = require("browser-sync").create();
var $ = require('gulp-load-plugins')({ camelize:true });
var config = require('./gulpconfig.js');
var isProduction = /prod/i.test(args.env);
// Start BrowserSync
gulp.task('browser-sync', function() {
browserSync.init({
proxy: {
target: "http://dev.m12.io:3030"
},
port: 3030
});
});
gulp.task('styles', function() {
gulp.src(config.source.styles)
.pipe($.plumber())
.pipe($.sourcemaps.init({loadMaps: true}))
.pipe($.sass({
includePaths: config.source.includePaths,
imagePath: config.dest.images,
errLogToConsole: true
}))
.pipe($.autoprefixer('last 3 version'))
.pipe($.if(true === isProduction, $.csso())) // only minify/compress on Production
.pipe($.if(false === isProduction, $.sourcemaps.write())) // only generate .map files on non-production env
.pipe(gulp.dest(config.dest.styles))
.pipe($.size({ showFiles:true }))
.pipe($.size({ gzip:true }))
;
});
gulp.task('scripts', function() {
var scripts = config.source.vendorScripts.concat(config.source.scripts);
return gulp.src(scripts)
.pipe($.if(isProduction,
$.uglify({ mangle: false }) // only minify/uglify on Production
))
.pipe($.concat('App.js'))
.pipe(gulp.dest(config.dest.scripts))
.pipe($.size({ showFiles:true }))
.pipe($.size({ gzip:true }))
;
});
gulp.task('scripts-hinting', function() {
return gulp.src(config.source.scripts)
.pipe($.jshint('.jshintrc'))
.pipe($.jshint.reporter('jshint-stylish'));
});
gulp.task('assets', function() {
del.sync(config.clear, {force:true});
return gulp.src(config.source.fonts)
.pipe(gulp.dest(config.dest.fonts))
;
});
gulp.task('build', [
'assets',
'styles',
'scripts-hinting',
'scripts'
]);
// Watch
gulp.task('watch', ['build', 'browser-sync'], function () {
// Watch .scss files
gulp.watch(config.watch.styles, ['styles']).on('change', browserSync.reload);
// Watch .js files
gulp.watch(config.watch.scripts, ['scripts-hinting', 'scripts']).on('change', browserSync.reload);
// Watch PHP code
gulp.watch(config.watch.php).on('change', browserSync.reload);
});
// Default Task
gulp.task('default', ['build']);