I'm trying to develop node.js app with express.js. One of the thing which I try to implement is a function to serve generated by browserify bundle js file. What I would like to do is to use maven-download-plugin to download that file and put into my repository (it's java app). I know that his is a bit complicated but that's how it's look like. I can generate bundle with browserify using code:
browserify("./path/myjs.js", {
gzip : true
});
b.transform("hbsfy");
b = b.bundle({standalone: 'bundle'});
However I cannot find any information how to write that information to the public/bundle.js and how to serve it when for example path /bundle.js will be requested. Any ideas how can I do that?
Well, why don't you just use static module for express?
var express = require('express');
var app = express();
app.use(express.static(__dirname + '/public'));
To write bundle to the file, just stream it...
var fs = require('fs');
var ws = fs.createWriteStream(__dirname + '/public/bundle.js');
b.bundle({standalone: 'bundle'}).pipe(ws);
Or you can do it completely on-fly avoiding file-system and streaming directly to client...
app.get('/bundle.js', function(req, res, next) {
b.bundle({standalone: 'bundle'}).pipe(res);
});