-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGulpfile.js
88 lines (72 loc) · 2.13 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');
var coffee = require('gulp-coffee');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var browserSync = require('browser-sync');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var connect = require('gulp-connect-php');
var open = require('gulp-open');
var urlUtil = require('url');
var URL = 'http://' + 'localhost:8080';
var parsedUrl = urlUtil.parse(URL);
console.log(parsedUrl);
var hostname = parsedUrl.hostname;
var host = parsedUrl.host;
var port = parsedUrl.port || 80;
var paths = {
scripts: 'js/**/*.coffee',
images: 'images/**/*',
styles: 'sass/style.scss',
php: './**/*.php'
};
gulp.task('scripts', function() {
// Minify and copy all JavaScript (except vendor scripts)
// with sourcemaps all the way down
return gulp.src(paths.scripts)
.pipe(sourcemaps.init())
.pipe(coffee())
.pipe(uglify())
.pipe(concat('main.min.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('js'));
});
gulp.task('styles', function () {
gulp.src(paths.styles)
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer())
.pipe(gulp.dest('./'))
// .pipe(browserSync.stream());
});
gulp.task('serve', function() {
console.log(hostname);
connect.server({
port: parseInt(port) + 1,
hostname: hostname,
base: '../../../', // default for a wordpress install
open: false
}, function() {
browserSync({
host: hostname,
proxy: host,
port: port,
ghostMode: true,
});
});
});
gulp.task('reload-scripts', ['scripts'], browserSync.reload);
gulp.task('watch', function() {
gulp.watch(paths.styles, ['styles']);
gulp.watch(paths.scripts, ['reload-scripts']);
gulp.watch(paths.php).on('change', browserSync.reload);
});
gulp.task('watch:styles', function() {
gulp.watch(paths.styles, ['styles']);
});
gulp.task('watch:scripts', function() {
gulp.watch(paths.scripts, ['reload-scripts']);
});
// The default task (called when you run `gulp` from cli)
gulp.task('default', ['serve', 'scripts', 'styles', 'serve', 'watch']);