forked from IdenGit/LPDevplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
130 lines (115 loc) · 3.86 KB
/
Copy pathgulpfile.js
File metadata and controls
130 lines (115 loc) · 3.86 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
/************************************************
INCLUDE PLUGINS
************************************************/
var gulp = require('gulp');
var sass = require('gulp-sass');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var streamify = require('gulp-streamify');
var minifycss = require('gulp-cssmin');
var notify = require('gulp-notify');
var autoprefix = require('gulp-autoprefixer');
var connect = require('gulp-connect-php');
var rename = require('gulp-rename');
var browserSync = require('browser-sync');
var critical = require('critical');
var reload = browserSync.reload;
/************************************************
PATH VARIABLES
************************************************/
var phpSrc = './build/**/*.php';
var phpIni = 'C:/MAMP/bin/php/php5.6.8/php.exe';
var phpExe = 'C:/MAMP/conf/php5.6.8/php.ini';
var stylesSrc = './src/scss/**/*.scss';
var stylesDest = './build/css';
var scriptsSrc = './src/js/index';
var scriptsDest = './build/js';
var scriptsWatch = './src/js/**/*.js';
var susy = 'C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/susy-2.2.7/sass';
/************************************************
SCSS(libsass) & CSS
************************************************/
gulp.task('styles', function() {
gulp.src(stylesSrc)
.pipe(sass({
includePaths: [
susy //required for sass
],
errLogToConsole: true,
sourceComments: 'map',
sourceMap: 'scss'
}))
.pipe(autoprefix("last 15 version"))
.pipe(minifycss())
.pipe(concat('styles.min.css'))
.pipe(gulp.dest(stylesDest))
.pipe(reload({stream: true}))
.pipe(notify('Styles compiled!'));
});
/************************************************
JS
************************************************/
gulp.task('scripts', function() {
return browserify(scriptsSrc, { debug: true })
.bundle().on('error', handleError)
.pipe(source('bundle.js'))
.pipe(streamify(uglify()))
.pipe(rename('scripts.min.js'))
.pipe(gulp.dest(scriptsDest))
.pipe(notify('Scripts compiled!'));
});
// create a task that ensures the `js` task is complete before
// reloading browsers
gulp.task('js-watch', ['scripts'], browserSync.reload);
/************************************************
PHP SERVER
************************************************/
gulp.task('server', function() {
connect.server({
bin: phpIni,
ini: phpExe,
base: './build'
}, function (){
browserSync({
proxy: 'localhost:8000'
});
//Watch
gulp.watch(stylesSrc, ['styles']);
gulp.watch(phpSrc).on('change', reload);
gulp.watch(scriptsWatch, ['js-watch']);
});
});
/************************************************
Error handler
************************************************/
function handleError(err) {
console.log(err.toString());
this.emit('end');
}
/************************************************
DEFAULT
************************************************/
gulp.task('default', ['server', 'styles', 'scripts']);
/************************************************
Critical CSS
************************************************/
gulp.task('copystyles', function () {
return gulp.src(['build/css/styles.min.css'])
.pipe(rename({
basename: "site" // site.css
}))
.pipe(gulp.dest('build/css/'));
});
gulp.task('critical', ['copystyles'], function () {
critical.generateInline({
base: 'build/',
src: 'index.php',
styleTarget: 'css/styles.min.css',
htmlTarget: 'index.php',
width: 960,
height: 780,
minify: true
});
});