forked from jackhutu/jackblog-angular2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
71 lines (63 loc) · 1.95 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
var path = require('path')
var gulp = require('gulp')
var gutil = require('gulp-util')
var WebpackDevServer = require("webpack-dev-server")
var webpack = require("webpack")
var del = require('del')
var env = require('gulp-env')
var gulpSequence = require('gulp-sequence')
var nodemon = require('gulp-nodemon')
var open = require('open')
var DEV_PORT = 5300,PROD_PORT = 8500
gulp.task('serve', function () {
var devConfig = require('./webpack.config')
devConfig.entry.main.unshift('webpack-dev-server/client?http://localhost:' + DEV_PORT, 'webpack/hot/only-dev-server')
new WebpackDevServer(webpack(devConfig), {
noInfo: false,
hot: true,
inline: true,
historyApiFallback: true,
publicPath: devConfig.output.publicPath,
stats: {
colors: true
},
watchOptions: { aggregateTimeout: 300, poll: 1000 }
}).listen(DEV_PORT, "localhost", (err,stat) => {
if(err) throw new gutil.PluginError("webpack-dev-server", err)
gutil.log("[webpack-dev-server]", "==> 🌎 http://localhost:" + DEV_PORT)
open('http://localhost:' + DEV_PORT)
});
})
gulp.task('clean', function () {
del([path.join(__dirname, '/dist/*')])
})
gulp.task('set-env-prod', function () {
env({
vars: {
'NODE_ENV':'production'
}
})
})
gulp.task('webpack', function (cb) {
var prodConfig = require('./webpack.config')
webpack(prodConfig, function(err, stats) {
if(err) throw new gutil.PluginError("webpack", err)
gutil.log("[webpack]", stats.toString({
// output options
}))
cb()
})
})
gulp.task('webpack:dist',gulpSequence('set-env-prod','webpack'))
gulp.task('build', gulpSequence('clean','webpack:dist'))
gulp.task('nodemon', function () {
nodemon({
script: path.join(__dirname,'/server.js'),
ext: 'js',
watch: [
path.join(__dirname,'/dist')
],
env: { 'NODE_ENV': 'production','PORT':PROD_PORT }
})
})
gulp.task('serve:dist',gulpSequence('build','nodemon'))