-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
133 lines (113 loc) · 3.4 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
var paths = {
'html': 'app/index.html',
'scripts': 'app/scripts/**/*.js',
'sass': 'app/styles/**/*.scss',
'sassDir': 'app/styles',
'css': 'app/.tmp'
};
var compassOptions = { // passed into compass()
'config_file': 'config.rb',
'sass': paths.sassDir,
'css': paths.css
};
// dependencies
var gulp = require('gulp');
var filter = require('gulp-filter');
var rimraf = require('gulp-rimraf');
// dependencies for the server
var connect = require('connect');
var livereload = require('gulp-livereload');
// dependencies for scripts
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
// dependencies for styles
var compass = require('gulp-compass');
var minifyCSS = require('gulp-minify-css');
// dependencies for HTML
var useref = require('gulp-useref');
var cdnizer = require('gulp-cdnizer');
var minifyHTML = require('gulp-minify-html');
// jshint
gulp.task('jshint', function () {
return gulp.src([paths.scripts, 'gulpfile.js'])
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// compass
var devCompass = function () {
return gulp.src(paths.sass)
.pipe(compass(compassOptions));
};
gulp.task('dev-compass', ['build-clean'], devCompass);
// development server, based on https://github.com/vohof/gulp-livereload
gulp.task('dev-server', function (next) {
var server = connect();
server.use(connect.static('app/'))
.use('/test', connect.static('test/'))
.listen(60001, next); // port
});
// watch
gulp.task('dev-watch', function() {
var server = livereload();
gulp.watch('app/**/*.*').on('change', function (file) {
if (file.path.match(/scss$/)) {
devCompass();
server.changed(paths.css + '/main.css');
} else {
server.changed(file.path);
}
});
});
// run this when developing this project
gulp.task('dev', ['dev-server', 'dev-watch']);
// delete the build dir
gulp.task('build-clean', function() {
return gulp.src('dist', {
'read': false // not reading the files speeds up this task
})
.pipe(rimraf());
});
// copy
gulp.task('build-copy', ['build-clean'], function () {
return gulp.src('app/bower_components/zeroclipboard/dist/ZeroClipboard.swf')
.pipe(gulp.dest('dist/scripts'));
});
// useref
gulp.task('build-useref', ['build-clean', 'dev-compass'], function () {
var htmlFilter = filter('**/*.html');
var scriptsFilter = filter('**/*.js');
var stylesFilter = filter('**/*.css');
return gulp.src(paths.html)
.pipe(useref.assets())
.pipe(scriptsFilter) // scripts start
.pipe(uglify())
.pipe(scriptsFilter.restore()) // scripts end
.pipe(stylesFilter) // styles start
.pipe(minifyCSS())
.pipe(stylesFilter.restore()) // styles end
.pipe(useref.restore())
.pipe(htmlFilter) // html start
.pipe(useref())
.pipe(cdnizer([
{
'package': 'bootstrap',
'file': '**/bootstrap.css',
'cdn': '//maxcdn.bootstrapcdn.com/bootstrap/${version}/css/bootstrap.min.css'
},
{
'package': 'jquery',
'file': '**/jquery.js',
'cdn': '//ajax.googleapis.com/ajax/libs/jquery/${version}/jquery.min.js'
}
]))
.pipe(minifyHTML())
.pipe(htmlFilter.restore()) // html end
.pipe(gulp.dest('dist'));
});
// build
gulp.task('build', ['build-useref', 'build-copy']);
// build server
gulp.task('build-server', ['build'], function (next) {
var server = connect();
server.use(connect.static('dist/')).listen(60002, next);
});