forked from Alecaddd/awps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
128 lines (110 loc) · 3.58 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
// Load Gulp...of course
var gulp = require( 'gulp' );
// CSS related plugins
var sass = require( 'gulp-sass' );
var autoprefixer = require( 'gulp-autoprefixer' );
var minifycss = require( 'gulp-uglifycss' );
// JS related plugins
var concat = require( 'gulp-concat' );
var uglify = require( 'gulp-uglify' );
var babelify = require( 'babelify' );
var browserify = require( 'browserify' );
var source = require( 'vinyl-source-stream' );
var buffer = require( 'vinyl-buffer' );
var stripDebug = require( 'gulp-strip-debug' );
// Utility plugins
var rename = require( 'gulp-rename' );
var sourcemaps = require( 'gulp-sourcemaps' );
var notify = require( 'gulp-notify' );
var plumber = require( 'gulp-plumber' );
var options = require( 'gulp-options' );
var gulpif = require( 'gulp-if' );
// Browers related plugins
var browserSync = require( 'browser-sync' ).create();
var reload = browserSync.reload;
// Project related variables
var projectURL = 'http://wp.dev';
var styleSRC = './src/scss/style.scss';
var styleAdminSRC = './src/scss/admin.scss';
var styleURL = './assets/css/';
var mapURL = './';
var jsSRC = './src/scripts/';
var jsFront = 'main.js';
var jsAdmin = 'admin.js';
var jsFiles = [ jsFront, jsAdmin ];
var jsURL = './assets/js/';
var imgSRC = './src/images/**/*';
var imgURL = './assets/images/';
var fontsSRC = './src/fonts/**/*';
var fontsURL = './assets/fonts/';
var styleWatch = './src/scss/**/*.scss';
var jsWatch = './src/scripts/**/*.js';
var imgWatch = './src/images/**/*.*';
var fontsWatch = './src/fonts/**/*.*';
var phpWatch = './**/*.php';
// Tasks
gulp.task( 'browser-sync', function() {
browserSync.init({
proxy: projectURL,
injectChanges: true,
open: false
});
});
gulp.task( 'styles', function() {
gulp.src( [ styleSRC, styleAdminSRC ] )
.pipe( sourcemaps.init() )
.pipe( sass({
errLogToConsole: true,
outputStyle: 'compressed'
}) )
.on( 'error', console.error.bind( console ) )
.pipe( autoprefixer({ browsers: [ 'last 2 versions', '> 5%', 'Firefox ESR' ] }) )
.pipe( rename( { suffix: '.min' } ) )
.pipe( sourcemaps.write( mapURL ) )
.pipe( gulp.dest( styleURL ) )
.pipe( browserSync.stream() );
});
gulp.task( 'js', function() {
jsFiles.map( function( entry ) {
return browserify({
entries: [jsSRC + entry]
})
.transform( babelify, { presets: [ 'es2015' ] } )
.bundle()
.pipe( source( entry ) )
.pipe( rename( {
extname: '.min.js'
} ) )
.pipe( buffer() )
.pipe( gulpif( options.has( 'production' ), stripDebug() ) )
.pipe( sourcemaps.init({ loadMaps: true }) )
.pipe( uglify() )
.pipe( sourcemaps.write( '.' ) )
.pipe( gulp.dest( jsURL ) )
.pipe( browserSync.stream() );
});
});
gulp.task( 'images', function() {
triggerPlumber( imgSRC, imgURL );
});
gulp.task( 'fonts', function() {
triggerPlumber( fontsSRC, fontsURL );
});
function triggerPlumber( src, url ) {
return gulp.src( src )
.pipe( plumber() )
.pipe( gulp.dest( url ) );
}
gulp.task( 'default', ['styles', 'js', 'images', 'fonts'], function() {
gulp.src( jsURL + 'admin.min.js' )
.pipe( notify({ message: 'Assets Compiled!' }) );
});
gulp.task( 'watch', ['default', 'browser-sync'], function() {
gulp.watch( phpWatch, reload );
gulp.watch( styleWatch, [ 'styles' ] );
gulp.watch( jsWatch, [ 'js', reload ] );
gulp.watch( imgWatch, [ 'images' ] );
gulp.watch( fontsWatch, [ 'fonts' ] );
gulp.src( jsURL + 'admin.min.js' )
.pipe( notify({ message: 'Gulp is Watching, Happy Coding!' }) );
});