Skip to content

Commit 5ada0a7

Browse files
committed
Allow serving npm linked modules using tools/serve
Developing modules in external repositories can be a bit tedious if you need to bundle up the external module every time you want to test it. This allows module authors to use `npm link` to make their development source code accessible to `tools/serve`.
1 parent 7d917a4 commit 5ada0a7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tools/serve

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,36 @@ app.use('/api/token', function(request, response) {
3333
});
3434

3535
app.use('/bundle/annotator.js', browserify('index.js', {standalone: 'annotator'}));
36+
37+
// Serve files locally from src/ext/
3638
app.use('/bundle/ext', function (req, res, next) {
3739
// browserify-middleware expects req.path to be set
3840
req.path = req.url;
3941
browserify('src/ext/')(req, res, next);
4042
});
4143

44+
// Serve any browserifiable module. Useful when developing external modules. If
45+
// you are developing the "annotator-widgets" module you can run
46+
//
47+
// npm link
48+
//
49+
// in the annotator-widgets repository, followed by
50+
//
51+
// npm link annotator-widgets
52+
//
53+
// in the annotator repository, and then you can load
54+
//
55+
// /bundle/ext/annotator-widgets.js
56+
//
57+
// from this server.
58+
app.use('/bundle/ext', function (req, res, next) {
59+
if (req.url.slice(0, 1) !== '/' || req.url.slice(-3) !== '.js') {
60+
next();
61+
}
62+
var moduleName = req.url.slice(1, -3);
63+
browserify([moduleName])(req, res, next);
64+
});
65+
4266
// Static files
4367
app.use(connect.static(process.cwd()));
4468

0 commit comments

Comments
 (0)