Repository navigation
Expand file tree
/
Copy pathgulpfile.js
More file actions
87 lines (72 loc) · 2.15 KB
/
Copy pathgulpfile.js
File metadata and controls
87 lines (72 loc) · 2.15 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
83
84
85
86
87
var gulp = require('gulp');
var mocha = require('gulp-mocha');
var gutil = require('gulp-util');
var eslint = require('gulp-eslint');
var babel = require('gulp-babel');
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var webpackConfiguration = require('./webpack.config.js');
var del = require('del');
require('babel-core/register');
/*** Unit tests ***/
gulp.task('lint', function () {
return gulp.src(['src/**/*.js', 'test/**/*.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError());
});
gulp.task('mocha', function() {
return gulp.src(['test/**/*.js'], { read: false })
.pipe(mocha({ reporter: 'spec' }))
.on('error', gutil.log);
});
gulp.task('mochaMin', function() {
return gulp.src(['test/**/*.js'], { read: false })
.pipe(mocha({ reporter: 'min' }))
.on('error', gutil.log);
});
gulp.task('test', ['lint', 'mocha']);
/*** Frontend ***/
gulp.task('webpack', function(callback) {
// run webpack
webpack(webpackConfiguration, function(err, stats) {
if (err) throw new gutil.PluginError('webpack', err);
gutil.log('[webpack]', stats.toString({}));
callback();
});
});
gulp.task('devserver', function() {
// Start a webpack-dev-server
var compiler = webpack(webpackConfiguration);
new WebpackDevServer(compiler, {
// server and middleware options
}).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');
});
});
gulp.task('client', ['webpack']);
/*** Backend ***/
gulp.task('babel', function() {
return gulp.src(['src/**/*.js'])
.pipe(babel())
.pipe(gulp.dest('lib'));
});
gulp.task('copy', function() {
return gulp.src(['src/**/*', '!src/**/*.js'])
.pipe(gulp.dest('lib'));
});
gulp.task('server', ['babel', 'copy']);
/*** Wrap up ***/
gulp.task('watch', function() {
gulp.watch(['src/**', 'test/**'], ['mochaMin']);
});
gulp.task('clean', function() {
return del([
'dist/**/*',
'lib/**/*'
]);
});
gulp.task('default', ['test', 'client', 'server']);