-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.js
More file actions
executable file
·58 lines (44 loc) · 1.56 KB
/
dev.js
File metadata and controls
executable file
·58 lines (44 loc) · 1.56 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
#!/usr/bin/env node
'use strict';
var browserify = require('browserify');
var watchify = require('watchify');
var path = require('path');
var http = require('http');
var fs = require('fs');
var finalhandler = require('finalhandler');
var serveStatic = require('serve-static');
var chalk = require('chalk');
var b = browserify(path.resolve('./src/index.js'), watchify.args);
var w = watchify(b);
var bytes, time;
w.on('bytes', function (b) { bytes = b });
w.on('time', function (t) { time = t });
var update = function(bundle) {
var didError = false;
var writeStream = fs.createWriteStream(path.resolve('./public/bundle.js'));
bundle.on('error', function (err) {
console.error(String(chalk.red(err)));
didError = true;
writeStream.end();
});
bundle.pipe(writeStream);
writeStream.on('error', function (err) {
console.error(chalk.red(err));
});
writeStream.on('close', function () {
if (!didError) {
console.error(chalk.cyan(bytes) + chalk.grey(' bytes written to ') + chalk.cyan(path.resolve('./public/bundle.js'))
+ ' (' + (time / 1000).toFixed(2) + ' seconds)'
);
}
});
}
update(w.bundle());
w.on('update', function (ids) {
update(w.bundle());
});
var serve = serveStatic(path.normalize('./public/'));
var server = http.createServer(function(req, res){
serve(req, res, finalhandler(req, res))
});
server.listen(1618, function() {console.log(chalk.grey('serving ') + chalk.blue(path.resolve('./public/')) + chalk.grey(' on port ') + chalk.blue('1618'));});