-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGulpfile.js
143 lines (119 loc) · 3.45 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
140
141
142
143
// Include gulp
var gulp = require('gulp');
// Gulp plugins loads almost all our dependency from package.json
var plugins = require('gulp-load-plugins')();
var pkg = require ('./package.json');
// Unsure how to get these to work with gulp-load-plugins
var autoprefixer = require('autoprefixer-core');
var mqpacker = require('css-mqpacker');
var focus = require('postcss-focus');
// Defining path variables
var dirs = {
"src": "src",
"assets": "public/assets",
"views": "public/views",
};
var paths = {
sass: [
dirs.src + '/sass/**/*.scss'
],
script: [
dirs.src + '/js/scripts/*.js',
dirs.src + '/js/*.js'
],
watch: [
'views/**/*.php',
'views/**/*.html'
]
};
// Tasks
//---
// Concatenate & Minify JS
gulp.task('script', function() {
return gulp.src( paths.script )
.pipe(plugins.plumber(function(error) {
plugins.util.log(
plugins.util.colors.red(error.message),
plugins.util.colors.yellow('\r\nOn line: '+error.line),
plugins.util.colors.yellow('\r\nCode Extract: '+error.extract)
);
this.emit('end');
}))
.pipe(plugins.concat('main.js'))
.pipe(plugins.babel())
.pipe(gulp.dest( dirs.assets + '/js/' ))
.pipe(plugins.uglify())
.pipe(plugins.rename('main.min.js'))
.pipe(gulp.dest( dirs.assets + '/js/' ))
.pipe(plugins.livereload());
});
// Compile our less
gulp.task('sass', function() {
// Make sure our css is compatible with the last two versions of all browsers
// For all ::hover styles duplicate a ::focus style
// Condense mediaquery calls
var processors = [
autoprefixer({browsers: ['last 2 version']}),
focus,
mqpacker,
];
return gulp.src( 'src/sass/main.scss' )
.pipe(plugins.plumber(function(error) {
plugins.util.log(
plugins.util.colors.red(error.message),
plugins.util.colors.yellow('\r\nOn line: '+error.line),
plugins.util.colors.yellow('\r\nCode Extract: '+error.extract)
);
this.emit('end');
}))
.pipe(plugins.sass())
.pipe(plugins.postcss( processors ))
.pipe(plugins.minifyCss())
.pipe(plugins.rename('main.min.css'))
.pipe(gulp.dest( dirs.assets + '/css/' ))
.pipe(plugins.livereload());
});
// Bower Update Task
gulp.task('bower', function() {
return plugins.bower();
});
// Cachebust
gulp.task('cachebust', function() {
return gulp.src([dirs.src + '/views/**/*.php'])
.pipe(plugins.consolidate('lodash', {
timestamp: Date.now()
}))
.pipe(gulp.dest( dirs.views ));
});
// Migrate Vendor Dependencies
gulp.task('vendor',['bower'], function() {
// materialize js
gulp.src( 'src/vendor/materialize/dist/js/materialize.min.js' )
.pipe(gulp.dest( dirs.assets + '/js/plugins' ));
// materialize fonts - roboto
gulp.src( 'src/vendor/materialize/dist/font/**/*')
.pipe(gulp.dest( dirs.assets + '/font' ));
// materialize sass
gulp.src( 'src/vendor/materialize/sass/components/**/*')
.pipe(gulp.dest( dirs.src + '/sass/materialize' ));
// jquery
gulp.src( 'src/vendor/jquery/dist/jquery.min.js' )
.pipe(gulp.dest( dirs.assets + '/js/plugins' ));
// modernizr
gulp.src( 'src/vendor/modernizr/modernizr.js' )
.pipe(gulp.dest( dirs.assets + '/js/plugins' ));
});
// Watch Files For Changes
gulp.task('watch', function() {
plugins.livereload.listen(23456);
gulp.watch( paths.script , ['script']);
gulp.watch( paths.sass, ['sass']);
gulp.watch( paths.watch ).on('change', function (event) {
plugins.livereload.changed(event.path);
});
});
gulp.task('init', ['vendor'], function() {
gulp.run('sass');
gulp.run('script');
});
gulp.task('build', ['script', 'sass', 'cachebust']);