-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
88 lines (77 loc) · 2.35 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
'use strict';
var gulp = require('gulp'),
debug = require('gulp-debug'),
gulpif = require('gulp-if'),
cache = require('gulp-cached'),
watch = require('gulp-watch'),
less = require('gulp-less'),
minifycss = require('gulp-minify-css'),
autoprefixer = require('gulp-autoprefixer'),
sourcemaps = require('gulp-sourcemaps'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify'),
clean = require('gulp-rimraf'),
sequence = require('gulp-sequence'),
php = require('gulp-connect-php'),
util = require('gulp-util'),
browserSync = require('browser-sync'),
reload = browserSync.reload,
args = require('yargs').argv,
pack = args.pack || false;
pack = (pack ? true : false);
var build_path = 'build';
gulp.task('php', function() {
php.server({ base: '.', port: 8010, keepalive: true});
});
gulp.task('webserver', ['php'], function () {
browserSync({
startPath: 'demo/index.html',
proxy: '127.0.0.1:8010',
port: 8080,
open: true,
notify: false
});
});
gulp.task('clean', function() {
return gulp.src([build_path + '/*'], { read: false }).pipe(clean({ force: true }));
});
gulp.task('less', function() {
return gulp.src(['src/**/*.less'])
.pipe(cache('cacheless'))
.pipe(debug())
.pipe(less())
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(gulp.dest('src'))
});
gulp.task('styles', function() {
return gulp.src(['src/**/*.css', '!src/**/*.min.css'])
.pipe(cache('cachestyles'))
.pipe(debug())
.pipe(gulpif(pack, minifycss()))
.pipe(rename(function (path) { path.basename += ".min"; }))
.pipe(gulp.dest('src'))
.pipe(gulp.dest(build_path))
.pipe(reload({stream: true})); // inject styles
});
gulp.task('scripts', function() {
return gulp.src(['src/**/*.js', '!src/**/*.min.js'])
.pipe(cache('cachescripts'))
.pipe(debug())
.pipe(gulpif(pack, uglify().on('error', util.log)))
.pipe(rename(function (path) { path.basename += ".min"; }))
.pipe(gulp.dest('src'))
.pipe(gulp.dest(build_path))
.pipe(reload({stream: true})); // inject scripts
});
gulp.task('watch', function() {
gulp.watch(['src/**/*.less'], ['less']);
gulp.watch(['src/**/*.css', '!src/**/*.min.css'], ['styles']);
gulp.watch(['src/**/*.js', '!src/**/*.min.js'], ['scripts']);
});
gulp.task('build', sequence(
'clean',
'less',
'styles',
'scripts'
));
gulp.task('default', sequence('build', 'webserver', 'watch'));