forked from jackhutu/jackblog-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
71 lines (63 loc) · 1.93 KB
/
gulpfile.babel.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
import path from 'path'
import gulp from 'gulp'
import gutil from 'gulp-util'
import WebpackDevServer from "webpack-dev-server"
import webpack from "webpack"
import del from 'del'
import env from 'gulp-env'
import gulpSequence from 'gulp-sequence'
import nodemon from 'gulp-nodemon'
import open from 'open'
const DEV_PORT = 3000,PROD_PORT = 8400
gulp.task('serve', cb =>{
let webpackConfig = require('./webpack.config')
let 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", 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', cb => del([path.join(__dirname, '/dist/*')]))
gulp.task('set-env-prod', ()=>{
env({
vars: {
'NODE_ENV':'production'
}
})
})
gulp.task('webpack', cb => {
let webpackConfig = require('./webpack.config')
let myConfig = Object.create(webpackConfig)
webpack(myConfig, 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', ()=> {
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'))