This repository has been archived by the owner on Apr 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
151 lines (122 loc) · 4.17 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
144
145
146
147
148
149
150
151
//
// Gulp Config
//
/*
* Environment Variables
* --------------------------------------------------
*/
var env = {
isProduction: false,
};
/*
* Load Plugins
* --------------------------------------------------
*/
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')({ // Load all dev dependencies in package.json except 'grunt related'.
pattern: ['*', '!{grunt,gulp-grunt}'],
scope: ['devDependencies']
});
/*
* Task: Truncate and delete the entire destination folder
* --------------------------------------------------
*/
gulp.task('clean', function(next) {
plugins.del([
'./dist/'
], next);
});
/*
* Task: Copy non-compiling files to build folder
* --------------------------------------------------
*/
gulp.task('copy', function(next) {
gulp.src(['./src/assets/images/**/*']).pipe(gulp.dest('./dist/images/'));
gulp.src(['./src/assets/js/**/*']).pipe(gulp.dest('./dist/js/'));
gulp.src(['./src/LICENSE']).pipe(gulp.dest('./dist/'));
gulp.src(['./src/manifest.json']).pipe(gulp.dest('./dist/'));
gulp.src(['./src/README.md']).pipe(gulp.dest('./dist/'));
next();
});
/*
* Task: Sass Compilation
* --------------------------------------------------
*/
gulp.task('styles', function() {
return gulp.src('./src/stylesheets/*.scss')
.pipe(plugins.if(!env.isProduction, plugins.sourcemaps.init()))
.pipe(plugins.sass({
errLogToConsole: true
}))
.pipe(plugins.autoprefixer({
browser: ['Firefox >= 32', 'Chrome >= 38', 'Explorer >= 10', 'iOS >= 7'],
cascade: false
}))
.pipe(plugins.if(env.isProduction, plugins.cssnano()))
.pipe(plugins.if(!env.isProduction, plugins.sourcemaps.write()))
.pipe(gulp.dest('./dist/css/'))
.pipe(plugins.browserSync.reload({
stream: true
}));
});
/*
* Task: Combine and compile server-side scripting for client-side purpose using Browserify
* --------------------------------------------------
*/
gulp.task('scripts', function() {
gulp.src(['./src/scripts/**/*.js'])
.pipe(plugins.jshint({
node: true, // Inform JSHint that this is a Node project to better fine tune error report
browser: true,
}))
.pipe(plugins.jshint.reporter('default')); // May opt to use 'jshint-stylish' reporter.
return gulp.src('./src/scripts/app.js')
.pipe(plugins.if(!env.isProduction, plugins.sourcemaps.init()))
.pipe(plugins.browserify({
debug: !env.isProduction,
}))
.pipe(plugins.if(env.isProduction, plugins.uglify()))
.pipe(plugins.if(!env.isProduction, plugins.sourcemaps.write()))
.pipe(gulp.dest('./dist/js/'));
});
/*
* Task: Build project to destination folder. This is broken up into 2 'gulp.task()' in order to execute the tasks in
* this order: 'clean' -> 'copy'|'styles'
* Watch out for gulp 4.0 as the dependency system will become easier to manage.
* --------------------------------------------------
*/
gulp.task('build-tasks', ['copy', 'scripts', 'styles'], function(next) {
this.emit('build-tasks:done');
next();
});
gulp.task('build', ['clean'], function(next) {
gulp.start('build-tasks');
this.on('build-tasks:done', next);
});
/*
* Task: Watch file changes on source folder and execute associated task(s).
* --------------------------------------------------
*/
gulp.task('watch', function() {
gulp.watch(['./src/**/*.html'], ['copy']);
gulp.watch(['./src/stylesheets/**/*.scss'], ['styles']);
gulp.watch(['./src/scripts/**/*.js'], ['scripts']);
});
/*
* Task: Preparation for Production environment output
* --------------------------------------------------
*/
gulp.task('build-production', function() {
env.isProduction = true;
return gulp.start('build');
});
gulp.task('bp', function() { // Shortcut
return gulp.start('build-production');
});
/*
* Default: By execute 'gulp', it will first 'build', then active 'server' and 'watch' in that sequence.
* --------------------------------------------------
*/
gulp.task('default', ['build'], function() {
gulp.start('watch');
});