-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·114 lines (104 loc) · 3.25 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
var gulp = require('gulp'),
gulpPlugins = require('gulp-load-plugins')(),
runSequence = require('run-sequence'),
browserSync = require('browser-sync'),
del = require('del'),
config = require('./config.json'),
reload = browserSync.reload,
webpack = require('webpack-stream'),
$ = gulpPlugins,
AUTOPREFIXER_BROWSERS = [
'ie >= 10',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 4.4',
'bb >= 10'
];
gulp.task('clean', function(){
return del(config.files.cleanPaths);
});
gulp.task('jshint', function () {
return gulp.src( config.app.js.sources )
.pipe(reload({stream: true, once: true}))
.pipe($.jshint())
.pipe($.jshint.reporter(config.app.js.jsHintReporter))
.pipe($.if(!browserSync.active, $.jshint.reporter('fail')));
});
gulp.task('styles', ['clean'],function () {
return gulp.src(config.app.css.entry)
.pipe($.sourcemaps.init())
.pipe($.stylus())
.pipe($.autoprefixer({browsers: AUTOPREFIXER_BROWSERS}))
.pipe($.sourcemaps.write())
.pipe(gulp.dest(config.app.css.tmpDirectory))
.pipe($.size({title: 'Styles'}));
});
gulp.task('webpack', function() {
return gulp.src(config.app.js.entry)
.pipe(webpack({
output: {
filename: 'bundle.js'
},
devtool: 'source-map'
}))
.pipe(gulp.dest(config.app.js.tmpDirectory));
});
gulp.task('concat-css', function(){
return gulp.src(config.files.concat.css)
.pipe($.changed(config.app.css.tmpDirectory, {extension: '.css'}))
.pipe($.if('*.css', $.concat( config.app.css.concat )))
.pipe($.if('*.css', gulp.dest(config.app.css.tmpDirectory)))
.pipe($.size({title: 'Concat CSS size'}));
});
gulp.task('server', ['styles','webpack','clean'], function () {
browserSync({
open: false,
notify: false,
logPrefix: 'Initial Layout',
server: {
baseDir: config.app.server,
middleware: function(req, res, next) {
if(/\S\.{1}(jpg|jpeg|png|svg|css|js|map|ttf|eot|woff|html)/.test(req.url) !== true){
req.url = '/index.html';
}
return next();
}
}
});
gulp.watch(config.files.watch.html, reload);
gulp.watch(config.files.watch.styles, ['styles', reload]);
gulp.watch(config.files.watch.js, ['jshint', 'webpack',reload]);
gulp.watch(config.files.watch.img, reload);
});
gulp.task('deploy-files', ['clean'],function () {
return gulp.src(config.deploy.from, {
dot: true
}).pipe(gulp.dest(config.deploy.to))
.pipe($.size({title: 'copy'}))
.pipe($.if('**/*.css', $.csso()))
.pipe($.if('**/*.js', $.uglify({preserveComments: 'some'})))
.pipe(gulp.dest(config.deploy.to));
});
gulp.task('server:deploy', ['deploy-files'],function () {
browserSync({
open: false,
notify: false,
server: {
baseDir: "deploy",
middleware: function(req, res, next) {
if(/\S\.{1}(jpg|jpeg|png|svg|css|js|map|ttf|eot|woff|html)/.test(req.url) !== true){
req.url = '/index.html';
}
return next();
}
}
});
});
// Build production files, the default task
gulp.task('default', ['clean'], function (cb) {
runSequence('styles', ['jshint','deploy'], cb);
});