forked from ifengkou/webpack-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
78 lines (64 loc) · 1.86 KB
/
gulpfile.js
File metadata and controls
78 lines (64 loc) · 1.86 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
/**
* Created by sloong on 2016/6/14.
*/
'use strict';
var gulp = require('gulp');
var webpack = require('webpack');
//用于gulp传递参数
var minimist = require('minimist');
var gutil = require('gulp-util');
var src = process.cwd() + '/src';
var assets = process.cwd() + '/dist';
var knownOptions = {
string: 'env',
default: {env: process.env.NODE_ENV || 'production'}
};
var options = minimist(process.argv.slice(2), knownOptions);
var webpackConf = require('./webpack.config');
var webpackConfDev = require('./webpack-dev.config');
var remoteServer = {
host: '192.168.56.129',
remotePath: '/data/website/website1',
user: 'root',
pass: 'password'
};
var localServer = {
host: '192.168.56.130',
remotePath: '/data/website/website1',
user: 'root',
pass: 'password'
}
//check code
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 asserts
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) {
var _conf = options.env === 'production' ? webpackConf : webpackConfDev;
webpack(_conf, function (err, stats) {
if (err) throw new gutil.PluginError('webpack', err)
gutil.log('[webpack]', stats.toString({colors: true}))
done()
});
});
//default task
gulp.task('default', ['pack'])
//deploy assets to remote server
gulp.task('deploy', function () {
var sftp = require('gulp-sftp');
var _conf = options.env === 'production' ? remoteServer : localServer;
return gulp.src(assets + '/**')
.pipe(sftp(_conf))
})