This repository has been archived by the owner. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgulpfile.js
117 lines (108 loc) · 2.62 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
var gulp = require('gulp');
var gutil = require('gulp-util');
var plumber = require('gulp-plumber');
var stylus = require('gulp-stylus');
var copy = require('gulp-copy');
var ghPages = require('gulp-gh-pages');
var webpack = require('webpack');
var notifier = require('node-notifier');
var browserSync = require('browser-sync');
var stylobuild = require('stylobuild');
var isDevelopment = process.env.NODE_ENV !== 'production';
var isWatch = false;
function reload() {
if (isDevelopment && isWatch) {
return browserSync.reload.apply(browserSync, arguments);
}
else {
return gutil.noop();
}
}
function notifyError(plugin, message, filepath, filename) {
console.log(gutil.colors.red.bold('\nError in ' + (filename || filepath) + '\n'));
console.log(message);
if (isWatch) {
notifier.notify({
title: '\uD83D\uDEA8 ' + plugin + ' error',
message: gutil.colors.stripColor(message).replace(/ +/g, ' '),
open: 'file://' + filepath
});
}
else {
process.exit(1);
}
}
gulp.task('webpack', function() {
webpack(require('./webpack.config.js'), function(err, stats) {
var error, message;
if (stats.hasErrors()) {
error = stats.compilation.errors[0];
message = error.error;
}
else if (stats.hasWarnings()) {
error = stats.compilation.warnings[0];
message = error.warning;
}
if (error) {
notifyError('Webpack', message.toString(), error.module.resource, error.module.rawRequest);
}
else {
reload();
}
});
});
gulp.task('styles', function() {
return gulp.src('styles/index.styl')
.pipe(plumber({errorHandler: function(error) {
notifyError('Stylus', error.message.replace(/.*\n/, ''), error.filename);
this.emit('end');
}}))
.pipe(stylus({
url: {
name: 'embedurl'
},
define: {
DEBUG: isDevelopment
},
paths: [
'tamia'
],
use: [
stylobuild({
autoprefixer: {
browsers: 'last 2 versions, ie 9'
},
minifier: isDevelopment ? false : 'cleancss',
pixrem: false
})
]
}))
.pipe(gulp.dest('build/'))
.pipe(reload({stream: true}));
});
gulp.task('watch', ['webpack', 'styles'], function() {
isWatch = true;
if (isDevelopment) {
browserSync({
notify: false,
online: false,
server: '.'
});
}
gulp.watch(['app/**/*.{js,jsx}'], ['webpack']);
gulp.watch(['styles/**/*.styl'], ['styles']);
});
gulp.task('make-dist', function() {
return gulp.src([
'build/**/*',
'icons/*.svg',
'index.html'
])
.pipe(copy('dist'));
});
gulp.task('gh-deploy', function() {
return gulp.src('dist/**/*')
.pipe(ghPages());
});
gulp.task('default', ['webpack', 'styles']);
gulp.task('deploy', ['webpack', 'styles', 'make-dist', 'gh-deploy']);