forked from jackhutu/jackblog-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
72 lines (64 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
72
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 = 3000,PROD_PORT = 8400
gulp.task('serve', function () {
var webpackConfig = require('./webpack.config')
var myConfig = Object.create(webpackConfig)
myConfig.entry.unshift('webpack/hot/only-dev-server')
myConfig.entry.unshift('webpack-dev-server/client?http://localhost:' + DEV_PORT)
new WebpackDevServer(webpack(myConfig), {
noInfo: false,
hot: true,
inline: true,
historyApiFallback: true,
publicPath: myConfig.output.publicPath,
stats: {
colors: true
}
}).listen(DEV_PORT, 'localhost', function (err) {
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 (callback) {
var config = require('./webpack.config')
webpack(config, function(err, stats) {
if(err) throw new gutil.PluginError("webpack", err)
gutil.log("[webpack]", stats.toString({
// output options
}))
callback()
})
})
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'))