-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
76 lines (62 loc) · 1.97 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
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
var gulp = require("gulp");
var gutil = require("gulp-util");
var webpack = require("webpack");
var WebpackDevServer = require("webpack-dev-server");
var jshint = require("gulp-jshint");
var stylish = require("jshint-stylish");
var jsonlint = require("gulp-jsonlint");
var path = require("path");
// Compile JS sources with Webpack
gulp.task("webpack", function (callback) {
var config = require("./webpack.config");
webpack(config, function (err, stats) {
if (err) {
throw new gutil.PluginError("webpack", err);
}
gutil.log("[webpack]", stats.toString({
colors: true
}));
callback();
});
});
// Webpack Dev Server
gulp.task("webpack-dev-server", function (callback) {
var config, compiler;
config = require("./webpack.config");
compiler = webpack(config);
new WebpackDevServer(compiler, config.devServer).listen(8080, "localhost", function (err) {
if (err) {
throw new gutil.PluginError("webpack-dev-server", err);
}
// Server listening
gutil.log(gutil.colors.green.bold("[webpack-dev-server] http://localhost:8080/index.html"));
// keep the server alive or continue?
// callback();
});
});
// Watch JS files for changes
gulp.task("watch", ["webpack"], function () {
gulp.watch([
"www/js/**/*.js",
"!www/js/pack.js",
"!www/js/**/*.min.js"
], ["webpack"]);
});
gulp.task("lint-json", function () {
function reporter (file) {
gutil.log(gutil.colors.red("File "), gutil.colors.cyan(path.relative(__dirname, file.path)), gutil.colors.red(" is not valid JSON."));
}
return gulp.src(["*.json", "www/**/*.json", "!www/lib/**/*.json"])
.pipe(jsonlint())
.pipe(jsonlint.reporter(reporter));
});
gulp.task("lint-js", function () {
return gulp.src(["*.js", "www/js/**/*.js", "!www/js/pack.js"])
.pipe(jshint())
.pipe(jshint.reporter(stylish, {
verbose: true
}));
});
gulp.task("lint", ["lint-js", "lint-json"]);
// Will use webpack-dev-server as the default task when typing `gulp` without a task name
gulp.task("default", ["webpack-dev-server"]);