-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
85 lines (73 loc) · 1.97 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
const gulp = require('gulp')
const webpack = require('webpack')
const rsync = require('gulp-rsync')
const gutil = require("gulp-util")
const path = require('path')
const clean = require('gulp-clean')
gulp.task('rsync', function() {
const exclude = ['.*', '*.swp']
return gulp.src(['src/static/**'])
.pipe(rsync({
root: 'src/',
destination: 'dist/',
exclude: exclude,
include: ['*.min.js', '*.min.css'],
recursive: true,
clean: true,
times: true,
update: true
}))
.on('error', function(e) {
console.log('>>> ERROR', e);
this.emit('end');
})
})
gulp.task('clean', function () {
return gulp.src('dist/')
.pipe(clean({force: true}))
})
gulp.task('build', ['clean', 'rsync'], function() {
const conf = require('./build/webpack.prod.conf')
console.log(JSON.stringify(conf))
webpack(conf).run((err, stats)=>{
if (err || stats.hasErrors()) {
console.log(stats.toString({
colors: true
}))
}
})
})
gulp.task("dev", function(callback) {
const express = require('express')
const app = express()
const history = require('connect-history-api-fallback')
const config = require('./build/webpack.dev.conf')
const compiler = webpack(config)
var devMiddleware = require('webpack-dev-middleware')(compiler, {
publicPath: config.output.publicPath,
stats: {
colors: true,
chunks: false
}
})
var hotMiddleware = require('webpack-hot-middleware')(compiler)
compiler.plugin('compilation', function (compilation) {
compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
hotMiddleware.publish({ action: 'reload' })
cb()
})
})
app.use('/static', express.static('./src/static'))
app.use(history({
index: '/',
}))
app.use(devMiddleware)
app.use(hotMiddleware)
app.listen(8888, function (err) {
if (err) {
console.log(err)
return
}
console.log('Listening at http://localhost:8888')
})
})