Skip to content

Commit 8dcca8c

Browse files
committed
modify gulpfile
1 parent 5dada58 commit 8dcca8c

File tree

6 files changed

+76
-75
lines changed

6 files changed

+76
-75
lines changed

dist/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<!DOCTYPE html><html lang="en"><head><base href="/"><meta charset="utf-8"><title>JackHu's blog vue版</title><meta name="viewport" content="width=device-width,initial-scale=1"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="renderer" content="webkit"><meta name="description" content="This is Jack Hu's blog. use vue and vuex."><meta name="keyword" content="Jackblog vue vuex vue-router vue-resource vue-strap vue-toastr vue-validator"><link rel="shortcut icon" href="/favicon.ico"><link href="/1bdb573a.style.css" rel="stylesheet"></head><body><!--[if lt IE 9]>
1+
<!DOCTYPE html><html lang="en"><head><base href="/"><meta charset="utf-8"><title>Jackblog vue版</title><meta name="viewport" content="width=device-width,initial-scale=1"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="renderer" content="webkit"><meta name="description" content="This is Jack Hu's blog. use vue and vuex."><meta name="keyword" content="Jackblog vue vuex vue-router vue-resource vue-strap vue-toastr vue-validator"><link rel="shortcut icon" href="/favicon.ico"><link href="/1bdb573a.style.css" rel="stylesheet"></head><body><!--[if lt IE 9]>
22
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
33
<![endif]--><div id="root"></div><script type="text/javascript" src="/1bdb573a.vendor.js"></script><script type="text/javascript" src="/1bdb573a.bundle.js"></script></body></html>

gulpfile.babel.js

Lines changed: 0 additions & 71 deletions
This file was deleted.

gulpfile.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
var path = require('path')
2+
var gulp = require('gulp')
3+
var gutil = require('gulp-util')
4+
var WebpackDevServer = require('webpack-dev-server')
5+
var webpack = require('webpack')
6+
var del = require('del')
7+
var env = require('gulp-env')
8+
var gulpSequence = require('gulp-sequence')
9+
var nodemon = require('gulp-nodemon')
10+
var open = require('open')
11+
12+
var DEV_PORT = 3000,PROD_PORT = 8400
13+
gulp.task('serve', function () {
14+
var webpackConfig = require('./webpack.config')
15+
var myConfig = Object.create(webpackConfig)
16+
myConfig.entry.unshift('webpack/hot/only-dev-server')
17+
myConfig.entry.unshift('webpack-dev-server/client?http://localhost:' + DEV_PORT)
18+
new WebpackDevServer(webpack(myConfig), {
19+
noInfo: false,
20+
hot: true,
21+
inline: true,
22+
historyApiFallback: true,
23+
publicPath: myConfig.output.publicPath,
24+
stats: {
25+
colors: true
26+
}
27+
}).listen(DEV_PORT, 'localhost', function (err) {
28+
if(err) throw new gutil.PluginError('webpack-dev-server', err)
29+
gutil.log('[webpack-dev-server]', '==> 🌎 http://localhost:' + DEV_PORT)
30+
open('http://localhost:' + DEV_PORT)
31+
})
32+
})
33+
34+
gulp.task('clean', function () {
35+
del([path.join(__dirname, '/dist/*')])
36+
})
37+
38+
gulp.task('set-env-prod', function () {
39+
env({
40+
vars: {
41+
'NODE_ENV':'production'
42+
}
43+
})
44+
})
45+
46+
gulp.task('webpack', function (callback) {
47+
var config = require('./webpack.config')
48+
webpack(config, function(err, stats) {
49+
if(err) throw new gutil.PluginError("webpack", err)
50+
gutil.log("[webpack]", stats.toString({
51+
// output options
52+
}))
53+
callback()
54+
})
55+
})
56+
57+
gulp.task('webpack:dist',gulpSequence('set-env-prod','webpack'))
58+
59+
gulp.task('build', gulpSequence('clean','webpack:dist'))
60+
61+
gulp.task('nodemon', function () {
62+
nodemon({
63+
script: path.join(__dirname,'/server.js'),
64+
ext: 'js',
65+
watch: [
66+
path.join(__dirname,'/dist')
67+
],
68+
env: { 'NODE_ENV': 'production','PORT':PROD_PORT }
69+
})
70+
})
71+
72+
gulp.task('serve:dist',gulpSequence('build','nodemon'))

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"scripts": {
66
"start": "gulp serve",
77
"build": "gulp build",
8+
"start:dist": "gulp serve:dist",
89
"pm2-start": "pm2 start --no-daemon process.json"
910
},
1011
"repository": {
@@ -27,7 +28,6 @@
2728
"babel-plugin-transform-runtime": "^6.15.0",
2829
"babel-preset-es2015": "^6.16.0",
2930
"babel-preset-stage-0": "^6.16.0",
30-
"babel-register": "^6.16.3",
3131
"babel-runtime": "^6.11.6",
3232
"bootstrap": "^3.3.7",
3333
"css-loader": "^0.25.0",

webpack.config.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = {
2020
new webpack.NoErrorsPlugin(),
2121
new HtmlWebpackPlugin({
2222
favicon:path.join(__dirname,'src/favicon.ico'),
23-
title: "JackHu's blog vue版",
23+
title: "Jackblog vue版",
2424
template: path.join(__dirname,'src/index.html'),
2525
inject: true
2626
}),

webpack.config.prod.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = {
3131
new ExtractTextPlugin('[hash:8].style.css', { allChunks: true }),
3232
new HtmlWebpackPlugin({
3333
favicon:path.join(__dirname,'src/favicon.ico'),
34-
title: "JackHu's blog vue版",
34+
title: "Jackblog vue版",
3535
template: path.join(__dirname,'src/index.html'), //模板文件
3636
inject:'body',
3737
hash:false, //为静态资源生成hash值

0 commit comments

Comments
 (0)