-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgulpfile.js
More file actions
82 lines (59 loc) · 1.84 KB
/
gulpfile.js
File metadata and controls
82 lines (59 loc) · 1.84 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
var gulp = require('gulp');
var gutil = require('gulp-util');
var env = require('gulp-env');
var argv = require('yargs').argv;
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var webpackCommonOpts = {colors: true, progress: true};
gulp.task('clean', function(){
var clean = require('gulp-clean');
return gulp.src('./dist', {read: false})
.pipe(clean());
});
gulp.task('set-env', function(){
if(argv.prod)
env.set({NODE_ENV: 'prod'});
else
env.set({NODE_ENV: 'dev'});
});
gulp.task('webpack:build', ['clean'], function (callback) {
var webpackConfig = require('./webpack.config');
webpack(webpackConfig, function(err, stats) {
if(err) throw new gutil.PluginError("webpack", err);
gutil.log("[webpack]", stats.toString(webpackCommonOpts));
callback();
});
});
gulp.task('build', ['set-env', 'webpack:build']);
gulp.task("webpack-dev-server", ['set-env', 'lint'], function (callback) {
var webpackConfig ;
if(argv.prod)
webpackConfig = require('./webpack.config');
else
webpackConfig = require('./webpack.dev.config');
var compiler = webpack(webpackConfig);
var apiServer = "http://localhost:8080";
new WebpackDevServer(compiler, {
hot: true,
stats: webpackCommonOpts,
historyApiFallback: true,
proxy: {
//API Server URL
"/api/*": apiServer
}
}).listen(8090, "localhost", function (err) {
if (err) throw new gutil.PluginError("webpack-dev-server", err);
gutil.log("[webpack-dev-server]", "http://localhost:8090");
callback();
});
});
gulp.task('lint', function(){
var eslint = require('gulp-eslint');
return gulp.src(['./src/**/*.js','!node_modules/**'])
.pipe(eslint({
useEslintrc: true
}))
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('default', ['webpack-dev-server']);