watchify-middleware
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -7,3 +7,10 @@ var watchifyMiddleware = require('../') | ||
var staticUrl = 'bundle.js' | ||
var bundler = browserify('app.js', { debug: true, basedir: __dirname }) | ||
var bundler = browserify('app.js', { | ||
// config for watchify | ||
cache: {}, | ||
transform: require('babelify'), | ||
packageCache: {}, | ||
debug: true, | ||
basedir: __dirname | ||
}) | ||
var watcher = watchifyMiddleware.emitter(bundler, { | ||
@@ -10,0 +17,0 @@ errorHandler: true |
@@ -6,2 +6,3 @@ var createWatchify = require('watchify') | ||
var assign = require('object-assign') | ||
var stripAnsi = require('strip-ansi') | ||
var parseError = require('./parse-error') | ||
@@ -31,5 +32,3 @@ | ||
emitter.close = function () { | ||
if (closed) { | ||
return | ||
} | ||
if (closed) return | ||
closed = true | ||
@@ -41,3 +40,3 @@ if (watchify) { | ||
watchify.close() | ||
}, 50) | ||
}, 200) | ||
} | ||
@@ -48,6 +47,7 @@ } | ||
watchify.on('update', function (rows) { | ||
if (closed) return | ||
updates = rows | ||
emitter.emit('pending') | ||
pending = true | ||
time = Date.now() | ||
emitter.emit('pending') | ||
bundleDebounced() | ||
@@ -58,6 +58,11 @@ }) | ||
time = Date.now() | ||
emitter.emit('pending') | ||
pending = true | ||
bundle() | ||
process.nextTick(function () { | ||
if (closed) return | ||
emitter.emit('pending') | ||
bundle() | ||
}) | ||
return emitter | ||
function bundle () { | ||
@@ -70,3 +75,2 @@ if (closed) { | ||
var didError = false | ||
var outStream = concat(function (body) { | ||
@@ -97,2 +101,6 @@ if (!didError) { | ||
}) | ||
} else { | ||
wb.once('error', function (err) { | ||
emitter.emit('error', err) | ||
}) | ||
} | ||
@@ -105,5 +113,5 @@ wb.pipe(outStream) | ||
} | ||
return emitter | ||
function update () { | ||
if (closed) return | ||
if (pending) { | ||
@@ -119,3 +127,4 @@ pending = false | ||
console.error('%s', err) | ||
return ';console.error(' + JSON.stringify(err.message) + ');' | ||
var msg = stripAnsi(err.message) | ||
return ';console.error(' + JSON.stringify(msg) + ');' | ||
} |
{ | ||
"name": "watchify-middleware", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "a server for faster watchify development", | ||
@@ -17,5 +17,7 @@ "main": "index.js", | ||
"object-assign": "^4.0.1", | ||
"strip-ansi": "^3.0.0", | ||
"watchify": "^3.3.1" | ||
}, | ||
"devDependencies": { | ||
"babelify": "^6.3.0", | ||
"browserify": "^11.0.1", | ||
@@ -27,3 +29,3 @@ "garnish": "^2.3.0", | ||
"scripts": { | ||
"start": "node example/server.js | garnish" | ||
"start": "node example/server.js " | ||
}, | ||
@@ -30,0 +32,0 @@ "keywords": [ |
@@ -26,3 +26,8 @@ # watchify-middleware | ||
var entry = 'bundle.js' | ||
var bundler = browserify('app.js', { basedir: __dirname }) | ||
var bundler = browserify('app.js', { | ||
// config for watchify | ||
cache: {}, | ||
packageCache: {}, | ||
basedir: __dirname | ||
}) | ||
var watchify = watchifyMiddleware(bundler) | ||
@@ -59,8 +64,13 @@ | ||
```js | ||
var stripAnsi = require('strip-ansi') | ||
function defaultErrorHandler (err) { | ||
console.error('%s', err) | ||
return ';console.error(' + JSON.stringify(err.message) + ');' | ||
var msg = stripAnsi(err.message) | ||
return ';console.error(' + JSON.stringify(msg) + ');' | ||
} | ||
``` | ||
<sup>(some plugins produce ANSI color codes in error messages)</sup> | ||
Otherwise, it assumes the normal behaviour for error handling (which is typically just an uncaught error event). | ||
@@ -104,2 +114,6 @@ | ||
#### `emitter.close()` | ||
Closes the `watchify` instance and stops file watching. | ||
## running the demo | ||
@@ -106,0 +120,0 @@ |
11566
196
137
6
5
+ Addedstrip-ansi@^3.0.0
+ Addedansi-regex@2.1.1(transitive)
+ Addedstrip-ansi@3.0.1(transitive)