-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
157 lines (137 loc) · 4.38 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
'use strict';
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var browserSyncConfig = {
reloadOnRestart: true,
notify: false,
port: 9000,
startPath: "/",
server: {
baseDir: ['dist', 'app']
}
};
var jadeData = require('./data.json');
// compile jade
gulp.task('views', function() {
return gulp.src(['app/tamplates/**/*.jade'])
.pipe($.plumber())
//only pass unchanged *main* files and *all* the partials
.pipe($.changed('dist', { extension: '.html' }))
//filter out unchanged partials, but it only works when watching
.pipe($.if(browserSync.active, $.cached('jade')))
//find files that depend on the files that have changed
.pipe($.jadeInheritance({ basedir: 'app/tamplates' }))
//filter out partials (folders and files starting with "_" )
.pipe($.filter(function(file) {
return !/\_/.test(file.path) && !/^_/.test(file.relative);
}))
.pipe($.jade({
locals: jadeData,
pretty: true
}))
.pipe($.beml())
.pipe($.fileInclude({ basepath: 'dist' }))
.pipe(gulp.dest('dist'))
.pipe(reload({ stream: true }));
});
// compile sass
gulp.task('styles', function() {
$.rubySass('app/styles', {
style: 'expanded',
precision: 10,
sourcemap: true
})
.on('error', function(err) {
console.error('Error!', err.message);
})
.pipe($.postcss([
require('autoprefixer'),
require('postcss-flexibility')
]))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('dist/styles'))
.pipe(reload({ stream: true }));
});
// view and check scripts
gulp.task('scripts', function() {
return gulp.src(['app/scripts/**/*.js', '!app/scripts/modernizr/modernizr.custom.js'])
.pipe($.filter(function(file) {
return !/\_/.test(file.path) && !/^_/.test(file.relative);
}))
.pipe($.plumber())
.pipe($.sourcemaps.init())
.pipe($.babel())
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('dist/scripts'));
});
gulp.task('jshint', function() {
return gulp.src('app/scripts/**/*.js')
.pipe($.plumber())
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.jshint.reporter('fail'));
});
// min-css
gulp.task('min-css', function() {
return gulp.src('dist/styles/*.css')
.pipe($.minifyCss({ compatibility: 'ie8' }))
.pipe($.rename({ suffix: '.min' }))
.pipe(gulp.dest('dist/styles'));
});
// sprite-gen
gulp.task('sprite', function() {
var spriteData = gulp.src('app/sprite/icons/*.png').pipe($.spritesmith({
imgName: 'sprite.png',
cssName: 'sprite.scss',
padding: 20,
imgPath: '../images/png/sprite.png'
}));
return spriteData.pipe(gulp.dest('app/sprite/'));
});
// sprite move to dist
var filesToMove = [
'app/sprite/*.png'
];
gulp.task('move-sprite', ['sprite'], function() {
gulp.src(filesToMove, { base: './app/sprite/' })
.pipe(gulp.dest('dist/images/png/'));
});
// clean scripts
gulp.task('clean-scripts', function() {
return gulp.src('./dist/scripts/app.min.js', { read: false })
.pipe($.clean());
});
gulp.task('min-js', ['clean-scripts'], function() {
return gulp.src([
'./dist/plugins/jquery.dotdotdot.min.js',
'./dist/plugins/flexibility.js',
'./dist/plugins/phone-mask.js',
'./dist/plugins/image-scale.min.js',
'./dist/plugins/responsive-tables/responsive-tables.js',
'./dist/scripts/*.js',
])
.pipe($.concat('app.min.js'))
.pipe(gulp.dest('dist/scripts/'))
.pipe($.uglify())
.pipe(gulp.dest('dist/scripts/'));
});
// main task
gulp.task('serve', $.sync(gulp).sync([
['views', 'styles', 'scripts', 'move-sprite']
]), function() {
browserSync.init(browserSyncConfig);
// watch for changes
gulp.watch([
'dist/scripts/**/*.js',
'app/images/**/*'
]).on('change', reload);
gulp.watch('app/scripts/**/*.js', ['scripts']);
gulp.watch('app/styles/**/*.scss', ['styles']);
gulp.watch('app/**/*.jade', ['views']);
gulp.watch('app/sprite/icons/*.*', ['move-sprite', 'styles']);
});
gulp.task('watch', function() {
gulp.start('serve');
});