-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGulpfile.js
85 lines (75 loc) · 1.66 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
var gulp = require('gulp'),
path = require('path'),
del = require('del'),
historyApiFallback = require('connect-history-api-fallback');
var $ = require('gulp-load-plugins')({
scope: ['devDependencies'],
camelize: true,
lazy: true
});
const ROOT = path.join(__dirname),
APP = path.join(ROOT, 'app'),
PUBLIC = path.join(ROOT, 'public'),
DIST = path.join(ROOT, 'dist'),
FILES = {
entry: path.join(APP, 'app.js'),
index: path.join(PUBLIC, 'index.html'),
style: path.join(PUBLIC, 'app.css'),
serveHTML: path.join(DIST, 'index.html')
};
gulp.task('clean', function(done) {
del.sync([DIST]);
done();
});
gulp.task('copy', function() {
gulp.src(FILES.index)
.pipe(gulp.dest(DIST))
.pipe($.connect.reload());
gulp.src(FILES.style)
.pipe(gulp.dest(DIST))
.pipe($.connect.reload());
});
gulp.task('scripts:build', function() {
gulp.src(FILES.entry)
.pipe($.webpack({
output: {
filename: '[name].js'
},
devtool: 'eval',
watch: true,
module: {
loaders: [{
test: /\.js$/,
exclude: /node_modules/,
loaders: ['babel-loader?experimental&optional=runtime']
}]
}
}))
.pipe(gulp.dest(DIST))
.pipe($.connect.reload());
});
gulp.task('connect:start', function() {
$.connect.server({
root: DIST,
port: 9000,
livereload: true,
middleware: function(connect, opt) {
return [ historyApiFallback ];
}
});
gulp.src(FILES.serveHTML)
.pipe($.open('', {
url: 'http://localhost:9000'
}));
});
gulp.task('watch:html', function() {
gulp.watch(FILES.index, ['copy']);
});
gulp.task('dev', [
'copy',
'scripts:build',
'connect:start',
'watch:html'
]);
gulp.task('tasks', $.taskListing);
gulp.task('default', ['dev']);