-
Notifications
You must be signed in to change notification settings - Fork 40
/
gulpfile.js
134 lines (120 loc) · 3.21 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
const gulp = require('gulp');
const del = require('del');
const gutil = require("gulp-util");
const webpack = require("webpack");
const server = require('gulp-develop-server');
const notifier = require('node-notifier');
const runSequence = require('run-sequence');
const lightReload = require('light-reload');
const useref = require('gulp-useref');
const gulpif = require('gulp-if');
const uglify = require('gulp-uglify');
const minifyCss = require('gulp-clean-css');
gulp.task('client:prd-build', (callback) => {
let config = require('./config/webpack.prod.js');
webpack(config, (err, stats) => {
showWebpackError(err, stats);
callback();
});
});
gulp.task('client:dev-build', () => {
let config = require('./config/webpack.dev.js');
let compiler = webpack(config);
compiler.watch(200, (err, stats) => {
showWebpackError(err, stats);
notifier.notify({
title: 'Humpback-Client',
message: 'Client build succeed.'
});
lightReload.reload();
});
});
gulp.task('clean', () => {
return del(['dist/*', '!dist/dbFiles', '!dist/node_modules'], { force: true });
});
gulp.task('server:clean', (callback) => {
return del(['dist/**/*', '!dist/client'], { force: true });
});
gulp.task('server:copy', () => {
return gulp.src(['src/server/**'])
.pipe(gulp.dest('dist/'));
});
gulp.task('server:reload', (callback) => {
runSequence('server:copy', 'server:restart', callback);
});
gulp.task('server:start', (callback) => {
lightReload.init();
server.listen({ path: 'dist/index.js' }, err => {
if (err) console.log('listen', err);
});
callback();
});
gulp.task('server:restart', (callback) => {
server.restart(err => {
if (err) console.log('restart', err);
notifier.notify({
title: 'Humpback-Server',
message: 'Server restarted.'
});
});
callback();
});
gulp.task('server:watch', () => {
return gulp.watch(['src/server/**/*.js'], ['server:reload']);
});
gulp.task('release:html', () => {
return gulp.src('dist/client/index.html')
.pipe(useref())
.pipe(gulpif('*.js', uglify()))
.pipe(gulpif('*.css', minifyCss()))
.pipe(gulp.dest('dist/client'));
});
gulp.task('release:clean-unused-file', () => {
let rootPath = 'dist/client/static';
return del([
`${rootPath}/**/*.css`,
`${rootPath}/**/*.js`,
`!${rootPath}/vendor/css/vendor.min.css`,
`!${rootPath}/vendor/js/vendor.min.js`,
`!${rootPath}/css/site.min.css`,
`!${rootPath}/js/site.min.js`
], { force: true });
});
gulp.task('dev', (callback) => {
runSequence(
'clean',
'server:copy',
'server:start',
'server:watch',
'client:dev-build',
callback);
});
gulp.task('release', (callback) => {
runSequence(
'clean',
'server:copy',
'client:prd-build',
'release:html',
'release:clean-unused-file',
callback);
});
let showWebpackError = (err, stats) => {
if (err) {
throw new gutil.PluginError('webpack', err);
}
gutil.log("[webpack:build-dev]", stats.toString({
colors: true,
hash: false,
timings: true,
chunks: true,
chunkModules: false,
modules: false,
children: false,
version: true,
cached: true,
cachedAssets: true,
reasons: false,
source: false,
errorDetails: false
}));
};