/
gulpfile.js
108 lines (92 loc) · 2.52 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
var gulp = require("gulp");
var $ = require("gulp-load-plugins")();
var del = require("del");
//var tsfmt = require("typescript-formatter");
//var glob = require("glob");
var webpack = require('webpack');
var webpackDevServer = require('webpack-dev-server');
var webpackConfig = require("./webpack.config.js");
// CONFIG
var paths = {
sass: "src/style/**/*.scss",
scripts: "src/app/**/*.ts",
index: "src/index.html"
};
var destination = "./build";
var devCompiler = webpack(webpackConfig);
var devServer;
var production = process.env.NODE_ENV === 'production';
// TASKS
gulp.task("sass", function() {
return gulp
.src(paths.sass)
.pipe($.sass({style: "compressed", errLogToConsole: true}))
.pipe($.autoprefixer())
.pipe(gulp.dest(destination));
});
gulp.task("ts-lint", function() {
return gulp
.src(paths.scripts)
.pipe($.tslint())
.pipe($.tslint.report('prose', {emitError: false}));
});
//gulp.task("tsfmt", function(callback) {
// glob(paths.scripts, function(err, files) {
// tsfmt.processFiles(files, {
// editorconfig: false,
// replace: true,
// tsfmt: false,
// tslint: true
// });
// callback();
// });
//});
gulp.task("clean", function(callback) {
del([destination], callback);
});
gulp.task("index", function() {
return gulp
.src(paths.index)
.pipe(gulp.dest(destination));
});
gulp.task("webpack:build", function(callback) {
devCompiler.run(function (err, stats) {
if (err) {
throw new $.util.PluginError("webpack:build", err);
}
$.util.log("[webpack:build-dev]", stats.toString({
colors: true
}));
callback();
});
});
gulp.task("webpack:dev-server", function (callback) {
devServer = new webpackDevServer(devCompiler, {
contentBase: destination,
hot: true,
watchDelay: 100,
noInfo: true
});
devServer.listen(8080, "127.0.0.1", function(err) {
if (err) {
throw new $.util.PluginError("webpack:dev-server", err);
}
$.util.log("Server running on http://localhost:8080");
callback();
});
});
// Watch the things we are taking care of in gulp: sass, ts linting and index
gulp.task("gulp-watch", function() {
gulp.watch(paths.sass, "sass");
gulp.watch(paths.scripts, "ts-lint");
gulp.watch(paths.index, "index");
});
// The tasks we will actually use 99.9% of the time
gulp.task(
"watch",
gulp.series("clean", "sass", "ts-lint", "index", "webpack:dev-server", "gulp-watch")
);
gulp.task(
"build",
gulp.series("clean", gulp.parallel("sass", "ts-lint", "index", "webpack:build"))
);