-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathgulpfile.js
149 lines (130 loc) · 3.37 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
var gulp = require('gulp');
var runSequence = require('run-sequence');
var webpack = require('webpack');
var notify = require('gulp-notify');
var rm = require('rimraf');
var imagemin = require('gulp-imagemin');
var scsslint = require('gulp-scss-lint');
//http://www.browsersync.cn/docs/recipes/
var browserSync = require('browser-sync').create();
var reload = browserSync.reload;
var src = './src/';
var dest = './dist/';
var homepage = 'index.html';
var config = {
src: src,
dest: dest,
webServer: {
server: './dist',
index: homepage,
port: 3000,
logLevel: 'debug',
logPrefix: 'JHW',
open: true,
files: [dest + '/*.js', './index.html']
},
scss: {
src: src + '**/*.scss'
},
script: {
entry: {
'entry': src + 'main.js'
},
output: {
path: dest, //js
filename: 'bundle.js'
},
sourceMap: true,
watch: src + '**/*.js'
},
html: {
watchHome: homepage,
watchAll: src + '**/*.html'
}
}
var webpackConfig = require('./webpack.config')(config);
gulp.task('webpack', function(cb) {
webpack(webpackConfig, function(err, stats) {
if (err) {
handleErrors();
console.error(stats);
}
if (stats.compilation.errors.length) {
console.error(stats.compilation.errors[0].toString());
}
cb();
});
});
gulp.task('img:dev', ['clean'], function() {
return gulp.src([src + '/images/**'])
.pipe(watch())
.pipe(reload());
});
gulp.task('img', ['clean'], function() {
return gulp.src([src + '/images/**'])
.pipe(imagemin())
.pipe(gulp.dest(dest + '/images'));
});
function handleErrors() {
var args = Array.prototype.slice.call(arguments);
notify.onError({
title: 'compile error',
message: '<%= error.message %>'
}).apply(this, args);
this.emit('end');
}
gulp.task('web-server', ['build'],function() {
browserSync.init(config.webServer);
});
gulp.task('watch', ['web-server'], function() {
gulp.watch(config.script.watch, ['webpack']).on('change', reload);
gulp.watch(config.scss.src, ['webpack']).on('change', reload);
gulp.watch(config.src + '/**/*.vue', ['webpack']).on('change', reload);
gulp.watch(config.html.watchHome, ['html']).on('change', reload);
gulp.watch(config.html.watchAll, ['html']).on('change', reload);
});
gulp.task('scss-lint', function() {
return gulp.src(src+'**/*.scss')
.pipe(scsslint({
'config': 'scsslint.yml',
}));
});
gulp.task('static', function() {
return gulp.src([src + 'static/**'])
.pipe(gulp.dest(dest + 'static'));
});
gulp.task('datajson', function() {
return gulp.src([src + 'data.json'])
.pipe(gulp.dest(dest));
});
gulp.task('gatheringdata', function() {
return gulp.src([src + 'gathering/**'])
.pipe(gulp.dest(dest + 'gathering'));
});
gulp.task('icons', function() {
return gulp.src([src + 'icons/**'])
.pipe(gulp.dest(dest + 'icons'));
});
gulp.task('html', function() {
return gulp.src([src + '**/*.html'])
.pipe(gulp.dest(dest));
});
gulp.task('clean', function(next) {
rm(dest, function() {
next();
});
});
gulp.task('default', ['watch']);
gulp.task('run', ['watch']);
gulp.task('build', function(callback) {
runSequence('clean', 'img', 'webpack', 'static', 'datajson', 'gatheringdata', 'icons', 'html',callback);
});
gulp.task( 'download-images', function() {
var data = require('./scripts/download-images');
});
// Require extra gulp tasks
try {
require('./gulptasks/upload.js')(gulp);
} catch(err) {
// Don't error if we don't have extra tasks, they're only for deploy right now
}