Home

Awesome

bfydir

a http-server which watchify's all the files in a dir simultaneously uppon request. also it supports minifying js-files and inlining it into html-tags: <html><body><script>/* bundled source here */</script></body></html>.

cli

bfydir [<dir>] [-p,--port <port>] [-b,--bundles <bundles>] [-d,--debug]
       [--key <key>] [--cert <cert>] [--pfx <pfx>]
       [-a,--auth <user>:<pwd>[,<user>:<pwd>]]
       [-h,--help]

    <dir>     .. serve files from that directory (default: pwd)
    <port>    .. listen on that port (default: 8001)
    <bundles> .. write bundles into that directory (default: <dir>/.bfydir-bundles)
    debug     .. write infos about bundling/minifying to stdout
    <key>     .. path to ssl-key-file
    <cert>    .. path to cert-key-file
    <pfx>     .. path to pfx-file
    auth      .. basic auth (comma separated list of user:pwd
    help      .. only show this message, otherwise just start bfydir

querystring-parameters:

    bundle, b    .. bundles the requested file instead of serving it
    min, m       .. minifies the bundle (sets b automatically)
    inline, i    .. inlines the bundle into html (sets b)
    transform, t .. comma-separated list of transforms (sets b)
    ignore       .. comma-separated list of modules to ignore (sets b)

example:

    $ bfydir ~ -p 8080 -a user1:pwd1,user2:pwd2
    $ echo "module.exports = 'a'" > ~/a.js
    $ echo "module.exports = 'b'" > ~/b.js
    $ echo "console.log(require('./a'), require('./b'))" > ~/c.js
    $ node -e `curl "http://user1:pwd1@localhost:8005/c.js?b"`
    a b

usage

install bfydir and start the server:

$ npm i -g bfydir
$ bfydir ~ -p 8005

write code:

$ echo "module.exports = 'a'" > ~/a.js
$ echo "module.exports = 'b'" > ~/b.js
$ echo "console.log(require('./a'), require('./b'))" > ~/c.js

create a bundle:

$ node -e `curl http://localhost:8005/c.js?bundle`
a b

when you change the code it will update the bundles:

$ echo "module.exports = 'foo'" > ~/a.js
$ node -e `curl http://localhost:8005/c.js?bundle`
foo b

with the inline querystring-parameter it wrap the bundle with html-tags:

$ curl http://localhost:8005/c.js?inline
<html><body><script>/* bundled source */</script></body></html>

inline and minify:

$ curl http://localhost:8005/c.js?inline&min
<html><body><script>/* bundled source minified */</script></body></html>

use one or multiple transforms:

$ curl http://localhost:8005/some-file.js?transform=glslify,otherTransform
< transformed bundle >

without any querystring-parameters it will serve the source without bundling:

$ curl http://localhost:8005/a.js
module.exports = 'foo'

api

var bfydir = require('bfydir')([opts])

opts is optional

bfydir is an eventemitter which emits following events:

<path> is the url-pathname of the served bundle

all the events emit with a info-object:

bfydir.on('bundled', function(info){
  // info.urlPath
  // info.entryPath
  // info.bundlePath
  // info.bundlePathMin (only when minifying)
  // info.bundleSize
  // info.bundleSizeMin
})

var server = bfydir.createServer()

server is a http-server, its a shortcut for http.createServer(this.requestHandler())

var handler = bfydir.requestHandler()

this is a shortcut for var handler = bfydir.handleRequest.bind(bfydir)

bfydir.handleRequest(req, res[, next])

this will look at the query-string object require('url').parse(req.url) for various member attributes:

var bStream = bfydir.bundleStream(opts)

var mStream = bfydir.minifyStream(opts)

var iStream = require('bfydir').inlineStream([sourcePath])

<html>
  <head>
    <meta content="width=device-width,
                   initial-scale=1.0,
                   maximum-scale=1.0,
                   user-scalable=0"
          name="viewport" />
    <meta charset=utf-8>
  </head>
  <body>
    <script>
      /* here is the content */
    </script>
  </body>
</html>

bfydir.close()

close all the watchify-bundle-watchers