-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
62 lines (57 loc) · 1.72 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
var gulp = require('gulp');
var tap = require('gulp-tap');
var gWebpack = require('gulp-webpack');
var webpack = require('webpack');
//var compiler = require('webpack-stream');
var WebpackDevServer = require('webpack-dev-server');
var wpConfig = require('./webpack.config.js');
var watch = require('gulp-watch');
var gutil = require('gulp-util');
var grun = require('gulp-run');
var fs = require('fs');
var path = require('path');
var runSeq = require('run-sequence');
const PATH = {
src: 'literature/*.md',
entry: 'build/app/app.js',
assets: 'assets',
dest: 'build',
deploy: 'dist'
}
gulp.task('watchLiterature', () => {
return watch(PATH.src, { ignoreInitial: true }, (vinyl) => {
return grun('node_modules/.bin/litpro ./literature/' + vinyl.relative).exec();
});
});
gulp.task('server', (cb) => {
// Start a webpack-dev-server
new WebpackDevServer(webpack(wpConfig), {}).listen(8080, "localhost", (err) => {
if (err) throw new gutil.PluginError("webpack-dev-server", err);
gutil.log("[webpack-dev-server]", "http://localhost:8080/webpack-dev-server/index.html");
});
});
gulp.task('compile', (done) => {
const folder = "./literature";
var files = fs.readdirSync(folder)
.filter((file) => fs.lstatSync(path.join(folder, file)).isFile()).length;
var compiled = 0;
gulp.src(PATH.src)
.pipe(tap((vinyl) => {
grun('node_modules/.bin/litpro ./literature/' + vinyl.relative)
.exec(() => {
if (++compiled === files.length)
done();
});
}));
});
gulp.task('webpack', () => {
return gulp.src(PATH.entry)
.pipe(gWebpack(wpConfig, webpack))
.pipe(gulp.dest(PATH.deploy));
});
gulp.task('build', (cb) => {
runSeq('compile', 'webpack', cb);
});
gulp.task('serve', () => {
runSeq(['watchLiterature', 'server']);
});