-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
206 lines (165 loc) · 4.78 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
'use strict';
// Generated on 2016-07-06 using generator-wim 0.0.1
var gulp = require('gulp');
var open = require('open');
var del = require('del');
var less = require('gulp-less');
var wiredep = require('wiredep').stream;
// Browser sync
var browserSync = require("browser-sync").create();
var reload = browserSync.reload;
// Load plugins
var $ = require('gulp-load-plugins')();
//copy leaflet images
//less compilation
gulp.task('less', function () {
return gulp.src(['src/bower_components/wim-mapper-styles/less/base.less'])
.pipe(less())
.pipe(gulp.dest('src/styles'))
.pipe(gulp.dest('build/styles'))
});
// Styles
gulp.task('styles', function () {
return gulp.src(['src/styles/main.css'])
.pipe($.autoprefixer('last 1 version'))
.pipe(gulp.dest('src/styles'))
.pipe($.size());
});
// Icons
gulp.task('icons', function () {
return gulp.src(['src/bower_components/bootstrap/dist/fonts/*.*'])
.pipe(gulp.dest('build/fonts'));
});
// Scripts
gulp.task('scripts', function () {
return gulp.src(['src/scripts/**/*.js'])
.pipe($.jshint('.jshintrc'))
.pipe($.jshint.reporter('default'))
.pipe($.size());
});
// HTML
gulp.task('html', ['styles', 'scripts', 'icons'], function () {
var jsFilter = $.filter('**/*.js');
var cssFilter = $.filter('**/*.css');
return gulp.src('src/*.html')
.pipe($.useref.assets())
.pipe(jsFilter)
.pipe($.uglify())
.pipe(jsFilter.restore())
.pipe(cssFilter)
.pipe($.csso())
.pipe(cssFilter.restore())
.pipe($.useref.restore())
.pipe($.useref())
//.pipe(rename({ extname: '.min.js' }))
.pipe(gulp.dest('build'))
.pipe($.size());
});
// Images
gulp.task('images', function () {
return gulp.src([
'src/images/**/*',
'src/lib/images/*'])
.pipe(gulp.dest('build/images'))
.pipe($.size());
});
// Clean
gulp.task('clean', function (cb) {
del([
'build/styles/**',
'build/scripts/**',
'build/images/**',
], cb);
});
// Build
gulp.task('build', ['html', 'images', 'less']);
// Default task
//make sure download-esri-api (if needed) is run just after clean, but before build
//gulp.task('default', ['clean', 'download-esri-api'], function () {
gulp.task('default', ['clean'], function () {
gulp.start('build');
});
// Run Bukld
gulp.task('connectBuild', function(){
$.connect.server({
root: 'src',
port: 9000,
livereload: true
});
});
// Open
gulp.task('serve-build', ['connectBuild'], function() {
open("http://localhost:9000");
});
// Connect
gulp.task('connect', function(){
$.connect.server({
root: 'src',
port: 9000,
livereload: true
});
});
// Open
gulp.task('serve', ['connect'], function() {
open("http://localhost:9000");
});
// Inject Bower components
gulp.task('wiredep', function () {
gulp.src('src/styles/*.css')
.pipe(wiredep({
directory: 'src/bower_components',
ignorePath: 'src/bower_components/'
}))
.pipe(gulp.dest('src/styles'));
gulp.src('src/*.html')
.pipe(wiredep({
directory: 'src/bower_components',
ignorePath: 'src/'
}))
.pipe(gulp.dest('src'));
});
// Watch
gulp.task('watch', ['less', 'connect', 'serve'], function () {
// Watch for changes in `app` folder
gulp.watch([
'src/*.html',
'src/styles/**/*.css',
'src/**/*.less',
'src/scripts/**/*.js',
'src/images/**/*'
], function (event) {
return gulp.src(event.path)
.pipe($.connect.reload());
});
gulp.watch("./src/**/*.less", ['sync-styles']);
// Watch .css files
gulp.watch('src/styles/**/*.css', ['styles']);
// Watch .js files
gulp.watch('src/scripts/**/*.js', ['scripts']);
// Watch image files
gulp.watch('src/images/**/*', ['images']);
// Watch bower files
gulp.watch('bower.json', ['wiredep']);
});
// Browsersync
// alternative to regular server
// After running Browsersync, run regular gulp and gulp build to make sure less changes built
gulp.task('bs', function(){
browserSync.init({
server: "./src/"
});
gulp.watch("./src/**/*.less", ['sync-styles']);
// Build CSS?
// gulp.watch('src/styles/**/*.css', ['styles']);
gulp.watch("./src/**/*.html").on("change", reload);
gulp.watch("./src/**/*.js").on("change", reload);
});
// Compile LESS to CSS then inject without reload
// Compile LESS to CSS then inject without reload
// Compile LESS to CSS then inject without reload
gulp.task('sync-styles', function(){
gulp.src('./src/styles/less/main.less')
.pipe(less())
.pipe(gulp.dest('./src/styles/'))
.pipe(browserSync.stream());
});