-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
139 lines (129 loc) · 3.43 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* Project Setup
*
* Setting up variables for project name and directories
*/
// Project configuration
var url = '',// Development URL. Example: julep.dev
source = './assets/', // Public assets
adminSource = './admin/assets/'; // Admin assets
// Load plugins
var autoprefixer = require('gulp-autoprefixer'),
browserSync = require('browser-sync'),
browserify = require('browserify'),
concat = require('gulp-concat'),
filter = require('gulp-filter'),
gulp = require('gulp'),
minifycss = require('gulp-uglifycss'),
notify = require('gulp-notify'),
plugins = require('gulp-load-plugins')({camelize: true}),
plumber = require('gulp-plumber'),
reload = browserSync.reload,
rename = require('gulp-rename'),
sass = require('gulp-scss'),
sourcemaps = require('gulp-sourcemaps'),
sourcestream = require('vinyl-source-stream'),
streamify = require('gulp-streamify'),
uglify = require('gulp-uglify');
/**
* Browser Sync
*/
gulp.task('browser-sync', function () {
var files = [
'**/*.php',
'**/*.{png,jpg,gif}'
];
browserSync.init(files, {
proxy: url
});
});
/**
* Styles
*/
gulp.task('styles', function () {
return gulp.src([source + 'scss/**/*.scss'])
.pipe(plumber({
errorHandler: function (err) {
console.log(err);
this.emit('end');
}
}))
.pipe(sourcemaps.init())
.pipe(sass({
errLogToConsole: true,
outputStyle : 'nested',
precision : 10
}))
.pipe(sourcemaps.write({includeContent: false}))
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(sourcemaps.write('.'))
.pipe(plumber.stop())
.pipe(gulp.dest(source + 'css'))
.pipe(filter('**/*.css'))
.pipe(reload({stream: true}))
.pipe(rename({suffix: '-min'}))
.pipe(minifycss({
maxLineLen: 80
}))
.pipe(gulp.dest(source + 'css'))
.pipe(reload({stream: true}))
});
/**
* Admin styles
*/
gulp.task('adminStyles', function () {
return gulp.src([adminSource + 'scss/**/*.scss'])
.pipe(plumber({
errorHandler: function (err) {
console.log(err);
this.emit('end');
}
}))
.pipe(sass({
errLogToConsole: true,
outputStyle : 'nested',
precision : 10
}))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(plumber.stop())
.pipe(gulp.dest(adminSource + 'css'))
.pipe(filter('**/*.css'))
.pipe(rename({suffix: '-min'}))
.pipe(minifycss({
maxLineLen: 80
}))
.pipe(gulp.dest(adminSource + 'css'))
});
/**
* Scripts
*
* Concatenate scripts
*/
gulp.task('js', function () {
return browserify(source + 'js/app/app')
.bundle()
.pipe(sourcestream('development.js'))
.pipe(gulp.dest(source + 'js/'))
.pipe(rename({
basename: "production",
suffix : '-min'
}))
.pipe(streamify(uglify()))
.pipe(gulp.dest(source + 'js/'))
});
// ==== TASKS ==== //
/**
* Gulp Default Task
*
* Compiles styles, fires-up browser sync, watches js and php files. Note browser sync task watches php files
*
*/
// Watch Task
gulp.task('default', ['styles', 'adminStyles', 'js', 'browser-sync'], function () {
gulp.watch('scss/**/*.scss', {cwd: source}, ['styles']);
gulp.watch('scss/**/*.scss', {cwd: adminSource}, ['adminStyles']);
gulp.watch('js/app/*.js', {cwd: source}, ['js', browserSync.reload]);
gulp.watch('js/app/**/*.js', {cwd: source}, ['js', browserSync.reload]);
gulp.watch('js/inc/*.js', {cwd: source}, ['js', browserSync.reload]);
});