-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
71 lines (57 loc) · 2.23 KB
/
gulpfile.js
File metadata and controls
71 lines (57 loc) · 2.23 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
'use strict'
const gulp = require('gulp')
const electron = require('electron-connect').server.create()
var source = require('vinyl-source-stream'); // Used to stream bundle for further handling etc.
var browserify = require('browserify');
var watchify = require('watchify');
var watch = require('gulp-watch');
var reactify = require('reactify');
var concat = require('gulp-concat');
var concatCss = require('gulp-concat-css');
gulp.task('electron', () => {
electron.start()
gulp.watch('main.js', electron.restart);
gulp.watch('./css/**/*.css', ['buildCSS']);
gulp.watch('./app/**/*.js', ['browserify']);
gulp.watch(['./app/index.html'], () => {
electron.reload()
})
})
gulp.task('browserify', function() {
var bundler = browserify({
entries: ['./app/index.js'], // Only need initial file, browserify finds the deps
transform: [reactify], // We want to convert JSX to normal javascript
debug: true, // Gives us sourcemapping
cache: {}, packageCache: {}, fullPaths: true // Requirement of watchify
});
var watcher = watchify(bundler);
return watcher
.on('update', function () { // When any files update
var updateStart = Date.now();
console.log('Updating!');
watcher.bundle() // Create new bundle that uses the cache for high performance
.pipe(source('bundle.js'))
// This is where you add uglifying etc.
.pipe(gulp.dest('./build/'));
console.log('Updated!', (Date.now() - updateStart) + 'ms');
})
.bundle() // Create the initial bundle when starting the task
.pipe(source('bundle.js'))
.pipe(gulp.dest('./build/'));
});
gulp.task('buildCSS', function () {
return gulp.src('./css/**/*.css')
.pipe(concatCss("bundle.css"))
.pipe(gulp.dest('./build/'));
});
gulp.task('buildJS', function() {
return browserify('./app/index.js')
.bundle()
//Pass desired output filename to vinyl-source-stream
.pipe(source('bundle.js'))
// Start piping stream to tasks!
.pipe(gulp.dest('./build/'));
});
// Just running the two tasks
gulp.task('default', ['electron']);
gulp.task('build', ['buildJS', 'buildCSS']);