-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
100 lines (82 loc) · 2.62 KB
/
gulpfile.js
File metadata and controls
100 lines (82 loc) · 2.62 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* @Author: dmyang
* @Date: 2015-06-16 15:19:59
* @Last Modified by: dmyang
* @Last Modified time: 2015-08-27 11:16:12
*/
'use strict';
var gulp = require('gulp');
var webpack = require('webpack');
var gutil = require('gulp-util');
var webpackConf = require('./webpack.config');
var webpackDevConf = require('./webpack-dev.config');
var src = process.cwd() + '/src';
var assets = process.cwd() + '/assets';
// js check
gulp.task('hint', function() {
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
return gulp.src([
'!' + src + '/js/lib/**/*.js',
src + '/js/**/*.js'
])
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
// clean assets
gulp.task('clean', ['hint'], function() {
var clean = require('gulp-clean');
return gulp.src(assets, {read: true}).pipe(clean());
});
// run webpack pack
gulp.task('pack', ['clean'], function(done) {
webpack(webpackConf, function(err, stats) {
if(err) throw new gutil.PluginError('webpack', err);
gutil.log('[webpack]', stats.toString({colors: true}));
done();
});
});
// html process
gulp.task('default', ['pack'], function() {
var replace = require('gulp-replace');
var htmlmin = require('gulp-htmlmin');
return gulp
.src(assets + '/*.html')
.pipe(replace(/<script(.+)?data-debug([^>]+)?><\/script>/g, ''))
// @see https://github.com/kangax/html-minifier
.pipe(htmlmin({
collapseWhitespace: true,
removeComments: true
}))
.pipe(gulp.dest(assets));
});
// deploy assets to remote server
gulp.task('deploy', function() {
var sftp = require('gulp-sftp');
return gulp.src(assets + '/**')
.pipe(sftp({
host: '[remote server ip]',
remotePath: '/www/app/',
user: 'foo',
pass: 'bar'
}));
});
// run HMR on `cli` mode
// @see http://webpack.github.io/docs/webpack-dev-server.html
gulp.task('hmr', function(done) {
var WebpackDevServer = require('webpack-dev-server');
var compiler = webpack(webpackDevConf);
var devSvr = new WebpackDevServer(compiler, {
contentBase: webpackConf.output.path,
publicPath: webpackDevConf.output.publicPath,
hot: true,
stats: webpackDevConf.devServer.stats,
});
devSvr.listen(8080, '0.0.0.0', function(err) {
if(err) throw new gutil.PluginError('webpack-dev-server', err);
gutil.log('[webpack-dev-server]',
'http://localhost:8088/webpack-dev-server/index.html');
// keep the devSvr alive
// done();
});
});