-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
42 lines (35 loc) · 1.36 KB
/
gulpfile.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
const gulp = require('gulp-help')(require('gulp'));
const gulpIf = require('gulp-if');
const eslint = require('gulp-eslint');
const plumber = require('gulp-plumber');
const watch = require('gulp-watch');
const gutil = require("gulp-util");
const webpack = require('webpack');
const webackDevServer = require('webpack-dev-server');
function isFixed(file) {
return file.eslint !== null && file.eslint.fixed;
}
gulp.task('lint', 'lints all js', function () {
return gulp.src(['**/*.js','!node_modules/**', '!build/**'])
.pipe(plumber())
.pipe(eslint({fix: true}))
.pipe(eslint.format())
.pipe(gulpIf(isFixed, gulp.dest('./')));
});
gulp.task('build', 'builds production js files',function(callback) {
webpack(require('./webpack.config.prod.js'), function(err, stats) {
if(err) throw new gutil.PluginError("webpack", err);
gutil.log("[webpack]", stats.toString());
callback();
});
});
gulp.task('devServer', 'watchs js files', function (callback) {
var compiler = webpack(require('./webpack.config.dev.js'));
new webackDevServer(compiler).listen(8080, "localhost", function(err) {
if(err) throw new gutil.PluginError("webpack-dev-server", err);
// Server listening
gutil.log("[webpack-dev-server]", "http://localhost:8080/webpack-dev-server/index.html");
// keep the server alive or continue?
// callback();
});
});